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
Incorrect streaming chat responses when using Azure OpenAI client's chat completions #8084
Comments
@parthmishra Thanks for reporting this issue 👍 We haven't really looked into |
@LukasMasuch thank you for looking into this! While the issue is specific to |
## Describe your changes This PR adds support for chat streams from AzureOpenAI and implements a couple of other related follow-up improvements. ## GitHub Issue Link (if applicable) - Closes #8084 ## Testing Plan - Updated tests --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
## Describe your changes This PR adds support for chat streams from AzureOpenAI and implements a couple of other related follow-up improvements. ## GitHub Issue Link (if applicable) - Closes streamlit#8084 ## Testing Plan - Updated tests --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Checklist
Summary
When using
write_stream()
with chat completions from the Azure OpenAI client (not the regular one!), the firstChatChunkCompletion
returns an emptychoices
list because it returns extra Responsible AI information first prior to sending the actual chat completions. When attempting towrite_stream()
this, it ends up pre-filling the chat response with the str of the ChatChunkCompletionReproducible Code Example
Steps To Reproduce
write_stream()
to write the streamExpected Behavior
The response should be written if there is actual content to display in the
ChatCompletionChunk
Current Behavior
In the above image you can see that the
choices
list is empty which it's usually not for regular OpenAI client calls.Is this a regression?
Debug info
Additional Information
While this issue is specific to Azure OpenAI client and should ideally be fixed upstream, I don't think it would hurt if Streamlit could do a check in its write API (e.g.
if len(chunk.choices > 0)
) to make sure there is actually content to writeI think it's possible to workaround this as user by just swallowing the first chunk of the stream (e.g.
next(stream)
) before sending towrite_stream()
but I haven't tried yet.Same as this issue: microsoft/semantic-kernel#3650
See other examples of guarding against this: AbanteAI/mentat#430
The text was updated successfully, but these errors were encountered: