An interactive Q&A tool that uses the OpenAI API to answer questions in real-time with streaming, built on Streamlit's native chat components.
- Real-time token streaming for a live chat feel
- System prompt customization (bot personality)
- Model selection (e.g., GPT-3.5, GPT-4 family)
- Conversation history persisted in session state
- Python 3.9+
- OpenAI API key
- Install dependencies:
pip install -r requirements.txt
- Create a secrets file:
# .streamlit/secrets.toml OPENAI_API_KEY = "sk-..."
- Run locally:
streamlit run streamlit_app.py
OPENAI_API_KEY
: Your OpenAI API key. Loaded viast.secrets['OPENAI_API_KEY']
.
- Open the app URL shown in the terminal after starting Streamlit.
- Configure the System Prompt and Model in the sidebar.
- Ask a question via the chat input; the assistant streams the answer.
- Streamlit Community Cloud: push this repo and add
OPENAI_API_KEY
under App Secrets. - Other platforms: ensure
.streamlit/secrets.toml
or environment-backed secrets are configured and that the port/network settings allow Streamlit to serve the app.
- Streaming is enabled by default and handled with
st.write_stream
. - Each interaction is a fresh API call; no caching is used.