@@ -64,6 +64,65 @@ private static function check_capabilities() {
64
64
return $ sitegen_enabled ;
65
65
}
66
66
67
+ /**
68
+ * Function to refine the site description, i.e. translate and summarize when required
69
+ *
70
+ * @param string $site_description The site description
71
+ */
72
+ private static function get_refined_site_description ( $ site_description ) {
73
+ $ refined_description = self ::get_sitegen_from_cache ( 'refinedSiteDescription ' );
74
+ if ( $ refined_description ) {
75
+ return $ refined_description ;
76
+ }
77
+
78
+ $ response = wp_remote_post (
79
+ NFD_AI_BASE . 'refineSiteDescription ' ,
80
+ array (
81
+ 'headers ' => array (
82
+ 'Content-Type ' => 'application/json ' ,
83
+ ),
84
+ 'timeout ' => 60 ,
85
+ 'body ' => wp_json_encode (
86
+ array (
87
+ 'hiivetoken ' => HiiveConnection::get_auth_token (),
88
+ 'prompt ' => $ site_description ,
89
+ 'identifier ' => $ identifier ,
90
+ )
91
+ ),
92
+ )
93
+ );
94
+
95
+ $ response_code = wp_remote_retrieve_response_code ( $ response );
96
+ if ( 200 !== $ response_code ) {
97
+ if ( 400 === $ response_code ) {
98
+ $ error = json_decode ( wp_remote_retrieve_body ( $ response ), true );
99
+ return array (
100
+ 'error ' => $ error ['payload ' ]['reason ' ],
101
+ );
102
+ }
103
+ try {
104
+ $ error = json_decode ( wp_remote_retrieve_body ( $ response ), true );
105
+ if ( array_key_exists ( 'payload ' , $ error ) ) {
106
+ return array (
107
+ 'error ' => $ error ['payload ' ],
108
+ );
109
+ } else {
110
+ return array (
111
+ 'error ' => __ ( 'We are unable to process the request at this moment ' ),
112
+ );
113
+ }
114
+ } catch ( \Exception $ exception ) {
115
+ return array (
116
+ 'error ' => __ ( 'We are unable to process the request at this moment ' ),
117
+ );
118
+ }
119
+ }
120
+
121
+ $ refined_description = json_decode ( wp_remote_retrieve_body ( $ response ), true );
122
+ self ::cache_sitegen_response ( 'refinedSiteDescription ' , $ refined_description );
123
+ return $ refined_description ;
124
+ }
125
+
67
126
/**
68
127
* Function to validate site info
69
128
*
@@ -401,6 +460,8 @@ public static function generate_site_meta( $site_info, $identifier, $skip_cache
401
460
}
402
461
}
403
462
463
+ $ refined_description = self ::get_refined_site_description ( self ::get_prompt_from_info ( $ site_info ) );
464
+
404
465
$ response = wp_remote_post (
405
466
NFD_AI_BASE . 'generateSiteMeta ' ,
406
467
array (
@@ -411,7 +472,7 @@ public static function generate_site_meta( $site_info, $identifier, $skip_cache
411
472
'body ' => wp_json_encode (
412
473
array (
413
474
'hiivetoken ' => HiiveConnection::get_auth_token (),
414
- 'prompt ' => self :: get_prompt_from_info ( $ site_info ) ,
475
+ 'prompt ' => $ refined_description ,
415
476
'identifier ' => $ identifier ,
416
477
)
417
478
),
@@ -501,6 +562,8 @@ public static function get_home_pages( $site_description, $content_style, $targe
501
562
}
502
563
}
503
564
565
+ $ site_description = self ::get_refined_site_description ( $ site_description );
566
+
504
567
$ generated_content_structures = self ::get_sitegen_from_cache (
505
568
'contentStructures '
506
569
);
@@ -848,6 +911,8 @@ public static function get_pages(
848
911
);
849
912
}
850
913
914
+ $ site_description = self ::get_refined_site_description ( $ site_description );
915
+
851
916
$ identifier = 'generatePages ' ;
852
917
853
918
if ( ! $ skip_cache ) {
0 commit comments