Skip to content

Add real-time SSE streaming for LLM chat responses - #330

Open
yoro1836 wants to merge 1 commit into
SimonSchubert:mainfrom
yoro1836:pr/streaming
Open

Add real-time SSE streaming for LLM chat responses#330
yoro1836 wants to merge 1 commit into
SimonSchubert:mainfrom
yoro1836:pr/streaming

Conversation

@yoro1836

@yoro1836 yoro1836 commented Jun 7, 2026

Copy link
Copy Markdown

Currently, the app only supports batch text generation, which forces users to wait until the entire response is completed. For longer outputs, this significantly harms the user experience as it feels like the app has frozen.

By implementing real-time SSE streaming, users can see the response token-by-token instantly. I also added a fallback mechanism to the existing batch implementation so that if streaming fails for any reason, it gracefully switches back to batch mode without interrupting the conversation.

  • Add StreamEvent model (Token, ToolCalls, Finished, Error) and accumulator
  • Add SseParser for line-by-line SSE reading from Ktor ByteReadChannel
  • Add OpenAICompatibleStreamParser for OpenAI-compatible SSE chunks
  • Add AnthropicStreamParser for Anthropic SSE events
  • Add streamingOpenAICompatibleChat() and streamingAnthropicChat() to Requests
  • Add stream field to request DTOs
  • Add streamingChat() to ToolLoopStrategy with batch fallback
  • Use placeholder History entries updated token-by-token in runToolLoop
  • Graceful fallback to batch API calls when streaming fails

- Add StreamEvent model (Token, ToolCalls, Finished, Error) and accumulator
- Add SseParser for line-by-line SSE reading from Ktor ByteReadChannel
- Add OpenAICompatibleStreamParser for OpenAI-compatible SSE chunks
- Add AnthropicStreamParser for Anthropic SSE events
- Add streamingOpenAICompatibleChat() and streamingAnthropicChat() to Requests
- Add stream field to request DTOs
- Add streamingChat() to ToolLoopStrategy with batch fallback
- Use placeholder History entries updated token-by-token in runToolLoop
- Graceful fallback to batch API calls when streaming fails
kilvz added a commit to kilvz/Kai-custom that referenced this pull request Jun 14, 2026
…onSchubert#330)

- Add StreamEvent model (Token, ToolCalls, Finished, Error) and StreamAccumulator
- Add SseParser for line-by-line SSE reading from Ktor ByteReadChannel
- Add OpenAICompatibleStreamParser for OpenAI SSE chunks
- Add AnthropicStreamParser for Anthropic SSE events
- Add streamingOpenAICompatibleChat() and streamingAnthropicChat() to Requests
- Add stream field to request DTOs
- Add streamingChat() to ToolLoopStrategy with batch fallback
- Use placeholder History entries updated token-by-token in runToolLoop
- Graceful fallback to batch API calls when streaming fails
kilvz added a commit to kilvz/Kai-custom that referenced this pull request Jun 14, 2026
@camdencarr84-jpg

Copy link
Copy Markdown

Merge this please @SimonSchubert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants