API unstable with function calls (on both Both 4K and 16K 3.5 Models)

I developed a small chat app that uses functions like Google search, URL download, file access, etc. Just basic implementation to experiment with tools. The mechanism works beautifully, but the OpenAI API response is (very) unreliable, failing completely about 50% of the times randomly when functions are used. Digging into the code I found that as soon as a function is defined in the request, (and not necessarily when the model uses it) the API becomes sketchy and responds error messages.

Here’s a screenshot of how things looks when it works, and below some examples of when id doesn’t.

"data":{
   "error":{
      "message":"The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error. (Please include the request ID 62f54e5eefffc42225377c7b75098ecc in your email.)",
      "type":"server_error",
      "param":null,
      "code":null
   }
}"data":[
   "DONE"
]

I contacted openAI and they suggested I hit the rate limit - but I’m the only one using the account as a developer so I know that’s not the case, and besides removing the function definitions solves the issue immediately. Here’s an example of the full request and response:

Request Body:

{
   "messages":[
      {
         "role":"system",
         "content":"\u0022You are Chat GPT, a versatile AI assistant specializing in Agent with Tools.\r\n .\u0022"
      },
      {
         "role":"user",
         "content":"hi",
         "name":"user"
      },
      {
         "role":"assistant",
         "content":"Hello! How can I assist you today?",
         "name":"assistant"
      },
      {
         "role":"user",
         "content":"how are you?",
         "name":"user"
      },
      {
         "role":"assistant",
         "content":"Thank you for asking! As an AI, I don\u0027t have feelings, but I\u0027m here and ready to help you with any questions or tasks you have. How can I assist you today?",
         "name":"assistant"
      },
      {
         "role":"user",
         "content":"tell me about your team",
         "name":"user"
      },
      {
         "role":"user",
         "content":"hi",
         "name":"user"
      }
   ],
   "functions":[
      {
         "name":"googleSearch",
         "description":"Search the web with Google",
         "parameters":{
            "type":"object",
            "properties":{
               "SearchTerm":{
                  "type":"string",
                  "description":"Search term to look for"
               }
            },
            "required":[
               "SearchTerm"
            ]
         }
      },
      {
         "name":"sendEmail",
         "description":"Send an Email to an Email address",
         "parameters":{
            "type":"object",
            "properties":{
               "EmailAddress":{
                  "type":"string",
                  "description":"Email Address of Recepient"
               },
               "Subject":{
                  "type":"string",
                  "description":"Subject of Email "
               },
               "EmailBody":{
                  "type":"string",
                  "description":"Content of Email "
               }
            },
            "required":[
               "EmailAddress",
               "Subject",
               "EmailBody"
            ]
         }
      }
   ],
   "stream":true,
   "model":"gpt-3.5-turbo-16k",
   "temperature":0.1,
   "function_call":"auto"
}

Response Headers:
Date : wed, 21 jun 2023 00:26:51 gmt content-type : text/event-stream transfer-encoding : chunked connection : close access-control-allow-origin : * cache-control : no-cache, must-revalidate openai-organization : XXXXX openai-processing-ms : 26 openai-version : 2020-10-01 strict-transport-security : max-age=15724800; includesubdomains x-ratelimit-limit-requests : 3500 x-ratelimit-limit-tokens : 180000 x-ratelimit-remaining-requests : 3499 x-ratelimit-remaining-tokens : 179895 x-ratelimit-reset-requests : 17ms x-ratelimit-reset-tokens : 35ms x-request-id : XXX cf-cache-status : dynamic server : cloudflare cf-ray : XXX alt-svc : h3=":443"; ma=86400

Response Body:

"data":{
   "error":{
      "message":"The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error. (Please include the request ID 62f54e5eefffc42225377c7b75098ecc in your email.)",
      "type":"server_error",
      "param":null,
      "code":null
   }
}"data":[
   "DONE"
]

Does any of you encounter similar issues? Any ideas? the only reference I could found was on Izmu’s blog: 'Function calling', OpenAI's API new feature.

2 Likes

I am not sure if this applies to you but when I was testing before I forgot to set the model to “gpt-3.5-turbo-0613” and got error in response.

3 Likes

Thanks. My model is set to “gpt-3.5-turbo-16k”. The API suffers from the same behavior with “gpt-3.5-turbo-0613”

1 Like

Maybe a cloudflare timeout problem? I did only read about 50% of your post though.
Maybe the functions take too long?

1 Like

Another example of failed request:

Request Body:

