Does streaming work with tool_calls yet on AzureOpenAI version 2023-12-01-preview? I'm getting an empty choices array.

Darweenist 5 Reputation points
2024-02-16T00:32:55.79+00:00

I just migrated to the newest OpenAI version which uses tool calls instead of function calls. I set stream = true. Just got it to work with OpenAI, but upon migrating to AzureOpenAI and not changing any code in my tool calls handler, I am getting IndexError: list index out of range on the line delta = res.choices[0].delta :

response_gen

async for res in response_gen:
    delta = res.choices[0].delta

I've seen some issues with AzureOpenAI returning an empty first spot in the array in earlier preview versions. Anyone know what's the issue here? I'm on 2023-12-01-preview, using GPT-4 1106-Preview.

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,933 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Evgeny Minkevich 0 Reputation points
    2024-03-14T18:45:29.5+00:00

    By default Azure OpenAI has content filtering on [1].

    So the first chunk might come with empty "choices". If you skip the chunks with empty "choices" it should work.

    Consider putting something along these lines into your code:

    if not res.choices:
        continue
    

    [1] Azure OpenAI Content Filtering

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.