-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Description
Use case
Please add native support for LLM streaming on Flutter Web in the official Flutter AI Toolkit, such that:
1. The sendMessageStream(..): Stream API works seamlessly on Web for providers like Gemini and OpenAI.
2. Token-by-token rendering (partial message UI rendering) works in real time in web browsers.
3. Underlying HTTP request tooling supports browser-specific protocols like fetch() streaming, SSE, or WebSockets as needed.
4. LlmProviders correctly propagate streamed updates to UI via ChangeNotifier like existing providers for mobile.
Use cases:
• Interactive chatbots in Flutter Web using streaming APIs from OpenAI or Gemini.
• Web‑based real‑time agents that display responses progressively as they arrive.
• Consistent cross‑platform behavior: web, mobile, and desktop using the same Flutter AI Toolkit interfaces.
Proposal
Flutter Web should support real-time token-by-token streaming of responses from LLM APIs like OpenAI and Gemini, using the standard sendMessageStream() interface from the Flutter AI Toolkit.
Currently, streaming works on mobile and desktop, but streamed responses do not work on Flutter Web—likely due to limitations in how Dart handles HTTP streams in the browser.
I propose that Flutter either:
1. Enhance the AI Toolkit’s LlmProvider layer to use browser-native streaming APIs (e.g. fetch().body.getReader(), SSE, or WebSockets) behind the scenes on web platforms.
2. OR provide clear, official guidance or tooling to support real-time streamed LLM output in web UIs.
This would allow developers to build truly cross-platform chatbots and agents in Flutter using the same interface on web, mobile, and desktop.
Possible example:
await for (final token in geminiProvider.sendMessageStream(prompt)) {
// Update chat bubble in real-time
print(token);
}
This works on mobile, but fails or buffers the entire response on Flutter Web, defeating the purpose of streaming.
Does it need to be in Flutter core?
By my understanding, yes, because:
• The Flutter AI Toolkit is an official Flutter project intended to work cross-platform.
• Supporting streaming on web may require changes to how the toolkit integrates with web-specific transport methods, which most third-party packages can’t easily access or abstract.
• It’s important that first-party LlmProviders (like GeminiProvider) behave consistently across platforms.