Build a DeepSeek chatbot using Streamlit and Ciyuano
Goal
Build a complete web chat interface in 30 minutes, supporting streaming output, conversation history, and model switching.
Tech Stack
- Frontend: Streamlit (pure Python, no HTML/JS needed)
- Backend: Ciyuano API (DeepSeek V4)
- Language: Python 3.10+
Step 1: Install Dependencies
pip install streamlit openai
Step 2: Create app.py
import streamlit as st
from openai import OpenAI
st.set_page_config(page_title="DeepSeek Chat", page_icon="π€")
st.title("π€ DeepSeek chat assistant")
with st.sidebar:
st.header("βοΈ Settings")
api_key = st.text_input("API Key", type="password")
model = st.selectbox("model", ["deepseek-v4", "glm-5", "qwen-plus", "auto"])
st.caption("Powered by Ciyuano")
if "messages" not in st.session_state:
st.session_state.messages = []
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.markdown(msg["content"])
if prompt := st.chat_input("Enter your question..."):
if not api_key:
st.error("Please enter first API Key")
st.stop()
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
client = OpenAI(
base_url="https://www.ciyuano.com/v1",
api_key=api_key
)
with st.chat_message("assistant"):
message_placeholder = st.empty()
full_response = ""
stream = client.chat.completions.create(
model=model,
messages=st.session_state.messages,
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
full_response += chunk.choices[0].delta.content
message_placeholder.markdown(full_response + "β")
message_placeholder.markdown(full_response)
st.session_state.messages.append(
{"role": "assistant", "content": full_response}
)
Step 3: Run
streamlit run app.py
The browser automatically opens http://localhost:8501, and a complete chat interface appears!
Preview
- β Streaming word-by-word output (typewriter effect)
- β Multi-turn conversation memory
- β Real-time model switching
- β Pure Python implementation, zero frontend code
Deployment
nohup streamlit run app.py --server.port 8501 &
Configure Nginx reverse proxy + SSL to serve externally.
Summary
The Streamlit + Ciyuano combination lets you have a production-ready AI chat application in 30 minutes. No complex frontend frameworks, no server-side API development, all done with Python.
π Related Articles
Building an Intelligent Customer Service Robot Using AI API: A Complete Practical Solution
Intelligent customer service robots are one of the most common application scenarios of AI APIs. This article will guide you from scratch to build an intelligent customer service system that supports multi-turn dialogue, knowledge base retrieval, and streaming output.
Dev PracticeBuilding a Multi-Model Intelligent Gateway: Ciyuano's Technical Architecture Revealed
Deep dive into Ciyuano's core technical architecture: underlying implementation principles of multi-model intelligent routing, health checks, failover, and real-time billing.
Dev PracticeHands-on AI Agent Development: Building Autonomous Decision-Making Agents
Build an AI Agent from scratch with tool calling, memory management, and autonomous planning capabilities, covering mainstream frameworks such as ReAct and Plan-and-Execute.
π¬ Comments are not yet available, stay tuned