Multi Function Call at once **NOT WORKING** for GPT-3.5-turbo-1106

Multi Function calls not working well when using gpt-3.5-turbo-1106.

When using gpt-4-turbo-1106 for the same code and question the function calls works as expected. When switching to gpt-3.5-turbo-1106 it call only once and the assistent response never comes, causing an error.

For example: Let’s say I want get_weather from Paris and Rio. When using gpt-4-turbo-1106 it correctly calls get_weather 2 times in the same request. When just switching the model to gpt-3.5-turbo-1106 it doesnt work. But the wierd thing is, if I include in the question that “What’s the weather in Paris and Rio, you can call the same function twice” it works! I also tried to put in the system instructions but doesnt have effect.

1 Like

I tested your query in gpt-3.5-turbo-1106.
I added date because it is required in my function.

What’s the weather in Paris and Rio today?

Output:

{
  index: 0,
  message: {
    role: 'assistant',
    content: null,
    tool_calls: [
  {
    id: 'call_Ubz0o58GQ2IL8nYg4RgUeI7y',
    type: 'function',
    function: {
      name: 'get_weather',
      arguments: '{"location": "Paris", "date": "2023-11-14"}'
    }
  },
  {
    id: 'call_IEWgtMDKjl6RUwnVZEI8tbKn',
    type: 'function',
    function: {
      name: 'get_weather',
      arguments: '{"location": "Rio", "date": "2023-11-14"}'
    }
  }
]
  },
  finish_reason: 'tool_calls'
}

My get_weather function:

{
    "name": "get_weather",
    "description": "Get the weather forecast based on the given location and date",
    "parameters": {
      "type": "object",
      "properties": {
        "location": {
          "type": "string",
          "description": "Location or place name"
        },
        "date": {
            "type": "string",
            "description": "Date of forecast"
          }
      },
      "required": [
        "location",
        "date"
      ]
    }
}
1 Like

@supershaneski, I appreciate your timing trying to help me. But yeah, for simple examples like what I did the model most of the time works. Try now:

{
    type: 'function',
    function: {
      name: 'get_sma_or_ema_trend',
      description:
        'Get the trend of a stock based on its symbol and period. It can be Simple Moving Average or Exponential Moving Average.',
      parameters: {
        type: 'object',
        properties: {
          symbol: {
            type: 'string',
            description: 'Stock symbol',
          },
          period: {
            type: 'number',
            description: 'Moving average period',
          },
          type: {
            type: 'string',
            description: 'Moving average type, valid values: sma, ema',
          },
        },
        required: ['symbol', 'period', 'type'],
      },
    },
  }

I tried your prompt and just tweaked the name a bit:

{
    "name": "get_stock_moving_average_trend",
    "description": "Get the trend of a stock based on its symbol and period. It can be Simple Moving Average or Exponential Moving Average.",
    "parameters": {
      "type": "object",
      "properties": {
        "symbol": {
          "type": "string",
          "description": "Stock symbol"
        },
        "period": {
          "type": "number",
          "description": "Moving average period"
        },
        "type": {
          "type": "string",
          "description": "Moving average type, valid values: sma, ema"
        }
      },
      "required": ["symbol", "period", "type"]
    }
}

Using this prompt:

i wanna to know the trend in the following stocks i am interested. APPL, MSFT, GOOGL. say for the last 7 days. for AAPL and MSFT, i want the sma. for GOOGL, i want ema but make the period just 5 days. oh, can you also get AMZN. also sma, also 7 days.

Output:

{
  index: 0,
  message: {
    role: 'assistant',
    content: null,
    tool_calls: [
  {
    id: 'call_83hBoQ6Mx144fPB6f3kQVH53',
    type: 'function',
    function: {
      name: 'get_stock_moving_average_trend',
      arguments: '{"symbol": "AAPL", "period": 7, "type": "sma"}'
    }
  },
  {
    id: 'call_foYfRhd35Ob6ANaUxYArwmzL',
    type: 'function',
    function: {
      name: 'get_stock_moving_average_trend',
      arguments: '{"symbol": "MSFT", "period": 7, "type": "sma"}'
    }
  },
  {
    id: 'call_JmiRTo6ZykqQyo4afJZbREPV',
    type: 'function',
    function: {
      name: 'get_stock_moving_average_trend',
      arguments: '{"symbol": "GOOGL", "period": 5, "type": "ema"}'
    }
  },
  {
    id: 'call_eq3ecQGjMdSBKyG80RC3IJtc',
    type: 'function',
    function: {
      name: 'get_stock_moving_average_trend',
      arguments: '{"symbol": "AMZN", "period": 7, "type": "sma"}'
    }
  }
]
  },
  finish_reason: 'tool_calls'
}

@supershaneski, please, try prompt “What’s the movel average 9 and 21 for AAPL?”. And What I face is only the call for period 9 and no assistant conclusion. Other than that, just to put some more details, I’m using the “stream” method. And also not using the Assistent new feature. That’s the comun chat completation stream:true.

You gonna notice that the model undestands only to call the first 9 periods. Leading in a bug.

So the model, probably realizes he doesnt have all and instead conclude the answer to the user the model try again, calling the second function, which crash the code because it’s considering the calling of all necessary functions at once.

When switching to GPT4 preview 1106 all functions are correctly called at once with same question, same code.

What I can do to deal with it is loop over the model answers and re-call the model again but it sounds like the old way we would not need anymore. Got it?

You need to handle this because this is how the AI finds the correct response to your query specially for compound queries. I will try your sample function again using stream.

1 Like

Hey, sorry this is completely unrealted to the question (however I did notice that when switching to gpt-4-1106-preview multiple function calls were working nearly 100% of the time) but I was wondering if you could share the code on how you got streaming to work with the tool/function calls?

If you could share your code that’d be awesome!

Hi, @Xeniox. I can’t share but you can easily get a rid looking to the Stream tutorial at OpenAI Platform

just console.log the chunks and you gonna get it.

So I tried your prompt and using stream=true.

user: What’s the movel average 9 and 21 for AAPL?
assistant: The simple moving average (SMA) for AAPL with a period of 9 is 92.69, and with a period of 21 is 50.2.

Raw output (screenshots):


It took 3 API calls.