Skip to content

Commit

Permalink
read from replaced pattern on all patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
amartya-dev committed Feb 8, 2024
1 parent 7905c39 commit 812dac3
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions includes/SiteGen/SiteGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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 ),
Expand Down Expand Up @@ -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(
Expand All @@ -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,
)
Expand Down Expand Up @@ -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,
Expand All @@ -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 ),
Expand Down Expand Up @@ -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 );
Expand All @@ -452,19 +456,20 @@ 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'];
}
}
$generated_homepages[ $slug ] = $homepage_patterns;
}

$generated_homepages['generatedImages'] = $generated_images;
self::cache_sitegen_response( 'homepages', $generated_homepages );
return $generated_homepages;
}
Expand Down Expand Up @@ -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 ),
Expand Down Expand Up @@ -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'];
}
Expand Down

0 comments on commit 812dac3

Please sign in to comment.