-
Notifications
You must be signed in to change notification settings - Fork 340
Closed
Labels
needs-triageWorkflow: This is a new issue that needs to be triaged.Workflow: This is a new issue that needs to be triaged.
Description
Describe the bug
When streaming a chat completion through CompleteChatStreamingAsync, the FinishReason on the StreamingChatCompletionUpdate always returns null.
Monitoring the traffic to the API, I can see the finish reason in the returned data:
data: {"id":"2f5de4d2-34b4-4c79-a7e3-554c0cd0423e","model":"gpt-4.1-mini","created":1758571978,"object":"extensions.chat.completion.chunk","choices":[{"index":0,"delta":{"content":"!"},"end_turn":false,"finish_reason":null}],"system_fingerprint":"fp_4f3d32ad4e"}
data: {"id":"2f5de4d2-34b4-4c79-a7e3-554c0cd0423e","model":"gpt-4.1-mini","created":1758571978,"object":"extensions.chat.completion.chunk","choices":[{"index":0,"delta":{},"end_turn":true,"finish_reason":"stop"}],"system_fingerprint":"fp_4f3d32ad4e"}
data: [DONE]
Here is the relevant bit for looping through the updates:
var updates = chatClient.CompleteChatStreamingAsync(messages, options, CancellationToken.None);
await foreach (var update in updates)
{
var token = string.Empty;
if (update.FinishReason != null)
{
if (debug == "1")
{
token += $"\n\n----\n[DEBUG] Finish Reason: {update.FinishReason}\n----\n\n";
}
}
if (update.ContentUpdate.Count == 0) continue;
token += update.ContentUpdate[0].Text;
if (string.IsNullOrEmpty(token)) continue;
var bytes = Encoding.UTF8.GetBytes(token);
await context.Response.OutputStream.WriteAsync(bytes, 0, bytes.Length);
await context.Response.FlushAsync();
}
The finish reason is never added to the output. Furthermore, stepping through debugging, the FinishReason is always null.
Steps to reproduce
See code in problem description.
Code snippets
OS
Windows 11
.NET version
.NET Framework 4.8
Library version
2.4.0
Metadata
Metadata
Assignees
Labels
needs-triageWorkflow: This is a new issue that needs to be triaged.Workflow: This is a new issue that needs to be triaged.