一个轻量级的仿ChatGPT聊天应用,支持深度思考和联网搜索功能。
项目代码下载
git clone https://github.com/jackhe183/chatboxRedo0906.gitWindows:
# 双击运行
start_backend.bat
# 或命令行运行
cd backend
python app.pyLinux/Mac:
# 运行脚本
./start_backend.sh
# 或命令行运行
cd backend
python app.py后端服务将在 http://localhost:8000 启动
在浏览器中打开 frontend/静态对话页面.html 文件
第一次安装桌面版docker,如果要提示安装WSL,powershell管理员运行以下代码
wsl --update --web-download轩辕docker镜像有限次数构建,节约使用,设置完docker镜像后重启docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://docker.xuanyuan.me"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart dockerdocker官方安装方式
https://docs.docker.com/engine/install/ubuntu/直接复制粘贴命令
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin重启docker并作helloworld验证
sudo systemctl status docker
sudo systemctl start docker
sudo docker run hello-worldsudo apt update
sudo apt install unzip
unzip chatboxRedo0906.zip
sudo apt update
sudo apt install zip
sudo zip -r chatboxRedo0906v2.zip chatboxRedo0906cd ~/chatboxRedo0906/
sudo docker compose up -d --buildserver {
listen 80;
server_name; # 这里可以写您的域名或_
# 规则一:处理API请求
# 所有以 /api/ 开头的请求,都转发给后端的app服务
location /api/ {
proxy_pass http://app:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 规则二:处理所有其他请求(前端静态文件)
# Nginx 会在 /usr/share/nginx/html 目录里寻找匹配的文件
location / {
root /usr/share/nginx/html;
index index.html index.htm;
# 这个 try_files 是单页应用(SPA)的关键,它确保刷新页面时不会404
try_files $uri $uri/ /index.html;
}
}- 用户注册/登录
- JWT Token 认证
- 自动登录状态保持
- 实时消息发送/接收
- 流式AI响应(打字机效果)
- 深度思考模式 🧠
- 联网搜索模式 🌐
- Markdown 渲染支持
- 创建新对话
- 历史对话列表
- 按时间分组显示(今天/7天内/30天内)
- 会话标题自动生成
- 响应式设计
- 侧边栏收起/展开
- 现代化UI设计
- 流畅的动画效果
- 框架: FastAPI + SQLAlchemy
- 数据库: SQLite
- 认证: JWT Token
- AI服务: DeepSeek API
- 流式响应: Server-Sent Events
- 框架: Vue 3 Composition API
- 样式: 原生CSS + CSS变量
- HTTP客户端: Fetch API
- 流式处理: Server-Sent Events
- Markdown渲染: marked.js
├── backend/ # 后端代码
│ ├── app.py # FastAPI应用入口
│ ├── routers/ # API路由
│ ├── services/ # 业务逻辑服务
│ ├── database/ # 数据库相关
│ └── schemas.py # 数据模型
├── frontend/ # 前端代码
│ ├── 静态对话页面.html # 主页面
│ └── README.md # 前端说明
├── docs/ # 文档
│ └── 总架构.md # 架构设计文档
├── start_backend.bat # Windows启动脚本
├── start_backend.sh # Linux/Mac启动脚本
└── README.md # 项目说明
POST /api/users/register- 用户注册POST /api/users/login- 用户登录GET /api/users/me- 获取当前用户信息GET /api/conversations/- 获取会话列表POST /api/conversations/- 创建新会话GET /api/messages/conversation/{id}- 获取会话消息POST /api/messages/send- 发送消息(流式响应)
- 完全响应式设计
- 实时流式消息接收
- 自动Token管理
- 错误处理和用户反馈
- 本地状态持久化
- JWT Token 认证
- 自动Token验证和刷新
- 用户数据隔离
- 输入验证和错误处理
- 首次使用: 注册新账号
- 开始聊天: 在输入框输入消息
- 功能开关: 开启深度思考或联网搜索
- 历史对话: 左侧边栏管理历史对话
- 新建对话: 点击"+ 开启新对话"
- 确保后端服务运行在
http://localhost:8000 - 首次使用需要注册账号
- 支持流式响应,AI回复会逐字显示
- 所有数据都会保存到后端数据库
- 需要配置DeepSeek API密钥(在backend/config.py中)
MIT License