-
Notifications
You must be signed in to change notification settings - Fork 6
feat/ Build WordPress REST API endpoints for AI client #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
felixarntz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ref34t Thank you for getting this started!
One early feedback:
POST /wp-json/{namespace}/prompt/generate-text POST /wp-json/{namespace}/prompt/generate-texts POST /wp-json/{namespace}/prompt/generate-image POST /wp-json/{namespace}/prompt/generate-images POST /wp-json/{namespace}/prompt/generate-speech POST /wp-json/{namespace}/prompt/generate-speeches POST /wp-json/{namespace}/prompt/generate-result POST /wp-json/{namespace}/prompt/generate-text-result POST /wp-json/{namespace}/prompt/generate-image-result POST /wp-json/{namespace}/prompt/generate-speech-result
I think we should only have endpoints for the generate-*-result terminate methods.
The other ones are shortcuts to get a specific part of the results, and that's easily something we can handle on the JavaScript API side. No need to have the other shortcut endpoints which are almost duplicates.
| * | ||
| * @return array<string, array<string, mixed>> Request arguments schema. | ||
| */ | ||
| protected function get_common_args(): array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message shouldn't manually define all the arguments. The PHP AI client SDK provides all the definitions (check the getJsonSchema() methods), and we can reuse those. Otherwise it's a lot of duplicate code, and it misses many arguments. No need to have validate_callbacks here either because it would be handled by default.
We need to support two arguments:
prompt: I think we can make this aoneOfof:- either
arrayofMessageDTOs - or a single
MessageDTO - or a single
MessagePartDTO - or a single
string
- either
config: A singleModelConfigDTO
For all of those we can combine the schemas from the respective DTOs to get this overall args array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixarntz handled here 1cf0a2a
| register_rest_route( | ||
| $this->namespace, | ||
| $route, | ||
| array( | ||
| 'methods' => 'POST', | ||
| 'callback' => array( $this, $callback ), | ||
| 'args' => $common_args, | ||
| 'permission_callback' => array( $this, 'check_permission' ), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also register the response schema for the routes here.
Per my previous comment, by only implementing the generate-*-result endpoints, this is easy: We can simply use GenerativeAiResult::getJsonSchema().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixarntz handled here 1cf0a2a
WordPress REST API Endpoints for AI Client
This PR implements comprehensive REST API endpoints that expose all PromptBuilder capabilities through WordPress's native REST API architecture and part of Project MVP Road #1.
Overview
Adds a unified REST controller that creates individual endpoints for each PromptBuilder terminate method, enabling WordPress plugins to integrate AI functionality through familiar REST API patterns with manual registration for distributed ecosystem compatibility.
Key Features
REST_Route_Registrar::register_rest_routes('namespace')Endpoints Added
Usage
Manual Registration Required
Architecture
phpstan.neon.distDistributed Ecosystem Support
This implementation follows WordPress distributed ecosystem patterns:
Quality Standards
This implementation provides the foundation for WordPress plugins to integrate AI capabilities through manual REST API registration, maintaining compatibility in WordPress's distributed plugin ecosystem.