Files

87 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AI Free Chat
一个基于 Flask 的免费 AI 对话应用,后端集成豆包(Doubao)和 DeepSeek 大模型,通过 Server-Sent Events (SSE) 实现消息实时推送,前端提供简洁美观的聊天界面。
## 功能特性
- 支持豆包(Doubao)和 DeepSeek 双模型切换
- SSE 实时流式推送,打字机效果
- 简洁美观的响应式聊天界面
- 支持多轮对话上下文
- 免费使用(需自行申请 API Key)
## 目录结构
```
ai-free-chat/
├── app.py # Flask 主应用
├── requirements.txt # Python 依赖
├── .env.example # 环境变量示例
├── README.md # 说明文档
├── services/
│ ├── __init__.py
│ ├── doubao.py # 豆包 API 封装
│ └── deepseek.py # DeepSeek API 封装
├── static/
│ ├── css/style.css # 样式
│ └── js/main.js # 前端逻辑
└── templates/
└── index.html # 聊天页面
```
## 快速开始
### 1. 安装依赖
```bash
pip install -r requirements.txt
```
### 2. 配置环境变量
复制 `.env.example` 为 `.env`,填入你的 API Key:
```bash
cp .env.example .env
```
```env
DOUBAO_API_KEY=你的豆包APIKey
DOUBAO_MODEL=doubao-1-5-pro-32k-250115
DEEPSEEK_API_KEY=你的DeepSeekAPIKey
DEEPSEEK_MODEL=deepseek-chat
```
- 豆包 API Key 申请:https://console.volcengine.com/ark
- DeepSeek API Key 申请:https://platform.deepseek.com
### 3. 启动服务
```bash
python app.py
```
打开浏览器访问 http://127.0.0.1:5000
## API 说明
### POST /api/chat
请求体:
```json
{
"provider": "deepseek",
"messages": [
{"role": "user", "content": "你好"}
]
}
```
响应:`text/event-stream` 流式数据,每行 `data: {"content": "..."}`。
## 注意事项
- 本项目仅用于学习交流,请遵守各平台的使用条款。
- API Key 请妥善保管,不要提交到公开仓库。