OnePrompt also facilitates the utilization of custom plugins generated by users through OpenAI's "Function Calling" feature. For more information about "Function Calling", please visit this OpenAI blog. Custom plugins enable integration with a variety of service APIs, thereby enhancing the AI chat experience for users.
OnePrompt provides custom plugin templates to give users an opportunity to experience custom plugins. Of course, users are free to create custom plugins beyond templates. Later in this article, we will provide a detailed description of how to create custom plugins.
Tap "Custom Plugins" in Settings screen.
Popular API services are accessible through custom plugins.
Supporting API key and other setup.
Custom plugins for OnePrompt are described using JSON data structures. JSON data consists of four key elements: "name", "description", "functions" and "plugins". Only JSON response data is supported by custom plugins. See the "Custom Plugin Data" table below in detail.
Key | Description |
---|---|
name | String. Title shown in the plugin menu |
description | String. Text applied as "system prompt" |
functions | Array. Contains "function data" (see below) |
plugins | Array. Contains "plugin data" (see below) |
The functions in custom plugin data is the same as "functions" defined in API reference. Each function consists of three key elements: "name", "description" and "parameters". See the "Function Data" table below in detail.
Key | Description |
---|---|
name | String. Function name |
description | String. Detailed function descriptions |
parameters | Dictionary. See function parameters |
The plugins in custom plugin data is JSON object contains "plugin". Each plugin consists of five key elements: "plugin_name", "http_method", "url_string","parameters" and "filter". See the "Plugin Data" table below in detail.
Key | Description |
---|---|
plugin_name | String. Same name as the corresponding function name |
http_method | String. HTTP method name, ether "GET" or "POST" |
url_string | String. Endpoint URL of Rest API |
parameters | Dictionary. Contains the constant key-value pairs defined in the Rest API (optional) |
filter | Dictionary. Used to extract only the desired keys from the response data. (optional) |
The filter in plugin data consists of three key elements: "paths", "type" and "keys". The filter can be used to reduce the number of tokens by extracting only the necessary keys from the response data. See the "Filter Data" table below in detail.
Key | Description |
---|---|
paths | Array. Keys containing the data you want to extract as path |
type | String. The value type indicated by last key in paths ether "array" or "dictionary" |
keys | Array. Desired keys to use chat response |
Let's create a custom plugin using the "Programmable Search Engine". Here is the entire plugin code provided for your reference, which you can study to create a custom plugin. And this is the Node.js code to confirm the response of the Google Custom Search API.
{
"name": "Google Search Plugin",
"description": "You can search information with [keywords] that are extracted in order to satisfy user's request. The [keywords] must be separated by white space.",
"functions": [
{
"name": "custom_search",
"description" : "Search information with keywords.",
"parameters": {
"type": "object",
"properties": {
"q": {
"type": "string",
"description" : "Set search keywords separated by white space."
}
},
"required": [ "q" ]
}
}
],
"plugins": [
{
"plugin_name": "custom_search",
"http_method": "GET",
"url_string": "https://customsearch.googleapis.com/customsearch/v1",
"parameters": {
"key": "Your-API-Key",
"cx": "Your-Search-Engine-ID",
"c2coff": 1,
"lr": "lang_en",
"hl": "en",
"num": 5,
"filter": 1
},
"filter": {
"paths": [
"items"
],
"type": "array",
"keys": [
"title",
"snippet",
"link"
]
}
}
]
}
The data structures in the "functions" section are exactly the same as those defined in the OpenAI API reference for "functions". The parameter name "q" in the "properties" section corresponds to the parameter name in the query parameters of the Custom Search JSON API reference. It's essential to ensure that the keys within the properties section match the query parameters specified in the API reference - this rule is of utmost significance when crafting the custom plugin.
In the "plugins" section, "parameters" refers to a dictionary (aka an associative array) of fixed values that will be sent to the API. This field can be omitted, especially when there is no API key or other relevant information. In the context of "plugins", the term "filter" instructs to target the "items" field within the response data of type "array". It further directs the extraction of specific fields such as "title", "snippet" and "link" as indicated by the contents of the "keys".
To use the custom plugin you've created, launch the Files.app and copy the plugin file to the "Plugins" folder of OnePrompt on your local device. After opening the chat screen, you'll come across the puzzle piece icon in case the custom plugin is accessible. Tap on the puzzle piece icon and choose the custom plugin you wish to utilize. When using the custom search plugin, input a sentence with particular keywords, and you'll obtain the relevant search results.
Open the "Files.app" and then copy the plugin file you've created to the "Plugins" folder within OnePrompt in the local iOS device.
Access the chat screen, then tap on the puzzle piece icon. From there, choose the plugin you've created.
Enter a sentence containing search keywords and the search results corresponding to the keywords will be displayed.
Below is an illustration of using the "YouTube Data API to Search for Content" as a custom plugin. Here is the complete plugin code provided for your convenience. Additionally, the following Node.js code demonstrates how to verify the response from the YouTube Search API.
{
"name": "YouTube Search Plugin",
"description": "You can perform searches on YouTube videos using [keywords] to fulfill user requests. The [keywords] must be separated by spaces. The output for search results must be contains the [videoTitle] and [videoDescription], and include the video's URL in the following format: https://www.youtube.com/watch?v=[videoId]. From the search results, please extract the [videoTitle], [videoDescription], and [videoId]. Lastly, please kindly provide a response in the same language as the one entered by the user.",
"functions": [
{
"name": "youtube_search",
"description" : "Perform searches on YouTube videos to fulfill user requests.",
"parameters": {
"type": "object",
"properties": {
"q": {
"type": "string",
"description" : "Search keywords separated by spaces."
}
},
"required": [ "q" ]
}
}
],
"plugins": [
{
"plugin_name": "youtube_search",
"http_method": "GET",
"url_string": "https://www.googleapis.com/youtube/v3/search",
"parameters": {
"key": "Your-API-Key",
"part": "id,snippet",
"type": "video",
"order": "relevance",
"maxResults": 5,
"regionCode": "en"
},
"filter": {
"paths": [
"items"
],
"type": "array",
"keys": [
"id.videoId",
"snippet.title:videoTitle",
"snippet.description:videoDescription"
]
}
}
]
}
The primary distinction compared to the plugin code above lies in the content of the "keys" within the "filter" section. The value of each key is used to extract the content of the response with the data structure below which contains dictionary data. The newly designated key for the response of the function call is the string on the right side, separated by a dot. For instance, "videoId" would be the key for "id.videoId".
For the key "snippet.title:videoTitle", it indicates the replacement of the value "title" within the key separated by a dot with the specified alias "videoTitle". The same principle applies to "snippet.description:videoDescription" as well. This is very useful when explicitly directing keywords at the system prompt.
{
"items": [
{
"id": {
"videoId": "VIDEO-ID",
...
},
"snippet": {
"title": "VIDEO-TITLE",
"description": "VIDEO-DESCRIPTION",
...
},
...
}
]
}
Access the chat screen, then tap on the puzzle piece icon. From there, choose the YouTube Search plugin you've created.
Input the text containing keywords to search for YouTube videos.
The ChatLog screen enables you to view the contents of the data structure that provided a response to the "function call".
To display the logs for "function call", enable the "Shows Function Chain in ChatLog" option in the "For Developer" section of the "Settings" screen.
OnePrompt can be used on all your iOS devices.