-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[BUG] Cancelling GetChatCompletionsStreaming throws error #37163
Labels
Client
This issue points to a problem in the data-plane of the library.
customer-reported
Issues that are reported by GitHub users external to the Azure organization.
needs-team-attention
Workflow: This issue needs attention from Azure service team or SDK team
OpenAI
question
The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Service Attention
Workflow: This issue is responsible by Azure service team.
Comments
Thank you for your feedback. This has been routed to the support team for assistance. |
Adding Service team to look into this. |
Was having the same issue in beta 5, updating to beta 6 fixed it. |
I'm still seeing the exception on the FWIW here's the PR which should fix it: #37984 and here's a full repro script: using Azure.AI.OpenAI;
public static class Program
{
public static async Task StreamingChatWithNonAzureOpenAI()
{
var apiKey = Environment.GetEnvironmentVariable("OPENAI_KEY");
var client = new OpenAIClient(apiKey, new OpenAIClientOptions());
var chatCompletionsOptions = new ChatCompletionsOptions() {
Messages = {
new ChatMessage(ChatRole.System, "You are a helpful assistant."),
new ChatMessage(ChatRole.User, "Please write me a long essay about cats."),
}
};
var tokenSource = new CancellationTokenSource();
var counter = 10;
var token = tokenSource.Token;
var response = await client.GetChatCompletionsStreamingAsync(
deploymentOrModelName: "gpt-3.5-turbo",
chatCompletionsOptions,
token
);
using var completions = response.Value;
await foreach (var choice in completions.GetChoicesStreaming(token))
await foreach (var message in choice.GetMessageStreaming(token)) {
Console.Write(message.Content);
if ( --counter == 0)
tokenSource.Cancel();
}
}
public static void Main()
{
StreamingChatWithNonAzureOpenAI().GetAwaiter().GetResult();
Thread.Sleep(1000);
}
} Results in:
|
when will this fix be released? |
This was referenced Aug 11, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
Client
This issue points to a problem in the data-plane of the library.
customer-reported
Issues that are reported by GitHub users external to the Azure organization.
needs-team-attention
Workflow: This issue needs attention from Azure service team or SDK team
OpenAI
question
The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Service Attention
Workflow: This issue is responsible by Azure service team.
Library name and version
Azure.AI.OpenAI 1.0.0-beta.5
Describe the bug
I'm streaming the response from
GetChatCompletionsStreamingAsync
through a WebAPI endpoint. The stream is consumed from web client usingconst reader = response.body?.getReader();
and if I callreader.cancel()
I will get an exception in IIS server.Simplified my code looks something like this in a service method
which is then further filtered down to
IAsyncEnumerable<string>
at the endpoint usingCancellation works fine, but I am concerned about the exception. Is it expected behaviour or am I using the stream/
CancellationToken
wrong somehow? The documentation/samples on how to properly stream data using the streaming methods are a bit thin so I might have missed something along the way.A sidenote, I found that I had to use ...
... to actually make the streaming work properly, perhaps this should be noted somewhere in the docs/examples as well.
Expected behavior
No exceptions thrown
Actual behavior
Reproduction Steps
See description
Environment
.NET SDK:
Version: 7.0.302
Commit: 990cf98a27
Runtime Environment:
OS Name: Windows
OS Version: 10.0.23481
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.302\
Host:
Version: 7.0.7
Architecture: x64
Commit: 5b20af47d9
The text was updated successfully, but these errors were encountered: