@@ -64,6 +64,26 @@ public function generate_text( $prompt = null, $system_instruction = null, array
6464 return new WP_Error ( 'ai_client_not_available ' , __ ( 'AI Client is not available ' , 'ai ' ) );
6565 }
6666
67+ $ prompt_builder = $ this ->prompt_builder ( $ prompt , $ system_instruction , $ options );
68+
69+ if ( is_wp_error ( $ prompt_builder ) ) {
70+ return $ prompt_builder ;
71+ }
72+
73+ return $ this ->get_result ( $ prompt_builder ->generateTexts () );
74+ }
75+
76+ /**
77+ * Build the prompt builder for the request.
78+ *
79+ * @since 0.1.0
80+ *
81+ * @param string|null $prompt The prompt to send.
82+ * @param string|null $system_instruction The system instruction to send.
83+ * @param array $options The options to send.
84+ * @return \WordPress\AiClient\PromptBuilder|\WP_Error The prompt builder or a WP_Error.
85+ */
86+ protected function prompt_builder ( $ prompt = null , $ system_instruction = null , array $ options = [] ) {
6787 try {
6888 $ model_config = $ this ->process_model_config ( $ options );
6989 $ prompt_builder = AiClient::prompt ( $ prompt );
@@ -84,7 +104,7 @@ public function generate_text( $prompt = null, $system_instruction = null, array
84104 }
85105 }
86106
87- return $ this -> get_result ( $ prompt_builder-> generateTexts () ) ;
107+ return $ prompt_builder ;
88108 } catch ( \Exception $ e ) {
89109 return new WP_Error ( 'ai_client_error ' , $ e ->getMessage () );
90110 }
0 commit comments