-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Add streaming response support using IAsyncEnumerable<T> for chat completions, enabling real-time token-by-token output similar to other AI SDKs.
Current Behavior
All responses are returned only after the complete response is received:
var response = await client.ChatAsync("Tell me a story");
Console.WriteLine(response); // Only prints after full responseProposed API
// New streaming method
await foreach (var chunk in client.ChatStreamAsync("Tell me a story"))
{
Console.Write(chunk.Delta?.Content); // Print tokens as they arrive
}
// Or with the full request object
var request = new ChatCompletionRequest
{
Stream = true,
Messages = [...]
};
await foreach (var chunk in client.CreateChatCompletionStreamAsync(request))
{
// Process each chunk
}Implementation Details
New Types Needed
public class ChatCompletionChunk
{
public string Id { get; set; }
public List<ChatChunkChoice> Choices { get; set; }
}
public class ChatChunkChoice
{
public int Index { get; set; }
public ChatChunkDelta Delta { get; set; }
public string? FinishReason { get; set; }
}
public class ChatChunkDelta
{
public string? Role { get; set; }
public string? Content { get; set; }
}SSE Parsing
Parse Server-Sent Events (SSE) format:
data: {"id":"...","choices":[{"delta":{"content":"Hello"}}]}
data: {"id":"...","choices":[{"delta":{"content":" world"}}]}
data: [DONE]
Expected Benefits
- Real-time output - Display tokens as they're generated
- Better UX - Users see immediate feedback
- Lower perceived latency - First token appears faster
- Feature parity - Match capabilities of other AI SDKs
Priority
🟡 P1 - High Impact
Dependencies
- Use HttpCompletionOption.ResponseHeadersRead for faster response start #2 (HttpCompletionOption.ResponseHeadersRead) should be implemented first
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request