Skip to content

Refactor experiments to leverage ai service layer - #898

Closed
theaminulai wants to merge 8 commits into
WordPress:developfrom
theaminulai:Refactor-experiments-to-leverage-AI_Service-layer
Closed

Refactor experiments to leverage ai service layer#898
theaminulai wants to merge 8 commits into
WordPress:developfrom
theaminulai:Refactor-experiments-to-leverage-AI_Service-layer

Conversation

@theaminulai

@theaminulai theaminulai commented Jul 26, 2026

Copy link
Copy Markdown
Member

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_Service layer introduced in #101, instead of calling wp_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 through AI_Service gives us one place to manage default model configuration and keeps each ability's prompt-builder setup consistent.

How?

  • Added AI_Service::create_imagegen_prompt(), mirroring the existing create_textgen_prompt(), but seeded with get_preferred_image_models() instead of the text-generation model list, since image generation needs a different default model preference.
  • Updated the following abilities to call AI_Service::get_instance()->create_textgen_prompt( $prompt ) instead of wp_ai_client_prompt( $prompt ) as the first call in their private get_prompt_builder() method:
    • Excerpt_Generation
    • Title_Generation
    • Summarization
    • Alt_Text_Generation
    • Generate_Image_Prompt
  • Updated Generate_Image to call the new AI_Service::get_instance()->create_imagegen_prompt( $prompt ).
  • Left the rest of each ability's builder chain (using_system_instruction(), using_temperature(), with_file(), filter_prompt_builder(), etc.) untouched, since Abstract_Ability::set_provider_model_preference() already handles developer provider/model overrides and reapplies the correct fallback model list (text vs. vision vs. image) after AI_Service seeds the default — so behavior is unchanged, only the entry point moved to the service layer.
  • Abilities Explorer required no change: Ability_Handler only invokes arbitrary registered abilities generically via wp_get_ability()->execute() and never calls the AI client directly, so there was nothing to migrate there.
  • Other experiments not listed in Refactor experiments to leverage AI_Service layer #233 (Editorial Updates, Editorial Notes, Content Classification, Type Ahead, Content Resizing, Meta Description, Suggest Reply, Comment Moderation) still call wp_ai_client_prompt() directly and are intentionally out of scope for this PR.

Testing Instructions

  1. Confirm no regressions in behavior — model preference, developer overrides, and prompt filters are unchanged:
    • composer test / run the PHPUnit integration suite, in particular:
      • tests/Integration/Includes/Services/AI_ServiceTest.php
      • tests/Integration/Includes/Abilities/Excerpt_GenerationTest.php
      • tests/Integration/Includes/Abilities/Title_GenerationTest.php
      • tests/Integration/Includes/Abilities/SummarizationTest.php
      • tests/Integration/Includes/Abilities/Alt_Text_GenerationTest.php
      • tests/Integration/Includes/Abilities/Image_GenerationTest.php
      • tests/Integration/Includes/Abilities/Image_Prompt_GenerationTest.php
  2. Manually verify each affected feature still works end-to-end with a connected provider:
    • Generate an excerpt suggestion on a post.
    • Generate a title suggestion on a post.
    • Generate a content summary on a post.
    • Generate alt text for an image in the Media Library.
    • Generate an image via the Generate Image admin page, and generate an image prompt from post content.

Changelog Entry

Developer - Refactored the Excerpt Generation, Title Generation, Content Summarization, Alt Text Generation, and Image Generation abilities to use the AI_Service layer instead of calling wp_ai_client_prompt() directly, and added AI_Service::create_imagegen_prompt() for image generation defaults.

Open WordPress Playground Preview

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
@theaminulai
theaminulai requested a review from a team July 26, 2026 02:39
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Unlinked Accounts

The 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.

Unlinked contributors: theaminulai.

Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.19%. Comparing base (02f2742) to head (b920b99).

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     
Flag Coverage Δ
unit 80.19% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dkotter

dkotter commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

I appreciate the contribution here but if you see the last comment on the attached Issue, we're more likely to remove the AI_Service layer at this point, as that's not used anywhere and doesn't really provide any value compared to how we are currently doing things. Going to close this out but if you'd like to open a PR that removes that layer, I'm happy to review and test that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor experiments to leverage AI_Service layer

2 participants