|
| 1 | +# Assistants API |
| 2 | + |
| 3 | +Use Connery actions in Function Calling tool of OpenAI Assistants API. |
| 4 | + |
| 5 | +## Information |
| 6 | + |
| 7 | +The Assistants API allows you to build AI assistants within your own applications. |
| 8 | +An Assistant has instructions and can leverage models, tools, and knowledge to respond to user queries. |
| 9 | +The Assistants API currently supports three types of tools: Code Interpreter, Retrieval, and _Function Calling_. |
| 10 | + |
| 11 | +Function calling allows you to describe functions to the Assistants and have it intelligently return the functions that need to be called along with their arguments. |
| 12 | +The Assistants API will pause execution during a Run when it invokes functions, and you can supply the results of the function call back to continue the Run execution. |
| 13 | + |
| 14 | +Connery actions can easily be used in the Function Calling tool of OpenAI Assistants API. |
| 15 | +See below for instructions on configuring and using Connery actions in the Assistant. |
| 16 | + |
| 17 | +:::note Helpful resources |
| 18 | + |
| 19 | +- [OpenAI Assistants API](https://platform.openai.com/docs/assistants/overview/agents) |
| 20 | +- [Funtion Calling](https://platform.openai.com/docs/assistants/tools/function-calling) |
| 21 | + |
| 22 | +::: |
| 23 | + |
| 24 | +## Configuration |
| 25 | + |
| 26 | +### Prerequisites |
| 27 | + |
| 28 | +If you are new to Connery, we recommend you start with the [Quickstart](/docs/platform/quick-start/) guide. |
| 29 | +There, you will find all the information required to set up Connery and start using it. |
| 30 | + |
| 31 | +### Configure functions in the Assistant |
| 32 | + |
| 33 | +1. **Get OpenAI Functions specification for Connery actions installed on the runner.** |
| 34 | + |
| 35 | +``` |
| 36 | +curl -L '<PUBLIC_RUNNER_URL>/v1/actions/specs/openai-functions' \ |
| 37 | +-H 'x-api-key: <CONNERY_RUNNER_API_KEY>' |
| 38 | +``` |
| 39 | + |
| 40 | +The `<PUBLIC_RUNNER_URL>` and `<CONNERY_RUNNER_API_KEY>` you should get during the runner setup in the [Quickstart](/docs/platform/quick-start/) guide. |
| 41 | + |
| 42 | +In response, you will get an OpenAI Function specification for every action installed on your Connery runner. |
| 43 | + |
| 44 | +2. **Use the specification to add functions to your assistant.** |
| 45 | + |
| 46 | +You can do it using Assistant API. |
| 47 | +See the [Defining functions](https://platform.openai.com/docs/assistants/tools/defining-functions) section of the Assistants AI documentation for more information. |
| 48 | + |
| 49 | +Also, you can do it on the [Assistants](https://platform.openai.com/assistants) or [Playground](https://platform.openai.com/playground) pages on the OpenAI developer platform. |
| 50 | + |
| 51 | +<p align="center"> |
| 52 | + <img |
| 53 | + src="/img/openai/[email protected]" |
| 54 | + alt="Functions configuration in Assistant" |
| 55 | + /> |
| 56 | +</p> |
| 57 | + |
| 58 | +:::info |
| 59 | + |
| 60 | +The UI does not allow adding an array of functions at once. So you need to add them one by one. |
| 61 | + |
| 62 | +::: |
| 63 | + |
| 64 | +Once you add the functions, you can use them as any other functions in the Function Calling tool of the Assistants API. |
| 65 | + |
| 66 | +## Usage |
| 67 | + |
| 68 | +1. **Get functions from the model that have to be called.** |
| 69 | + |
| 70 | +When you initiate a Run with a user Message that triggers the function, the model can provide multiple functions. |
| 71 | +See the [Reading the functions called by the Assistant](https://platform.openai.com/docs/assistants/tools/reading-the-functions-called-by-the-assistant) section of the Assistants AI documentation for more information. |
| 72 | + |
| 73 | +2. **Resolve the function name to the Connery action.** |
| 74 | + |
| 75 | +``` |
| 76 | +curl -L '<PUBLIC_RUNNER_URL>/v1/actions/specs/resolve-action-from-specs?specActionKey=<FUNCTION_NAME>' \ |
| 77 | +-H 'x-api-key: <CONNERY_RUNNER_API_KEY>' |
| 78 | +``` |
| 79 | + |
| 80 | +Replace `<FUNCTION_NAME>` with the function name you got from the model. |
| 81 | + |
| 82 | +In the response you will get the Plugin ID and Action ID which you can then use to run the action in the runner. |
| 83 | + |
| 84 | +:::info |
| 85 | + |
| 86 | +Because of the limitation of the OpenAI Function schema, we can not put the Plugin ID and Action ID in the function name. |
| 87 | +So, we use a short hashed action key in the OpenIA Function schema. |
| 88 | +Then we resolve it to the Plugin ID and Action ID required to run the action on the runner. |
| 89 | + |
| 90 | +This is a temporary solution which will be adjusted in the future. |
| 91 | + |
| 92 | +::: |
| 93 | + |
| 94 | +3. **Run the action on the runner and get the result.** |
| 95 | + |
| 96 | +Use the following API endpoint to run the action: |
| 97 | + |
| 98 | +``` |
| 99 | +curl -L '<PUBLIC_RUNNER_URL>/v1/plugins/<PLUGIN_ID>/actions/<ACTION_ID>/run' \ |
| 100 | +-H 'Content-Type: application/json' \ |
| 101 | +-H 'x-api-key: <CONNERY_RUNNER_API_KEY>' \ |
| 102 | +-d '<ARGUMENTS>' |
| 103 | +``` |
| 104 | + |
| 105 | +Replace `<PLUGIN_ID>` and `<ACTION_ID>` with the values you got from the previous step. |
| 106 | + |
| 107 | +Replace `<ARGUMENTS>` with the arguments you got from the model. |
| 108 | +It should be a flat JSON object like this: |
| 109 | + |
| 110 | +``` |
| 111 | +{ |
| 112 | + "argument1": "value1", |
| 113 | + "argument2": "value2" |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +After the action is executed, you will get the result in the response. |
| 118 | + |
| 119 | +4. **Send the result back to the model.** |
| 120 | + |
| 121 | +See the [Submitting functions outputs](https://platform.openai.com/docs/assistants/tools/submitting-functions-outputs) section of the Assistants AI documentation for more information. |
| 122 | + |
| 123 | +:::tip One action - multiple opportunities |
| 124 | + |
| 125 | +Once the action is configured on Connery Runner, you can use it not only in the Assistants API but also on many other platforms. |
| 126 | +Check the list of [Clients](/docs/clients/native/) to see what platforms are supported. |
| 127 | + |
| 128 | +::: |
0 commit comments