ai-robot-core/README.md

211 lines
6.2 KiB
Markdown
Raw 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 Robot Core
AI中台业务的能力支撑提供智能客服、RAG知识库检索、LLM对话等核心能力。
## 项目结构
```
ai-robot-core/
├── ai-service/ # Python 后端服务
│ ├── app/ # FastAPI 应用
│ ├── tests/ # 测试用例
│ ├── Dockerfile # 后端镜像
│ └── pyproject.toml # Python 依赖
├── ai-service-admin/ # Vue 前端管理界面
│ ├── src/ # Vue 源码
│ ├── Dockerfile # 前端镜像
│ ├── nginx.conf # Nginx 配置
│ └── package.json # Node 依赖
├── docker-compose.yaml # 容器编排
├── .env.example # 环境变量示例
└── README.md
```
## 功能特性
- **多租户支持**: 通过 X-Tenant-Id 头实现租户隔离
- **RAG 知识库**: 基于 Qdrant 的向量检索增强生成
- **LLM 集成**: 支持 OpenAI、DeepSeek、Ollama 等多种 LLM 提供商
- **SSE 流式输出**: 支持 Server-Sent Events 实时响应
- **置信度评估**: 自动评估回复质量,低置信度时建议转人工
## 快速开始
### 环境要求
- Docker 20.10+
- Docker Compose 2.0+
### 部署步骤
#### 1. 克隆代码
```bash
git clone http://49.232.209.156:3005/MerCry/ai-robot-core.git
cd ai-robot-core
```
#### 2. 配置环境变量
```bash
cp .env.example .env
```
编辑 `.env` 文件,配置 LLM API
```env
# OpenAI 配置
AI_SERVICE_LLM_PROVIDER=openai
AI_SERVICE_LLM_API_KEY=your-openai-api-key
AI_SERVICE_LLM_BASE_URL=https://api.openai.com/v1
AI_SERVICE_LLM_MODEL=gpt-4o-mini
# 或使用 DeepSeek
# AI_SERVICE_LLM_PROVIDER=openai
# AI_SERVICE_LLM_API_KEY=your-deepseek-api-key
# AI_SERVICE_LLM_BASE_URL=https://api.deepseek.com/v1
# AI_SERVICE_LLM_MODEL=deepseek-chat
```
#### 3. 启动服务
```bash
docker-compose up -d --build
```
#### 4. 验证服务
```bash
# 检查服务状态
docker-compose ps
# 查看后端日志
docker-compose logs -f ai-service
```
#### 5. 访问服务
| 服务 | 地址 | 说明 |
|------|------|------|
| 前端管理界面 | http://服务器IP:3000 | Vue 管理后台 |
| 后端 API | http://服务器IP:8080 | FastAPI 服务 |
| API 文档 | http://服务器IP:8080/docs | Swagger UI |
| Qdrant 控制台 | http://服务器IP:6333/dashboard | 向量数据库管理 |
## 服务架构
```
┌─────────────────────────────────────────────────────────┐
│ 用户访问 │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ ai-service-admin (端口3000) │
│ - Nginx 静态文件服务 │
│ - 反向代理 /api/* → ai-service:8080 │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ ai-service (端口8080) │
│ - FastAPI 后端服务 │
│ - RAG / LLM / 知识库管理 │
└─────────────────────────────────────────────────────────┘
│ │
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ PostgreSQL │ │ Qdrant │
│ (端口5432) │ │ (端口6333) │
│ - 会话存储 │ │ - 向量存储 │
│ - 知识库元数据 │ │ - 文档索引 │
└──────────────────┘ └──────────────────┘
```
## 常用命令
```bash
# 启动所有服务
docker-compose up -d
# 重新构建并启动
docker-compose up -d --build
# 查看服务状态
docker-compose ps
# 查看日志
docker-compose logs -f ai-service
docker-compose logs -f ai-service-admin
# 重启服务
docker-compose restart ai-service
# 停止所有服务
docker-compose down
# 停止并删除数据卷(清空数据)
docker-compose down -v
```
## 本地开发
### 后端开发
```bash
cd ai-service
# 创建虚拟环境
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# .venv\Scripts\activate # Windows
# 安装依赖
pip install -e ".[dev]"
# 启动开发服务器
uvicorn app.main:app --reload --port 8000
```
### 前端开发
```bash
cd ai-service-admin
# 安装依赖
npm install
# 启动开发服务器
npm run dev
```
## API 接口
### 核心接口
| 接口 | 方法 | 说明 |
|------|------|------|
| `/ai/chat` | POST | AI 对话接口 |
| `/admin/kb` | GET/POST | 知识库管理 |
| `/admin/rag/experiments/run` | POST | RAG 实验室 |
| `/admin/llm/config` | GET/PUT | LLM 配置 |
| `/admin/embedding/config` | GET/PUT | 嵌入模型配置 |
详细 API 文档请访问 http://服务器IP:8080/docs
## 环境变量说明
| 变量名 | 默认值 | 说明 |
|--------|--------|------|
| `AI_SERVICE_LLM_PROVIDER` | openai | LLM 提供商 |
| `AI_SERVICE_LLM_API_KEY` | - | API 密钥 |
| `AI_SERVICE_LLM_BASE_URL` | https://api.openai.com/v1 | API 地址 |
| `AI_SERVICE_LLM_MODEL` | gpt-4o-mini | 模型名称 |
| `AI_SERVICE_DATABASE_URL` | postgresql+asyncpg://... | 数据库连接 |
| `AI_SERVICE_QDRANT_URL` | http://qdrant:6333 | Qdrant 地址 |
| `AI_SERVICE_LOG_LEVEL` | INFO | 日志级别 |
## License
MIT