You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After starting the streaming of the first chunk and issuing Cancel on the token, the stream is not cancelled and continues to give the remaining chunks.
To Reproduce
Important
This example uses the AzureOpenAIClient but the CancellationToken behavior is inherited from the OpenAIClient.
Failing xUnit Reproduction Code (should Pass)
[Fact]publicasyncTaskItCancellationWorksAsExpectedAfterFirstChunkSuccessful2Async(){// ArrangeusingvarstreamText=newMemoryStream(Encoding.UTF8.GetBytes(""" data: {"id":"Eoo","object":"chat.completion.chunk","created":1711377846,"model":"gpt-4-0125-preview","system_fingerprint":"fp_a7daf7c51e","choices":[{"index":0,"delta":{"content":"Test chat streaming response"},"logprobs":null,"finish_reason":null}]} data: {"id":"Eoo","object":"chat.completion.chunk","created":1711377846,"model":"gpt-4-0125-preview","system_fingerprint":"fp_a7daf7c51e","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]} data: [DONE] """));usingvarresponse=newHttpResponseMessage(HttpStatusCode.OK){Content=newStreamContent(streamText)};this._messageHandlerStub.ResponsesToReturn.Add(response);varazureClient=newAzureOpenAIClient(newUri("http://localhost"),"api-key",newAzureOpenAIClientOptions{Transport=newHttpClientPipelineTransport(this._httpClient)});usingvarcancellationTokenSource=newCancellationTokenSource();cancellationTokenSource.CancelAfter(1000);varsut=azureClient.GetChatClient("mock-model");// Act & Assertvarenumerator=sut.CompleteChatStreamingAsync(["Hello!"],cancellationToken:cancellationTokenSource.Token).GetAsyncEnumerator();awaitenumerator.MoveNextAsync();varfirstChunk=enumerator.Current;Assert.False(cancellationTokenSource.IsCancellationRequested);awaitTask.Delay(1000);awaitAssert.ThrowsAsync<TaskCanceledException>(async()=>{// Should throw for the second chunkAssert.True(cancellationTokenSource.IsCancellationRequested);Assert.True(cancellationTokenSource.Token.IsCancellationRequested);awaitenumerator.MoveNextAsync();awaitenumerator.MoveNextAsync();});}
Code snippets
No response
OS
Windows 11
.NET version
.net 8
Library version
beta.11
The text was updated successfully, but these errors were encountered:
Confirm this is not an issue with the OpenAI Python Library
Confirm this is not an issue with the underlying OpenAI API
Confirm this is not an issue with Azure OpenAI
Describe the bug
We got an issue raised at Semantic Kernel that ended up also being a potential bug on the SDK implementation.
After starting the streaming of the first chunk and issuing
Cancel
on the token, the stream is not cancelled and continues to give the remaining chunks.To Reproduce
Important
This example uses the
AzureOpenAIClient
but theCancellationToken
behavior is inherited from theOpenAIClient
.Failing xUnit Reproduction Code (should Pass)
Code snippets
No response
OS
Windows 11
.NET version
.net 8
Library version
beta.11
The text was updated successfully, but these errors were encountered: