-
Notifications
You must be signed in to change notification settings - Fork 9
Implement JS API and necessary REST endpoints #27
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
Conversation
|
Still working on finalizing this (mostly adding some docs), but this is the currently envisioned JS API. Important consideration: This API should (by default) only be used for features where being able to prompt anything from the client-side is desirable. It is basically unrestricted in what you can do with AI, which is why it's restricted to administrators by default. For actual features in distributed plugins, it's recommended to stick to the PHP-side API and build custom REST API endpoints, in order to "harden" things so that users can't run arbitrary prompts. Due to cost factor, you probably don't want to allow that to users with fewer privileges. |
|
@felixarntz The more I sit on this, the more I'm left wondering what the use case is for someone wanting to make arbitrary prompts from the front-end? As we've discussed, we'll need to lock this down to admins, and even then it's likely folks will make bespoke endpoints and such for specific AI-powered use cases. Now that we're aiming this for core, I'm more reluctant to add something like this if we don't have clear scenarios in mind. |
|
@JasonTheAdams A few reasons to add this:
In other words: For some features, the JS API is preferable - for other features, the PHP API with REST endpoints and manual JS is preferable. |
|
I'm interested in how people would use this Client Side API. I think because it exists, and because this package likely won't 1 to 1 make it into WP Core v7.0 (like Abilities), it's worth shipping with a note/flag explaining that this is an experimental feature. Then, we can see how things work, and have a hard deadline of the next Core version to determine if this is useful or not. However it shakes out, for Built-In AI, we'll need some way to handle this as well - this is 100% client side. I can see it taking the path of Abilities Client, where it's a package added to GB out of sync with the first core addition. At the same time, my concerns lie with the fragmentation of prompt registrations, and why we'd only want to write out these systems in the Client. I think there's some merit to thinking that Agencies could use this ... so let's find out(?) There's also some client-side element of accepting user messages in a standard way for Command Palette (workflows), Agents, frontend chatbots, et. |
JasonTheAdams
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.
Great work, @felixarntz! It's really cool to see how easily everything translated to JS. I left a couple minor suggestions, but it's all simple so I'll approve now.
| 'minItems' => 2, | ||
| 'maxItems' => 2, |
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.
Why is there a min and max?
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.
It's needed here because the array must have exactly 2 elements (provider ID and model ID).
| register_rest_route( | ||
| 'wp-ai/v1', | ||
| '/generate', |
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.
Do we want to add /generate-text and such endpoints for the corresponding terminating methods? Or just start with the more robust endpoint only?
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.
I think this endpoint is sufficient, since the return shape is always the same, regardless of terminating method. No need for individual endpoints.
Important: This is built on top of #29. That PR must be reviewed and merged first.
This adds a JS equivalent of the server-side prompt builder based API, via
wp.aiClient.prompt.To test:
Make sure you have at least one provider configured with credentials.
Then try something like this in your browser console (make sure to specify at least one model from a configured provider):
You can also try with any of the new JS examples in
README.md.