Refactor experiments to leverage ai service layer - #898
Conversation
Mirrors create_textgen_prompt() but seeds the builder with the plugin's preferred image models instead of text-generation defaults, so image generation can route through the AI_Service layer too. Refs WordPress#233
Route the prompt builder through AI_Service::create_textgen_prompt() instead of calling wp_ai_client_prompt() directly. Refs WordPress#233
Route the prompt builder through AI_Service::create_textgen_prompt() instead of calling wp_ai_client_prompt() directly. Refs WordPress#233
Route the prompt builder through AI_Service::create_textgen_prompt() instead of calling wp_ai_client_prompt() directly. Refs WordPress#233
Route the prompt builder through AI_Service::create_textgen_prompt() instead of calling wp_ai_client_prompt() directly. Refs WordPress#233
Route the prompt builder through the new AI_Service::create_imagegen_prompt() instead of calling wp_ai_client_prompt() directly.
Route the prompt builder through AI_Service::create_textgen_prompt() instead of calling wp_ai_client_prompt() directly. Part of the Image Generation experiment covered by WordPress#233
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @theaminulai. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #898 +/- ##
=============================================
+ Coverage 80.18% 80.19% +0.01%
- Complexity 2526 2530 +4
=============================================
Files 106 106
Lines 10240 10251 +11
=============================================
+ Hits 8211 8221 +10
- Misses 2029 2030 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I appreciate the contribution here but if you see the last comment on the attached Issue, we're more likely to remove the |
What?
Closes #233
Refactors the Excerpt Generation, Title Generation, Content Summarization, Alt Text Generation, and Image Generation (Generate_Image + Generate_Image_Prompt) abilities to route their AI calls through the
AI_Servicelayer introduced in #101, instead of callingwp_ai_client_prompt()directly.Why?
With #101 merged and part of the 0.2.1 release, the various experiments/abilities still constructed prompt builders by calling the global
wp_ai_client_prompt()function directly and duplicated model-preference logic themselves. Centralizing that throughAI_Servicegives us one place to manage default model configuration and keeps each ability's prompt-builder setup consistent.How?
AI_Service::create_imagegen_prompt(), mirroring the existingcreate_textgen_prompt(), but seeded withget_preferred_image_models()instead of the text-generation model list, since image generation needs a different default model preference.AI_Service::get_instance()->create_textgen_prompt( $prompt )instead ofwp_ai_client_prompt( $prompt )as the first call in their privateget_prompt_builder()method:Excerpt_GenerationTitle_GenerationSummarizationAlt_Text_GenerationGenerate_Image_PromptGenerate_Imageto call the newAI_Service::get_instance()->create_imagegen_prompt( $prompt ).using_system_instruction(),using_temperature(),with_file(),filter_prompt_builder(), etc.) untouched, sinceAbstract_Ability::set_provider_model_preference()already handles developer provider/model overrides and reapplies the correct fallback model list (text vs. vision vs. image) afterAI_Serviceseeds the default — so behavior is unchanged, only the entry point moved to the service layer.Abilities Explorerrequired no change:Ability_Handleronly invokes arbitrary registered abilities generically viawp_get_ability()->execute()and never calls the AI client directly, so there was nothing to migrate there.wp_ai_client_prompt()directly and are intentionally out of scope for this PR.Testing Instructions
composer test/ run the PHPUnit integration suite, in particular:tests/Integration/Includes/Services/AI_ServiceTest.phptests/Integration/Includes/Abilities/Excerpt_GenerationTest.phptests/Integration/Includes/Abilities/Title_GenerationTest.phptests/Integration/Includes/Abilities/SummarizationTest.phptests/Integration/Includes/Abilities/Alt_Text_GenerationTest.phptests/Integration/Includes/Abilities/Image_GenerationTest.phptests/Integration/Includes/Abilities/Image_Prompt_GenerationTest.phpChangelog Entry