- Home
- AI
- Configuration
- Adding a custom AI provider
Adding a custom AI provider
The ONLYOFFICE editors allow you to add a custom AI provider and configure it according to your preferences.
Prerequisites
Before adding a custom provider, make sure you complete the following steps:
-
Obtain the necessary credentials from the provider of your choosing:
-
Base URL: The web address where API requests are sent. In some cases, the base URL may include an endpoint that specifies the model being used, for example:
https://dashscope.aliyuncs.com/compatible-mode/ -
Model Version: This identifies the version of the model you are accessing. Sometimes, the model version is included in the base URL, for example,
v1in the following URL:https://api.moonshot.cn/v1 - API Key: A unique key provided by the service provider, used for authentication.
-
Base URL: The web address where API requests are sent. In some cases, the base URL may include an endpoint that specifies the model being used, for example:
Creating the external JavaScript file
To add a custom provider and display it in the list of available providers within the AI Plugin, you need to create and upload an external JS file.
Custom providers parsed from this file are instances of the Provider class, which extends AI.Provider. This class manages all available providers within the plugin.
Below are the parameters of the Provider class:
class Provider {
/**
* Provider base class.
* @param {string} name Provider name.
* @param {string} url Url to service.
* @param {string} key Key for service. This is an optional field. Some providers may require a key for access.
* @param {string} addon Addon for url. For example: v1 for many providers.
*/
constructor(name, url, key, addon) {
this.name = name || "";
this.url = url || "";
this.key = key || "";
this.addon = addon || "";
this.models = [];
this.modelsUI = [];
}
Let's look at implementing the Tongyi Qianwen service as an example:
"use strict";
class Provider extends AI.Provider {
constructor() {
super("Alibaba Cloud", "https://dashscope.aliyuncs.com/compatible-mode", "yourAPIKey", "v1");
}
}
Where:
- Alibaba Cloud is the name of the provider that will be displayed in the plugin.
- https://dashscope.aliyuncs.com/compatible-mode is the web address to which we are sending the API request.
- yourAPIKey is the API key issued by the provider.
- v1 is the version of the model to which we are sending the API request.
Adding a custom provider
- Right-click on any selected word and navigate to AI → Settings in the contextual menu.
- In the AI Configuration window, select Edit AI models.
- In the AI Models list window, click the pencil icon to edit models.
- In the Edit AI Model window, click custom providers in the bottom left corner of the window.
- Click the plus icon and upload the JavaScript file containing your custom provider settings.
- Click Back to exit the Add AI Model window.
- Select your custom provider from the list in the Add AI Model window and click OK.
- Click Back to exit the AI Models list window.
- Set your custom provider model for a specific task in the AI Configuration window.
Article with the tag:
Browse all tags