WP_AI_Client_Prompt_Builder::__construct( WordPressAiClientProvidersProviderRegistry $registry, Prompt $prompt = null )

In this article

Constructor.

Parameters

$registryWordPressAiClientProvidersProviderRegistryrequired
The provider registry for finding suitable models.
$promptPromptoptional
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

Source

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,
			)
		)
	);
}

Hooks

apply_filters( ‘wp_ai_client_default_request_timeout’, float $default_timeout )

Filters the default request timeout in seconds for AI Client HTTP requests.

Changelog

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.