[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ai-client/ -> class-wp-ai-client-prompt-builder.php (summary)

WP AI Client: WP_AI_Client_Prompt_Builder class

File Size: 290 lines (13 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_AI_Client_Prompt_Builder:: (7 methods):
  using_abilities()
  create_sdk_builder()
  get_error_code_prefix()
  get_prevented_error_message()
  is_prevented_by_filter()
  get_generating_methods()
  get_support_check_methods()


Class: WP_AI_Client_Prompt_Builder  - X-Ref

Fluent builder for constructing AI prompts, returning WP_Error on failure.

This class provides a fluent interface for building prompts with various
content types and model configurations. It wraps the PHP AI Client SDK's
PromptBuilder and adds WordPress-specific behavior including WP_Error
handling instead of exceptions, snake_case method naming, and integration
with the Abilities API.

Only the generating methods will return a WP_Error, to not break the fluent
interface. As soon as any exception is caught in a chain of method calls,
the returned instance will be in an error state, and all subsequent method
calls will be no-ops that just return the same error state instance. Only
when a generating method is called, the WP_Error will be returned. The
support check methods are the exception to the no-op behavior: they return
false rather than the error state instance.

using_abilities( ...$abilities )   X-Ref
Registers WordPress abilities as function declarations for the AI model.

Converts each WP_Ability to a FunctionDeclaration using the wpab__ prefix
naming convention and passes them to the underlying prompt builder.

return: self The current instance for method chaining.
param: WP_Ability|string ...$abilities The abilities to register, either as WP_Ability objects or ability name strings.

create_sdk_builder( ProviderRegistry $registry, $prompt )   X-Ref
Creates the wrapped prompt builder instance from the PHP AI Client SDK.

return: PromptBuilder The SDK prompt builder instance.
param: ProviderRegistry $registry The provider registry for finding suitable models.
param: Prompt           $prompt   Initial prompt content, or null.

get_error_code_prefix()   X-Ref
Retrieves the prefix used for WP_Error codes created by this builder.

return: string The error code prefix.

get_prevented_error_message()   X-Ref
Retrieves the error message to use when the prompt is prevented by a filter.

return: string The translated error message.

is_prevented_by_filter()   X-Ref
Checks whether the prompt is prevented by the `wp_ai_client_prevent_prompt` filter.

return: bool Whether the prompt is prevented.

get_generating_methods()   X-Ref
Retrieves the methods that generate a result from the prompt.

return: array<string, bool> The generating methods map.

get_support_check_methods()   X-Ref
Retrieves the methods that check whether the prompt is supported.

return: array<string, bool> The support check methods map.



Generated : Sun Nov 1 08:20:35 2026 Cross-referenced by PHPXref