The AI Assistant plugin allows a user to interact with registered AI APIs by sending queries and viewing responses within a {productname} editor dialog.
Once a response is generated and displayed within the dialog, the user can choose to either:
-
insert it into the editor at the current selection;
-
create another query to further refine the response generated by the AI; or
-
close the dialog and discard the returned response.
Users can retrieve a history of their conversations with the AI using the getThreadLog API, including any discarded responses.
|
Note
|
This example uses a proxy endpoint to communicate with the OpenAI API. This is done to avoid exposing the API key in the client-side code. For more information on using a proxy server with the AI Assistant plugin, see the AI Proxy Server reference guide. |
liveDemo::ai[]
To add the AI Assistant plugin to the editor, follow these steps:
-
Add
aito thepluginsoption in the editor configuration. -
Add the
ai_requestfunction to the editor configuration.
For example:
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugins: 'ai',
toolbar: 'aidialog aishortcuts',
ai_request: <AI_REQUEST_FUNCTION>,
});|
Note
|
As per OpenAI’s best practices for API key safety, deployment of an API key in a client-side environment is specifically not recommended. |
Using a proxy server obviates this, reducing financial and service uptime risks.
A proxy server can also provide flexibility by allowing extra processing before the request is sent to an LLM AI endpoint and before returning the response to the user.
See the AI Proxy Server reference guide for information on how to setup a proxy server for use with the AI Assistant.
|
Note
|
The AI Proxy Server reference guide is, as its name notes, a reference. There is no single proxy server setup that is right or correct for all circumstances and other setups may be better for your use-case. |
The following configuration options affect the behavior of the AI Assistant plugin.
The AI Assistant plugin provides the following {productname} commands.
The AI Assistant plugin provides the following events.
The AI Assistant plugin provides the following APIs.