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 for Exception raised while parsing Chat Completions streaming response, in some rare cases #39741

Conversation

dargilco
Copy link
Member

Description

I finally got one repro of the GitHub issue, while taking SDK logs and using DeepSeek model. That confirmed what I suspected. But I could not understand why the unit-test I added a couple of days ago, streaming Chinese characters broken across lines, did not exhibit the same issue. That unit-test passed.

After investigation turns out I had a bug in the unit-test! Missing comma after one of the SSE lines in the input array for the test. Which miraculously made the unit-test pass, when they should have failed exactly as reported in the GitHub issue.

After I discovered that, it was easy to implement a fix. I updated the logic in the SSE parsing to make sure UTF-8 decoding was moved further down, at the point where we are guaranteed we have a complete line of JSON string, just before deserializing it into the output chunk object. Until that point (including caching the previous incomplete line) the input is still handled as a "bytes" object.

I also updated all streaming samples with extra checks during printing of the streaming response and also printed the token usage. We already did that in the GitHub samples.

@dargilco dargilco requested a review from howieleung February 14, 2025 04:53
@dargilco dargilco self-assigned this Feb 14, 2025
@github-actions github-actions bot added the AI Model Inference Issues related to the client library for Azure AI Model Inference (\sdk\ai\azure-ai-inference) label Feb 14, 2025
@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-ai-inference

@dargilco dargilco merged commit 3dc6388 into feature/azure-ai-inference-beta9 Feb 14, 2025
21 of 24 checks passed
@dargilco dargilco deleted the dargilco/azure-ai-inference-pr-utf8-streaming-fix-part2 branch February 14, 2025 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI Model Inference Issues related to the client library for Azure AI Model Inference (\sdk\ai\azure-ai-inference)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants