Skip to content

OpenAI function calling broken since 3.19.0 #224

@garraflavatra

Description

@garraflavatra

Hi, it seems that since v3.19.0, the function parameter chunks fetched using the completions API of the synchronous OpenAI API wrapper with stream=True are duplicated, resulting in invalid JSON, e.g. {"{"processprocess_id_id":2}:2} instead of just {"process_id":2}. The "normal" responses work fine though.

I use the following logic to concatenate the chunks, which worked before v3.19.0:

final_tool_calls = {}

for chunk in response:
    delta = chunk.choices[0].delta

    if delta.tool_calls:
        for tool_call in delta.tool_calls:
            index = tool_call.index

            if index not in final_tool_calls:
                final_tool_calls[index] = tool_call

            final_tool_calls[index].function.arguments += tool_call.function.arguments

I suppose the following line causes the issue. It does exactly the same as my code, including manipulating the original function object. Maybe that should be cloned first?

accumulated_tools[index].function.arguments += tool_call.function.arguments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions