#How to work with assistant function data?

1 messages · Page 1 of 1 (latest)

bronze lotus
#

I am using a function to give my assistant return value structure and nothing more. How do I extract the data from the function without having to go directly into the function call?

@next kiln

next kilnBOT
#

Hi @bronze lotus. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To work with the data returned by the assistant function, you need to understand that the assistant function doesn't directly call the API. Instead, it provides you with parameters to a function, and you will have to call the API on your backend. The assistant will provide you with the body based on the user prompt source (https://community.openai.com/t/523101).

When you initiate a Run with a user Message that triggers the function, the Run will enter a pending status. After it processes, the run will enter a requires_action state. The model can provide multiple functions to call at once using parallel function calling. You can verify this by retrieving the Run. Here is an example of how the returned data might look like:

{
 "id": "run_abc123",
 "object": "thread.run",
 "assistant_id": "asst_abc123",
 "thread_id": "thread_abc123",
 "status": "requires_action",
 "required_action": {
 "type": "submit_tool_outputs",
 "submit_tool_outputs": {
 "tool_calls": [
 {
 "id": "call_abc123",
 "type": "function",
 "function": {
 "name": "getCurrentWeather",
 "arguments": "{\"location\":\"San Francisco\"}"
 }
 },
 {
 "id": "call_abc456",
 "type": "function",
 "function": {
 "name": "getNickname",
 "arguments": "{\"location\":\"Los Angeles\"}"
 }
 }
 ]
 }
 },
...

source (https://platform.openai.com/docs/assistants/tools)

In this example, the assistant has provided two function calls: getCurrentWeather and getNickname, each with their respective arguments. You can then use this data to call the function in your code.

Remember, any context produced by retrievals or code interpreter will be fed into the prompt as context and charged for as input source (https://community.openai.com/t/504217).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: