AI: Update PHP AI Client to 1.4.0 and introduce WP_AI_Client_Embedding_Builder#12530
AI: Update PHP AI Client to 1.4.0 and introduce WP_AI_Client_Embedding_Builder#12530JasonTheAdams wants to merge 6 commits into
Conversation
Regenerated via `bash tools/php-ai-client/installer.sh --version=1.4.0`. The 1.4.0 release adds embedding generation support, including the new EmbeddingBuilder, embedding lifecycle events, Embedding/EmbeddingResult DTOs, and a shared ModelResolver for model selection. Full changelog: https://github.com/WordPress/php-ai-client/releases/tag/1.4.0 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Wraps the PHP AI Client SDK's new EmbeddingBuilder (added in 1.4.0), following the same pattern as WP_AI_Client_Prompt_Builder: snake_case method naming via __call() proxying, and WP_Error handling instead of exceptions, with an error state that preserves the fluent interface. Introduces the wp_ai_client_embedding() entry point function and the wp_ai_client_prevent_embedding filter, analogous to their prompt counterparts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
dkotter
left a comment
There was a problem hiding this comment.
Haven't tested this out yet but overall this looks good to me, noting most of what's here is coming from the PHP AI Client repo so I haven't reviewed any of that closely. Left a few comments that may be worth discussing
| * @param array<int, mixed> $arguments The method arguments. | ||
| * @return mixed The result of the method call. | ||
| */ | ||
| public function __call( string $name, array $arguments ) { |
There was a problem hiding this comment.
A lot of the things in this class are pretty close duplicate of what's in the WP_AI_Client_Prompt_Builder, if not a full duplicate (like exception_to_wp_error, is_support_check_method, is_generating_method, get_builder_callable, snake_to_camel_case).
Any thoughts around extracting any of that duplicate functionality out into some sort of shared class/trait/something to avoid duplicate code?
In 1.4.0, model selection state (model, registry, providerIdOrClassName, requestOptions) moved from the SDK's PromptBuilder onto its ModelResolver. Update the reflection helper to fall back to the model resolver for properties that no longer live on the wrapped builder. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ass. WP_AI_Client_Prompt_Builder and WP_AI_Client_Embedding_Builder shared nearly all of their machinery: the snake_case __call() proxying, the WP_Error error-state handling, exception-to-WP_Error conversion, and the default request timeout setup. Move that into an abstract WP_AI_Client_Builder base class, parameterized via abstract methods for the SDK builder instantiation, error code prefix, prevent filter, and generating/support-check method maps. No behavior changes: error codes, filter names, and _doing_it_wrong notices (which continue to report the concrete class name) are identical to before. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… filter. Allows developers to adjust the default request timeout per builder type, e.g. a different timeout for embeddings than for prompts. The builder's class name is passed as the second filter parameter. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…edding(). Covers the WordPress wrapper behavior (not the SDK itself): constructor input parsing and the default request timeout handling, snake_case fluent proxying and error-state semantics, the wp_supports_ai() and wp_ai_client_prevent_embedding gates, exception-to-WP_Error mapping with embedding-prefixed error codes, generation through a mock embedding model, and the variadic input handling of wp_ai_client_embedding(). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
What
Updates the bundled PHP AI Client library to 1.4.0 and introduces embedding generation support in core.
Library update
Regenerated
src/wp-includes/php-ai-client/viabash tools/php-ai-client/installer.sh --version=1.4.0. The headline feature of 1.4.0 is embedding generation: a newEmbeddingBuilder, embedding lifecycle events,Embedding/EmbeddingResultDTOs, and a sharedModelResolver. See the 1.4.0 release notes for a full list of changes.New:
WP_AI_Client_Embedding_BuilderA WordPress wrapper around the SDK's new
EmbeddingBuilder, following the exact pattern established byWP_AI_Client_Prompt_Builder:__call().WP_Errorhandling instead of exceptions: non-generating methods never throw; once an error occurs the instance enters an error state that preserves the fluent interface, and theWP_Erroris returned from the generating methods (generate_embedding_result(),generate_embedding(),generate_embeddings()).wp_supports_ai()and the existingwp_ai_client_default_request_timeoutfilter.wp_ai_client_prevent_embeddingfilter, analogous towp_ai_client_prevent_prompt.embedding_*prefix (e.g.embedding_network_error,embedding_invalid_argument) with HTTP status codes for REST-friendly errors.Also introduces the variadic
wp_ai_client_embedding()entry point, analogous towp_ai_client_prompt():Testing
php -land PHPCS pass on all changed files.WordPress\AiClient\AiClientresolves after the update.EmbeddingBuildermethods.🤖 Generated with Claude Code
Shared base class:
WP_AI_Client_BuilderSince the prompt and embedding builders share nearly all of their machinery, it now lives in an abstract
WP_AI_Client_Builderbase class: the snake_case__call()proxying,WP_Errorerror-state handling, exception-to-WP_Errorconversion, and default request timeout setup. Child classes supply the SDK builder, error code prefix, prevent filter, and method maps via abstract methods. No behavior changes forWP_AI_Client_Prompt_Builder— error codes, filter names, and_doing_it_wrong()notices (which report the concrete class name) are identical to 7.0.Test updates
PHP AI Client 1.4.0 moved model selection state (
model,registry,providerIdOrClassName,requestOptions) from the SDKPromptBuilderonto its newModelResolver; the test reflection helper now follows properties there.Dedicated tests were added for
WP_AI_Client_Embedding_Builderandwp_ai_client_embedding(), covering the wrapper behavior (not the SDK): constructor input parsing, timeout filter handling, fluent proxying and error-state semantics, thewp_supports_ai()/wp_ai_client_prevent_embeddinggates, exception-to-WP_Errormapping, and generation via a mock embedding model. The fullai-clientgroup passes: 298 tests, 747 assertions.