{
  "messages": [
    {
      "role": "system",
      "content": "\\u0022You are Chat GPT, a versatile AI assistant specializing in Agent with Tools.\r\nYour expertise: .\\u0022"
    },
    {
      "role": "user",
      "content": "based on the user request stored in hello.txt write a recipe and save it to recipe.txt",
      "name": "user"
    },
    {
      "role": "assistant",
      "content": "",
      "name": "assistant",
      "function_call": {
        "name": "readFile",
        "arguments": "{ \\u0022FileName\\u0022: \\u0022hello.txt\\u0022}"
      }
    },
    {
      "role": "function",
      "content": "I love poppy seed cakes\r\nepsecially with pears\r\n",
      "name": "readFile"
    }
  ],
  "functions": [
    {
      "name": "readFile",
      "description": "Reads a file from storage",
      "parameters": {
        "type": "object",
        "properties": {
          "FileName": {
            "type": "string",
            "description": "Name of file to read "
          }
        },
        "required": [
          "FileName"
        ]
      }
    },
    {
      "name": "writeFile",
      "description": "Writes a file to storage, overwriting it completely.",
      "parameters": {
        "type": "object",
        "properties": {
          "FileName": {
            "type": "string",
            "description": "Name of file to write"
          },
          "Content": {
            "type": "string",
            "description": "Content of file to write"
          }
        },
        "required": [
          "FileName",
          "Content"
        ]
      }
    },
    {
      "name": "googleSearch",
      "description": "Search the web with Google",
      "parameters": {
        "type": "object",
        "properties": {
          "SearchTerm": {
            "type": "string",
            "description": "Search term to look for"
          }
        },
        "required": [
          "SearchTerm"
        ]
      }
    },
    {
      "name": "sendEmail",
      "description": "Send an Email to an Email address",
      "parameters": {
        "type": "object",
        "properties": {
          "EmailAddress": {
            "type": "string",
            "description": "Email Address of Recepient"
          },
          "Subject": {
            "type": "string",
            "description": "Subject of Email "
          },
          "EmailBody": {
            "type": "string",
            "description": "Content of Email "
          }
        },
        "required": [
          "EmailAddress",
          "Subject",
          "EmailBody"
        ]
      }
    }
  ],
  "stream": true,
  "model": "gpt-3.5-turbo-16k",
  "temperature": 0.1,
  "function_call": "auto"
}

Response:

{
  "error": {
    "message": "The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error. (Please include the request ID 441c93542e64a27a77ba2f343cc89f1f in your email.)",
    "type": "server_error",
    "param": null,
    "code": null
  }
}
1 Like

I made a quick test with your data, it gives proper responses. So there might be some issue elsewhere, did you contact the support with the request id?

2 Likes

I get good working responses about 50% of the time, and the error message I shared in the other half of times. As you can see, the entire message thread was created automatically and then failed in the last call. I contacted OpenAI and they said it’s rate limit but I don’t get those error messages without function calls, and I implemented a 500ms wait between calls. Can you try running it a few more times and see if you encounter any issue? :pray:

1 Like

I was seeing similar errors to yours, both with synchronous calls as well as streaming responses, while using functions, which went away when not using them.
The only pattern I’ve identified, was the usage of the “name” attribute in the messages.
When using “name” (in my case I was doing multi-user chat using that name property), it would consistently fail as soon as functions came into play in the history.
As soon as I remove names from the user messages in the chat history, everything works again.

3 Likes

Spot on. That solved most of the issues.
Another issue I found was extra sensitivity for the arguments formatting of the function call, especially if its rich text. The text needs to be escaped properly, and backtick is weird.

2 Likes

Awesome! At least I’m not the only one causing 500 errors when using name attributes.
Now, if only we could report that issue somewhere! I’d love to be able to use the attribute instead of clunky 'UserX says “something” '.

1 Like

Just want to report that I am also getting this error. Also, pabloromeo’s solution works for me too. I too was using the ‘name’ in the assistant’s messages that caused this trouble.

I too am building multi-agent applications. Being able to use the name attribute seems important to me. Do wish there is some way to report this to OpenAI eng.

1 Like

The workaround I’m using for mult-user chat, given the presence of that bug, is basically to build a user message without the name, and the content being something along the lines of:
{the username} says “{their actual message}”

Not very elegant, but for the time being it works.
Let’s hope someone in OpenAI sees this, or somebody else manages to report the issue to them. I’ve reported it with the Support bot, so I guess we have to wait.

2 Likes

Chiming in to say that I’ve started getting random 500 on gpt-3.5-turbo-16k when I’ve started adding name attributes. Specifically I get streaming errors randomly about 40% of the times when the model has multiple functions that might decide to call.

1 Like

This would be consistent with others findings as well, could you post a code snippet of your use of “names” so I can check?

1 Like

Brilliant, I was also having this issue and I came across this thread in the community. Removing names for the user has solved the problem.