#Custom functions

1 messages · Page 1 of 1 (latest)

fringe turtle
#

I am receiving this javascript error after gettting a response back from my function when trying to ask another question

An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages

next raptorBOT
#

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

#

This error message indicates that after making a tool call in your assistant message, you must follow it up with a tool message that responds to each tool_call_id. This is a requirement of the OpenAI API.

Here's an example of how you might structure your messages:

{
  "role": "system",
  "content": "You are a helpful assistant."
},
{
  "role": "user",
  "content": "What's the weather like?",
  "tool_calls": [
    {
      "id": "call_1",
      "type": "function",
      "function": {
        "name": "getWeather",
        "arguments": "Tokyo"
      }
    }
  ]
},
{
  "role": "tool",
  "tool_call_id": "call_1",
  "content": "The weather in Tokyo is sunny."
}

In this example, the user message includes a tool call to a function named getWeather. The tool message that follows includes the tool_call_id from the user message, indicating that it's a response to that tool call.

If you're still encountering issues, it would be helpful to review your code and ensure that each tool call in your assistant messages is being properly responded to with a tool message. If you're using the OpenAI Python library, you might find the OpenAI Cookbook's guide on handling function calls (https://github.com/openai/openai-cookbook/blob/main/examples/How_to_handle_function_calls.ipynb) useful.

For more detailed information, you can refer to the OpenAI API documentation (https://beta.openai.com/docs/guides/chat/).

Source: OpenAI Community Post (https://community.openai.com/t/535360)

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