Demonstrates real-time LLM response streaming with user interrupt capability.
- Check out the Substack Post Tutorial for more!
- Real-time display of LLM responses as they're generated
- User interrupt with ENTER key at any time
pip install -r requirements.txt
python main.pyStreamNode:
- Creates interrupt listener thread
- Fetches content chunks from LLM
- Displays chunks in real-time
- Handles user interruption
By default, demo uses fake streaming responses. To use real OpenAI streaming:
- Edit main.py to replace the fake_stream_llm with stream_llm:
# Change this line:
chunks = fake_stream_llm(prompt)
# To this:
chunks = stream_llm(prompt)- Make sure your OpenAI API key is set:
export OPENAI_API_KEY="your-api-key-here"main.py: StreamNode implementationutils.py: Real and fake LLM streaming functions