WP_AI_Client_Prompt_Builder::__construct
Constructor.
Method of the class: WP_AI_Client_Prompt_Builder{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WP_AI_Client_Prompt_Builder = new WP_AI_Client_Prompt_Builder(); $WP_AI_Client_Prompt_Builder->__construct( $registry, $prompt );
- $registry(ProviderRegistry) (required)
- The provider registry for finding suitable models.
- $prompt(Prompt)
- Initial prompt content. A string for simple text prompts, a MessagePart or Message object for structured content, an array for a message array shape, or a list of parts or messages for multi-turn conversations.
Default:null
Changelog
| Since 7.0.0 | Introduced. |
WP_AI_Client_Prompt_Builder::__construct() WP AI Client Prompt Builder:: construct code WP 7.0
public function __construct( ProviderRegistry $registry, $prompt = null ) {
try {
$this->builder = new PromptBuilder( $registry, $prompt, AiClient::getEventDispatcher() );
} catch ( Exception $e ) {
$this->builder = new PromptBuilder( $registry, null, AiClient::getEventDispatcher() );
$this->error = $this->exception_to_wp_error( $e );
}
$default_timeout = 30.0;
/**
* Filters the default request timeout in seconds for AI Client HTTP requests.
*
* @since 7.0.0
*
* @param float $default_timeout The default timeout in seconds.
*/
$filtered_default_timeout = apply_filters( 'wp_ai_client_default_request_timeout', $default_timeout );
if ( is_numeric( $filtered_default_timeout ) && (float) $filtered_default_timeout >= 0.0 ) {
$default_timeout = (float) $filtered_default_timeout;
} else {
_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: %s: wp_ai_client_default_request_timeout */
__( 'The %s filter must return a non-negative number.' ),
'<code>wp_ai_client_default_request_timeout</code>'
),
'7.0.0'
);
}
$this->builder->usingRequestOptions(
RequestOptions::fromArray(
array(
RequestOptions::KEY_TIMEOUT => $default_timeout,
)
)
);
}