marimo
marimo copied to clipboard
Add streaming support for chat: async generator bug and add documentation
Summary
This PR adds real-time streaming support to mo.ui.chat, enabling ChatGPT-like experiences where responses appear word-by-word as they're generated.
What's New
✨ Streaming Support for Chat Models
Users can now stream responses from chat models in real-time:
With built-in models (OpenAI, etc.):
chat = mo.ui.chat(
mo.ai.llm.openai(
"gpt-4o",
stream=True, # Enable streaming!
)
)
With custom models using async generators:
async def streaming_model(messages, config):
for word in words:
accumulated += word + " "
yield accumulated # Each yield updates the UI
await asyncio.sleep(0.1)
chat = mo.ui.chat(streaming_model)
📚 Documentation
- Added comprehensive "Streaming Responses" section to chat API docs
- Explains both built-in model streaming and custom async generator approach
- Includes links to working examples (
streaming_openai.pyandstreaming_custom.py)
🎯 Examples
streaming_openai.py: Demonstrates streaming with OpenAI modelsstreaming_custom.py: Shows how to build custom streaming chatbots- Fixed quote escaping in examples to prevent file corruption on auto-save
Implementation Details
- Added
streamparameter toopenaiChatModel class - Implemented async generator support in chat UI element
- Frontend receives incremental updates via
stream_chunkmessages - Final message marked with
is_final: trueflag
Testing
- Added
test_chat_streaming_sends_messagesto verify streaming behavior - Manually tested both OpenAI and custom streaming examples
- Code passes lint and format checks
User Experience
Users will see responses appear progressively in the chat interface, creating a more engaging and responsive experience similar to ChatGPT, Claude, and other modern AI chat interfaces.
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| marimo-docs | Preview | Comment | Nov 19, 2025 4:30am |
All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.
I have read the CLA Document and I hereby sign the CLA
Additional UI Improvement: Chat Reset Icon Change
Changed the chat reset button icon from trash to rotate-clockwise to improve UX clarity.
Why this change? The trash icon was confusing as it looked like it would delete the cell itself rather than reset the conversation. The rotate icon better represents the "reset/restart" action.
Additional improvements:
- Reset button is now disabled when there are no messages (consistent with send button behavior)
- Individual message delete buttons still use the trash icon appropriately
See commit: 4b987ea12
@adamwdraper looks great! few build errors to fix, but otherwise good to merge afterwards.
we can followup as a team to figure out the correct default for stream
@adamwdraper looks great! few build errors to fix, but otherwise good to merge afterwards.
we can followup as a team to figure out the correct default for
stream
@mscolnick i tried to fix the build issues, but it seems like they are waiting for approval to run