Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ID field to be optional #911

Merged
merged 1 commit into from
Dec 8, 2024
Merged

Conversation

TimMisiak
Copy link
Contributor

@TimMisiak TimMisiak commented Dec 5, 2024

When testing tool calls in streaming mode I noticed that I was getting entirely empty deltas. Dumping the json before trying to deserialize showed that the "id" field is missing after the first message, but the json annotation has the field as required. Here's an example json:

{
    "id": "chatcmpl-...",
    "object": "chat.completion.chunk",
    "created": 1733436687,
    "model": "gpt-4o-2024-08-06",
    "system_fingerprint": "fp_...",
    "choices": [
        {
            "index": 0,
            "delta": {
                "tool_calls": [
                    {
                        "index": 0,
                        "function": {
                            "arguments": "{\""
                        }
                    }
                ]
            },
            "logprobs": null,
            "finish_reason": null
        }
    ]
}

Adding "omitempty" seems to let the json parse correctly and shouldn't break existing users. I tested these changes in a local copy of the lib and it was able to parse successfully.

The ID field is not always present for streaming responses. Without omitempty, the entire ToolCall struct will be missing.
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.69%. Comparing base (774fc9d) to head (b631ade).
Report is 76 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #911      +/-   ##
==========================================
+ Coverage   98.46%   98.69%   +0.23%     
==========================================
  Files          24       26       +2     
  Lines        1364     1761     +397     
==========================================
+ Hits         1343     1738     +395     
- Misses         15       16       +1     
- Partials        6        7       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@sashabaranov sashabaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@sashabaranov sashabaranov merged commit af5355f into sashabaranov:master Dec 8, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants