feat: v2.0.0 架构重构 - 大模型池、Agent管理、渠道独立绑定、思考功能
This commit is contained in:
167
README.md
167
README.md
@@ -1,49 +1,44 @@
|
||||
# AI 对话系统
|
||||
# AI 对话系统 v2.0
|
||||
|
||||
支持网页端和Matrix端实时同步对话的AI聊天系统。
|
||||
|
||||
## 功能特性
|
||||
## v2.0.0 新功能
|
||||
|
||||
- **网页端对话**: 通过浏览器与AI进行对话
|
||||
- **Matrix端对话**: 配置Matrix Bot,用户可通过Matrix与AI对话
|
||||
- **实时同步**: 同一用户在网页端和Matrix端的对话自动同步
|
||||
- **后台管理**: 用户管理、对话记录、系统配置
|
||||
### 🎯 核心架构重构
|
||||
|
||||
## 系统架构
|
||||
- **大模型池管理**:支持配置多个LLM Provider,Agent可选择使用哪个
|
||||
- **Agent管理**:每个Agent可独立配置系统设定、思考功能开关
|
||||
- **渠道独立绑定**:网页端和Matrix可绑定不同的Agent,或同一个Agent
|
||||
- **思考功能**:支持原生思考模型,兼容无思考功能的大模型
|
||||
|
||||
### 📊 系统架构
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ AI 对话系统 │
|
||||
├─────────────────────────────────────────────────────────┤
|
||||
│ 网页端 (用户A) ←──┐ ┌──→ Matrix端 │
|
||||
│ │ 同一会话同步 │ (用户A) │
|
||||
├─────────────────────────────────────────────────────────┤
|
||||
│ 后端服务 (FastAPI + WebSocket) │
|
||||
│ - 会话管理 │
|
||||
│ - 消息存储 │
|
||||
│ - Matrix Bot 集成 │
|
||||
│ - AI 模型调用 │
|
||||
├─────────────────────────────────────────────────────────┤
|
||||
│ 后台管理 │
|
||||
│ - 用户管理 │
|
||||
│ - 对话记录 │
|
||||
│ - 系统配置 │
|
||||
└─────────────────────────────────────────────────────────┘
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ 大模型池 (LLMProvider) │
|
||||
│ 多个LLM API配置,支持思考功能检测 │
|
||||
└─────────────────────────────────────────────────────────────────────┘
|
||||
↓ 被选择
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ Agent │
|
||||
│ 系统设定、思考开关、思考提示词、大模型选择 │
|
||||
└─────────────────────────────────────────────────────────────────────┘
|
||||
↓ 映射绑定
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ 渠道 (Channel) │
|
||||
│ 网页端、Matrix端各自独立配置 │
|
||||
└─────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## 端口分配
|
||||
|
||||
- 19020: 主服务(网页端 + API)
|
||||
- 后台管理: http://localhost:19020/admin
|
||||
- 19020: 主服务(网页端 + API + Matrix Bot)
|
||||
|
||||
## 快速启动
|
||||
|
||||
```bash
|
||||
# 安装依赖
|
||||
pip3 install -r requirements.txt
|
||||
|
||||
# 启动服务
|
||||
./start.sh
|
||||
# v2.0 启动
|
||||
./start_v2.sh
|
||||
|
||||
# 检查状态
|
||||
./status.sh
|
||||
@@ -52,43 +47,105 @@ pip3 install -r requirements.txt
|
||||
./stop.sh
|
||||
```
|
||||
|
||||
## 配置Matrix Bot
|
||||
## 后台管理
|
||||
|
||||
在后台管理页面配置以下参数:
|
||||
访问 http://localhost:19020/admin
|
||||
|
||||
| 配置项 | 说明 |
|
||||
|--------|------|
|
||||
| matrix_homeserver | Matrix服务器地址,如 https://matrix.tphai.com |
|
||||
| matrix_username | Matrix Bot用户名,如 @ai-bot:matrix.org |
|
||||
| matrix_password | Matrix Bot密码 |
|
||||
### 管理功能
|
||||
|
||||
配置完成后,其他Matrix用户可以直接与Bot对话。
|
||||
1. **大模型池管理**
|
||||
- 添加/编辑/删除LLM Provider
|
||||
- 测试API连接
|
||||
- 获取可用模型列表
|
||||
- 配置思考功能支持
|
||||
|
||||
2. **Agent管理**
|
||||
- 创建多个Agent
|
||||
- 配置系统设定(System Prompt)
|
||||
- 开关思考功能
|
||||
- 选择大模型池
|
||||
|
||||
3. **渠道管理**
|
||||
- 网页端/Matrix独立配置
|
||||
- 绑定Agent(支持优先级/条件)
|
||||
- Matrix Bot配置
|
||||
|
||||
## API接口
|
||||
|
||||
### 会话管理
|
||||
### v2 新增API
|
||||
|
||||
- `GET /api/conversations` - 获取会话列表
|
||||
- `POST /api/conversations` - 创建新会话
|
||||
- `GET /api/conversations/{id}/messages` - 获取会话消息
|
||||
- `DELETE /api/conversations/{id}` - 删除会话
|
||||
```
|
||||
# 大模型池
|
||||
GET /api/v2/providers # 获取所有Provider
|
||||
POST /api/v2/providers # 创建Provider
|
||||
PUT /api/v2/providers/{id} # 更新Provider
|
||||
DELETE /api/v2/providers/{id} # 删除Provider
|
||||
POST /api/v2/providers/models # 获取API模型列表
|
||||
POST /api/v2/providers/test # 测试API连接
|
||||
|
||||
### 后台管理
|
||||
# Agent
|
||||
GET /api/v2/agents # 获取所有Agent
|
||||
POST /api/v2/agents # 创建Agent
|
||||
PUT /api/v2/agents/{id} # 更新Agent
|
||||
DELETE /api/v2/agents/{id} # 删除Agent
|
||||
POST /api/v2/agents/{id}/default # 设为默认Agent
|
||||
GET /api/v2/agents/{id}/config # 获取Agent完整配置
|
||||
|
||||
- `GET /api/admin/stats` - 获取统计数据
|
||||
- `GET /api/admin/users` - 获取用户列表
|
||||
- `GET /api/admin/conversations` - 获取对话列表
|
||||
- `GET /api/admin/config` - 获取系统配置
|
||||
- `POST /api/admin/config` - 更新系统配置
|
||||
# 渠道
|
||||
GET /api/v2/channels # 获取所有渠道
|
||||
POST /api/v2/channels # 创建渠道
|
||||
PUT /api/v2/channels/{id} # 更新渠道
|
||||
PUT /api/v2/channels/{id}/config # 更新渠道配置
|
||||
POST /api/v2/channels/bind # 绑定Agent
|
||||
DELETE /api/v2/channels/unbind/{id} # 解绑Agent
|
||||
```
|
||||
|
||||
### 原有API(兼容)
|
||||
|
||||
```
|
||||
GET /api/conversations # 获取会话列表
|
||||
GET /api/conversations/latest # 获取最新会话
|
||||
POST /api/conversations # 创建新会话
|
||||
GET /api/conversations/{id}/messages # 获取消息
|
||||
DELETE /api/conversations/{id} # 删除会话
|
||||
GET /api/admin/stats # 统计数据
|
||||
```
|
||||
|
||||
## 思考功能
|
||||
|
||||
### 配置方式
|
||||
|
||||
1. **原生支持**:某些模型原生支持思考(如DeepSeek R1)
|
||||
- Provider配置 `supports_thinking: true`
|
||||
- 可配置专门的 `thinking_model`
|
||||
|
||||
2. **兼容模式**:不支持原生思考的模型
|
||||
- Agent配置 `thinking_prompt` 思考提示词
|
||||
- 配置 `thinking_prefix`/`thinking_suffix` 识别思考内容
|
||||
- 系统会将思考提示添加到System Prompt
|
||||
|
||||
### Matrix命令
|
||||
|
||||
```
|
||||
/new # 创建新会话
|
||||
/agent <name> # 切换Agent
|
||||
/thinking on # 开启思考功能
|
||||
/thinking off # 关闭思考功能
|
||||
```
|
||||
|
||||
## 技术栈
|
||||
|
||||
- **后端**: FastAPI + WebSocket
|
||||
- **数据库**: SQLite (SQLAlchemy)
|
||||
- **Matrix**: matrix-nio
|
||||
- **前端**: HTML + JavaScript (原生)
|
||||
- **AI**: 可配置任意LLM API(默认使用本地LLM Proxy)
|
||||
- **数据库**: SQLite (SQLAlchemy) + 新增v2模型
|
||||
- **Matrix**: matrix-nio (支持加密)
|
||||
- **前端**: Bootstrap 5 + 原生JavaScript
|
||||
- **AI**: 可配置多个LLM API
|
||||
|
||||
## 仓库地址
|
||||
|
||||
http://192.168.2.8:12007/coder/ai-chat-system
|
||||
http://192.168.2.8:12007/coder/ai-chat-system
|
||||
|
||||
## 版本历史
|
||||
|
||||
- v2.0.0 (2026-04-12): 架构重构,大模型池、Agent管理、渠道独立绑定、思考功能
|
||||
- v1.0.0: 基础版本,网页端+Matrix同步对话
|
||||
Reference in New Issue
Block a user