Add extensibility hooks for system instructions, ability results, and post context#304
Add extensibility hooks for system instructions, ability results, and post context#304Ryujiyasu wants to merge 2 commits intoWordPress:developfrom
Conversation
… post context Adds filters agreed upon in WordPress#34 hook audit discussion: - `ai_experiments_system_instruction` in Abstract_Ability::get_system_instruction() - `ai_experiments_ability_result` and `ai_experiments_ability_result_{$name}` for filtering ability execution results - `ai_experiments_get_post_details` in get-post-details ability - `ai_experiments_get_post_terms` in get-post-terms ability
|
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 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. |
Tests cover:
- ai_experiments_system_instruction filter modifies instructions
- ai_experiments_system_instruction filter receives correct ability name
- ai_experiments_ability_result filter modifies results
- ai_experiments_ability_result_{$name} dynamic filter works
- WP_Error results bypass filtering
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #304 +/- ##
=============================================
+ Coverage 58.03% 58.19% +0.15%
- Complexity 576 578 +2
=============================================
Files 37 37
Lines 2955 2966 +11
=============================================
+ Hits 1715 1726 +11
Misses 1240 1240
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The plugin is being renamed in #287 by @dkotter. There is a related feedback #287 (review) from @jeffpaul, which makes perfect sense here as well:
This applies to the names of the proposed hooks. Let's finalize the naming conventions here. Also note that in WP core, all AI related hooks are prefixed with |
|
Thanks for working on this, @Ryujiyasu! I'm very much in favor of adding extensibility filters — this is exactly the kind of developer control the plugin needs. However, after reviewing this alongside prior work on the Abilities API, I think some of these filters would be better suited for WP core rather than the plugin. Here's my analysis: Filters that should go to WP coreWP core already fires
These are generic "filter the result of any ability execution" hooks — not AI-specific. The same concept was proposed in the Abilities API repo in the early phase of development:
Placing result filtering in core (inside
Now that Abilities API development has moved to core, these filters should be proposed there. I'd be happy to help with that. Filters that belong in this plugin
|
| /** | ||
| * Filters the post details returned by the get-post-details ability. | ||
| * | ||
| * @since 0.5.0 |
There was a problem hiding this comment.
Let's replace all @since statements with x.x.x as we're not sure of the actual version until we prep a release (and we have a step in our release process to find and replace all of those)
Summary
Implements the extensibility hooks agreed upon in the #34 hook audit discussion with @dkotter.
New Filters
1. System Instruction Filter (
Abstract_Ability)ai_experiments_system_instruction— Filters the system instruction text before it's passed to the AI model. Receives the instruction string, ability name, and data array.2. Ability Result Filters (
Abstract_Ability)ai_experiments_ability_result— Generic filter applied to the result of any ability execution. Receives the result, ability name, and input.ai_experiments_ability_result_{$name}— Dynamic filter for a specific ability (e.g.,ai_experiments_ability_result_ai/title-generation). Receives the result and input.3. Post Context Filters (in the Abilities, per discussion)
ai_experiments_get_post_details— Filters post details returned by theai/get-post-detailsability. Receives details array, post ID, and requested fields.ai_experiments_get_post_terms— Filters terms returned by theai/get-post-termsability. Receives terms array, post ID, and allowed taxonomies.Design Decisions
filtered_execute_callbackwrapper inAbstract_Abilitythat wraps the abstractexecute_callback. This avoids requiring changes to every concrete ability class while ensuring all abilities get consistent filtering.get_post_contexthelper), as agreed with @dkotter.Example Usage
Closes #34
Test Plan
ai_experiments_system_instructionfilter modifies system instructionsai_experiments_ability_resultfilter modifies ability resultsai_experiments_get_post_detailsfilter modifies post detailsai_experiments_get_post_termsfilter modifies post terms