Skip to content

Commit ec8c3b8

Browse files
committed
Add a prompt builder method to our API Request class
1 parent c08f292 commit ec8c3b8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

includes/API_Request.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)