From 0585cbf2e538cfef4ffcd4de4f30f9873bc9b4a7 Mon Sep 17 00:00:00 2001 From: amartya-dev Date: Thu, 8 Feb 2024 18:06:01 +0530 Subject: [PATCH 1/6] response change to include generated images per page --- includes/SiteGen/SiteGen.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/SiteGen/SiteGen.php b/includes/SiteGen/SiteGen.php index fa6920f..a331122 100644 --- a/includes/SiteGen/SiteGen.php +++ b/includes/SiteGen/SiteGen.php @@ -454,7 +454,11 @@ public static function get_home_pages( $site_description, $content_style, $targe if ( in_array( $pattern_category, $categories_to_separate, true ) ) { $homepage_patterns[ $pattern_category ] = $random_pattern; } else { - $homepage_patterns['content'] = $homepage_patterns['content'] . $random_pattern; + $homepage_patterns['content'] = $homepage_patterns['content'] . $random_pattern['']; + } + + if ( ! empty( $random_pattern['dalleImages'] ) ) { + $homepage_patterns['generatedImages'] = $random_pattern['dalleImages']; } } $generated_homepages[ $slug ] = $homepage_patterns; From 7905c39b712bb43381fe4080bce9794c233f5dd4 Mon Sep 17 00:00:00 2001 From: amartya-dev Date: Thu, 8 Feb 2024 18:07:17 +0530 Subject: [PATCH 2/6] fix: replaced pattern key --- includes/SiteGen/SiteGen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/SiteGen/SiteGen.php b/includes/SiteGen/SiteGen.php index a331122..dd4f92d 100644 --- a/includes/SiteGen/SiteGen.php +++ b/includes/SiteGen/SiteGen.php @@ -454,7 +454,7 @@ public static function get_home_pages( $site_description, $content_style, $targe if ( in_array( $pattern_category, $categories_to_separate, true ) ) { $homepage_patterns[ $pattern_category ] = $random_pattern; } else { - $homepage_patterns['content'] = $homepage_patterns['content'] . $random_pattern['']; + $homepage_patterns['content'] = $homepage_patterns['content'] . $random_pattern['replacedPattern']; } if ( ! empty( $random_pattern['dalleImages'] ) ) { From 812dac3c197d63cf61c857c8b42248fe9835b3fc Mon Sep 17 00:00:00 2001 From: amartya-dev Date: Thu, 8 Feb 2024 20:00:21 +0530 Subject: [PATCH 3/6] read from replaced pattern on all patterns --- includes/SiteGen/SiteGen.php | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/includes/SiteGen/SiteGen.php b/includes/SiteGen/SiteGen.php index dd4f92d..a37fbc5 100644 --- a/includes/SiteGen/SiteGen.php +++ b/includes/SiteGen/SiteGen.php @@ -50,6 +50,7 @@ class SiteGen { * Function to check capabilities */ private static function check_capabilities() { + return true; $capability = new SiteCapabilities(); $ai_enabled = $capability->get( 'canAccessAI' ); @@ -211,7 +212,7 @@ private static function generate_pattern_content( 'timeout' => 60, 'body' => wp_json_encode( array( - 'hiivetoken' => HiiveConnection::get_auth_token(), + 'hiivetoken' => 'test-ai-sitegen', 'prompt' => array( 'site_description' => $site_description, 'keywords' => wp_json_encode( $keywords ), @@ -280,6 +281,16 @@ public static function generate_site_meta( $site_info, $identifier, $skip_cache } } + print_r( + wp_json_encode( + array( + 'hiivetoken' => 'test-ai-sitegen', + 'prompt' => self::get_prompt_from_info( $site_info ), + 'identifier' => $identifier, + ) + ) + ); + $response = wp_remote_post( NFD_AI_BASE . 'generateSiteMeta', array( @@ -289,7 +300,7 @@ public static function generate_site_meta( $site_info, $identifier, $skip_cache 'timeout' => 60, 'body' => wp_json_encode( array( - 'hiivetoken' => HiiveConnection::get_auth_token(), + 'hiivetoken' => 'test-ai-sitegen', 'prompt' => self::get_prompt_from_info( $site_info ), 'identifier' => $identifier, ) @@ -363,9 +374,6 @@ public static function get_home_pages( $site_description, $content_style, $targe $generated_content_structures = self::get_sitegen_from_cache( 'contentStructures' ); - $generated_images = self::get_sitegen_from_cache( - 'generatedImages' - ); $keywords = self::generate_site_meta( array( 'site_description' => $site_description, @@ -383,7 +391,7 @@ public static function get_home_pages( $site_description, $content_style, $targe 'timeout' => 60, 'body' => wp_json_encode( array( - 'hiivetoken' => HiiveConnection::get_auth_token(), + 'hiivetoken' => 'test-ai-sitegen', 'prompt' => array( 'site_description' => $site_description, 'keywords' => wp_json_encode( $keywords ), @@ -424,10 +432,6 @@ public static function get_home_pages( $site_description, $content_style, $targe $generated_content_structures = $parsed_response['contentStructures']; $generated_patterns = $parsed_response['generatedPatterns']; $generated_homepages = $parsed_response['pages']; - if ( array_key_exists( 'generatedImages', $parsed_response ) ) { - $generated_images = $parsed_response['generatedImages']; - self::cache_sitegen_response( 'generatedImages', $generated_images ); - } self::cache_sitegen_response( 'contentStructures', $generated_content_structures ); self::cache_sitegen_response( 'generatedPatterns', $generated_patterns ); self::cache_sitegen_response( 'homepages', $generated_homepages ); @@ -452,11 +456,13 @@ public static function get_home_pages( $site_description, $content_style, $targe $random_pattern = $generated_patterns[ $pattern_category ][ $pattern_index ]; if ( in_array( $pattern_category, $categories_to_separate, true ) ) { - $homepage_patterns[ $pattern_category ] = $random_pattern; + $homepage_patterns[ $pattern_category ] = $random_pattern['replacedPattern']; } else { $homepage_patterns['content'] = $homepage_patterns['content'] . $random_pattern['replacedPattern']; } + $homepage_patterns['generatedImages'] = array(); + if ( ! empty( $random_pattern['dalleImages'] ) ) { $homepage_patterns['generatedImages'] = $random_pattern['dalleImages']; } @@ -464,7 +470,6 @@ public static function get_home_pages( $site_description, $content_style, $targe $generated_homepages[ $slug ] = $homepage_patterns; } - $generated_homepages['generatedImages'] = $generated_images; self::cache_sitegen_response( 'homepages', $generated_homepages ); return $generated_homepages; } @@ -494,7 +499,7 @@ public static function get_content_for_page( 'timeout' => 60, 'body' => wp_json_encode( array( - 'hiivetoken' => HiiveConnection::get_auth_token(), + 'hiivetoken' => 'test-ai-sitegen', 'prompt' => array( 'site_description' => $site_description, 'content_style' => wp_json_encode( $content_style ), @@ -533,7 +538,7 @@ public static function get_content_for_page( } $parsed_response = json_decode( wp_remote_retrieve_body( $response ), true ); if ( ! array_key_exists( 'error', $parsed_response['content'] ) ) { - $parsed_response['content'] = implode( '', $parsed_response['content'] ); + $parsed_response['content'] = implode( '', $parsed_response['content']['replacedPattern'] ); } return $parsed_response['content']; } From 6188ae6e7334da3d849b588f2b65f370c73df523 Mon Sep 17 00:00:00 2001 From: amartya-dev Date: Thu, 8 Feb 2024 20:04:46 +0530 Subject: [PATCH 4/6] remove print r --- includes/SiteGen/SiteGen.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/includes/SiteGen/SiteGen.php b/includes/SiteGen/SiteGen.php index a37fbc5..1a40ce1 100644 --- a/includes/SiteGen/SiteGen.php +++ b/includes/SiteGen/SiteGen.php @@ -281,16 +281,6 @@ public static function generate_site_meta( $site_info, $identifier, $skip_cache } } - print_r( - wp_json_encode( - array( - 'hiivetoken' => 'test-ai-sitegen', - 'prompt' => self::get_prompt_from_info( $site_info ), - 'identifier' => $identifier, - ) - ) - ); - $response = wp_remote_post( NFD_AI_BASE . 'generateSiteMeta', array( From 552dcb9ce6ac4809303e56a1c14b9995f9b80f5d Mon Sep 17 00:00:00 2001 From: amartya-dev Date: Fri, 9 Feb 2024 19:24:19 +0530 Subject: [PATCH 5/6] fix: other pages --- includes/SiteGen/SiteGen.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/includes/SiteGen/SiteGen.php b/includes/SiteGen/SiteGen.php index 1a40ce1..ab6a230 100644 --- a/includes/SiteGen/SiteGen.php +++ b/includes/SiteGen/SiteGen.php @@ -50,7 +50,6 @@ class SiteGen { * Function to check capabilities */ private static function check_capabilities() { - return true; $capability = new SiteCapabilities(); $ai_enabled = $capability->get( 'canAccessAI' ); @@ -212,7 +211,7 @@ private static function generate_pattern_content( 'timeout' => 60, 'body' => wp_json_encode( array( - 'hiivetoken' => 'test-ai-sitegen', + 'hiivetoken' => HiiveConnection::get_auth_token(), 'prompt' => array( 'site_description' => $site_description, 'keywords' => wp_json_encode( $keywords ), @@ -290,7 +289,7 @@ public static function generate_site_meta( $site_info, $identifier, $skip_cache 'timeout' => 60, 'body' => wp_json_encode( array( - 'hiivetoken' => 'test-ai-sitegen', + 'hiivetoken' => HiiveConnection::get_auth_token(), 'prompt' => self::get_prompt_from_info( $site_info ), 'identifier' => $identifier, ) @@ -381,7 +380,7 @@ public static function get_home_pages( $site_description, $content_style, $targe 'timeout' => 60, 'body' => wp_json_encode( array( - 'hiivetoken' => 'test-ai-sitegen', + 'hiivetoken' => HiiveConnection::get_auth_token(), 'prompt' => array( 'site_description' => $site_description, 'keywords' => wp_json_encode( $keywords ), @@ -489,7 +488,7 @@ public static function get_content_for_page( 'timeout' => 60, 'body' => wp_json_encode( array( - 'hiivetoken' => 'test-ai-sitegen', + 'hiivetoken' => HiiveConnection::get_auth_token(), 'prompt' => array( 'site_description' => $site_description, 'content_style' => wp_json_encode( $content_style ), @@ -527,10 +526,13 @@ public static function get_content_for_page( } } $parsed_response = json_decode( wp_remote_retrieve_body( $response ), true ); + $generated_page = ''; if ( ! array_key_exists( 'error', $parsed_response['content'] ) ) { - $parsed_response['content'] = implode( '', $parsed_response['content']['replacedPattern'] ); + foreach ($parsed_response['content'] as $pattern_content) { + $generated_page .= $pattern_content['replacedPattern']; + } } - return $parsed_response['content']; + return $generated_page; } /** From 855d98507da87388c074baab2a0602db40fbbfb9 Mon Sep 17 00:00:00 2001 From: amartya-dev Date: Fri, 9 Feb 2024 19:25:03 +0530 Subject: [PATCH 6/6] fix: lint errors --- includes/SiteGen/SiteGen.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/SiteGen/SiteGen.php b/includes/SiteGen/SiteGen.php index ab6a230..ccbf293 100644 --- a/includes/SiteGen/SiteGen.php +++ b/includes/SiteGen/SiteGen.php @@ -526,9 +526,9 @@ public static function get_content_for_page( } } $parsed_response = json_decode( wp_remote_retrieve_body( $response ), true ); - $generated_page = ''; + $generated_page = ''; if ( ! array_key_exists( 'error', $parsed_response['content'] ) ) { - foreach ($parsed_response['content'] as $pattern_content) { + foreach ( $parsed_response['content'] as $pattern_content ) { $generated_page .= $pattern_content['replacedPattern']; } }