WP_AI_Client_Prompt_Builder::__construct( WordPress\AiClient\Providers\ProviderRegistry $registry, Prompt $prompt = null )
- Since
- 7.0.0
- Source
wp-includes/ai-client/class-wp-ai-client-prompt-builder.php:185
Compatibility
- WordPress
- since 7.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 2 of the 5 tracked releases, added in 7.0.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$registryWordPress\AiClient\Providers\ProviderRegistry- 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.Default:null
Performance profile
How much work a call to WP_AI_Client_Prompt_Builder::__construct() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 36–45
- Plugin surface
- 1 hook
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 63.
Third-party callbacks on 'wp_ai_client_default_request_timeout' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_AI_Client_Prompt_Builder::__construct() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$filtered_default_timeout | 36 | ::AiClient(), apply_filters(), ::RequestOptions() |
| always | 42–45 | ::AiClient(), apply_filters(), __(), sprintf(), _doing_it_wrong(), ::RequestOptions() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 63 | 36–45 | 2 | |
| 8.5 | 63 | 36–45 | 2 | |
| 8.4 | 63 | 36–45 | 2 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 65 | 38–47 | 2 | |
| 8.2 | 65 | 38–47 | 2 | |
| 8.1 | 65 | 38–47 | 2 | |
| 7.4 | 65 | 38–47 | 2 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while WP_AI_Client_Prompt_Builder::__construct() runs, in this order:
- apply_filters( wp_ai_client_default_request_timeout )filterline 202 (+17 into the body)
Filters the default request timeout in seconds for AI Client HTTP requests.
Uses · 7
- apply_filters()Calls the callback functions that have been added to a filter hook.
- _doing_it_wrong()Marks something as being incorrectly called.
- __()Retrieves the translation of $text.
- \WordPress\AiClient\Builders\PromptBuilder::__construct()
- \WordPress\AiClient\AiClient::getEventDispatcher()
- WP_AI_Client_Prompt_Builder::exception_to_wp_error()Converts an exception into a WP_Error with a structured error code and message.
- \WordPress\AiClient\Providers\Http\DTO\RequestOptions::fromArray()
Used by · 1
- wp_ai_client_prompt()Creates a new AI prompt builder using the default provider registry.
Source code
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, ) ) ); }Changelog
Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.
Signature, return type and hooks compared across 2 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/ai-client/class-wp-ai-client-prompt-builder.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.