OpenAI: Run Assistant action
- Updated: 2024/07/19
OpenAI: Run Assistant action
The OpenAI: Run Assistant action uses OpenAI's Assistant API (v2) to build AI assistants within your own applications. An Assistant has instructions and can leverage models, tools, and knowledge to respond to user queries. The v2 Assistants API currently supports three types of tools: Code Interpreter, File search, and Function calling.
Prerequisites
- You must have the Bot creator role to use the OpenAI Run Assistant action in an automation.
- Ensure that you have the necessary credentials to send a request and have included OpenAI: Authenticate action before calling any OpenAI actions.
- Understanding the assistant limitations: Knowing the assistant's capabilities and limitations helps you to set realistic expectations.
This example shows how to load an existing assistant in the OpenAI Run Assistant action and get an appropriate response. If you are interested to learn how to create your own assistant, see OpenAI Create Assistant.
Procedure
The following example demonstrates how to use the assistant with the code interpreter enabled to generate the first eight terms of the Fibonacci sequence.
The response of the above automation is as follows:
{
"metadata": {},
"data": [
{
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "The first 8 terms of the Fibonacci sequence are: \n\n\\[0, 1, 1, 2, 3, 5, 8, 13\\]",
"annotations": []
}
}
]
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. Let's generate the first 8 terms of the Fibonacci sequence.",
"annotations": []
}
}
]
}
],
"status": "completed"
}
The following example demonstrates how to use the assistant with File search enabled. In this scenario, the assistant reads the attached file to generate the response.
The response of the above automation is as follows:
{
"metadata": {},
"data": [
{
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "Here are the holidays listed in the attached file:\n\n1. New Year's Day\n2. Martin Luther King Jr. Day\n3. Presidents' Day\n4. Memorial Day\n5. Independence Day\n6. Labor Day\n7. Columbus Day\n8. Veterans Day\n9. Thanksgiving Day\n10. Christmas Day\n\nThese holidays were found within the attached document .",
"annotations": []
}
}
]
}
],
"status": "completed"
}
- To upload multiple files, you can add a list of File IDs. These File IDs are unique identifiers assigned to files uploaded using the OpenAI. For more information on uploading and retrieving Files in a Assistant, see OpenAI Files Operations
- The Control Room files or desktop files uploaded to OpenAI can be found on the OpenAI storage.
The following example
demonstrates how to use the assistant with a function. In this scenario, imagine you
want your assistant to retrieve weather information. By feeding it a new function
named get_weather
(along with a description and parameters), you
equip the assistant with this new skill.
{
"name": "get_weather",
"description": "Determine weather in my location",
"parameters":
{
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"c",
"f"
]
}
},
"required": [
"location"
]
}
}
The JSON output following the below image highlights the assistant's status as
requires_action
. This indicates that the assistant awaits your
input on how to proceed. You can now leverage the OpenAI: Run Assistant Function action
to instruct the assistant on how to use the newly introduced
get_weather
function and formulate an appropriate response
based on the retrieved data.
The response of the above automation is as follows:
{
"data":{
"thread_id":"thread_Sizn8HNIKH5NzDYXQ61n05RC",
"tool_calls":[
{
"id":"call_wCWp3g9fdWLszmSvUMqglyW5",
"type":"function",
"function":{
"name":"get_weather",
"arguments":"{\"location\":\"Chicago, IL\"}"
}
}
],
"id":"run_MBq3pioUk9K0NaREPOIY4qFG"
},
"status":"requires_action"
}
You can use the thread id, call id and run id from the JSON to call the
OpenAI: Run Assistant Function action.