Files
tw/图绘派单系统集成说明.md
ZuoWei a6c42d505a feat: 完整功能部署 v1.0
新增功能:
- 天网协作系统 (HTTP API 端口 6060)
- 三种工作流 (查找图片/处理图片/转人工派单)
- 图片任务数据库 (支持客户后续增加需求)
- 图绘派单系统集成 (API: 8005)
- 文字检测与加价 (60-80 元高价值订单)
- 风险评估与接单判断
- 作图失败自动转人工

新增文档:
- 项目功能汇总.md
- 三种工作流功能说明.md
- 文字加价功能说明.md
- 风险评估功能说明.md
- 图片任务数据库功能说明.md
- 图绘派单系统集成说明.md
- 作图失败转接人工说明.md
- DEPLOYMENT.md
- TIANWANG_INTEGRATION.md

核心修改:
- core/pydantic_ai_agent.py
- core/workflow.py
- core/websocket_client.py
- image/image_analyzer.py
- services/service_tuhui_dispatch.py
- db/image_tasks_db.py

版本:v1.0
日期:2026-02-28
2026-02-28 11:20:40 +08:00

279 lines
5.5 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 客服系统已接入图绘派单系统 API实现自动派单给在线设计师。
---
## 🚀 派单系统 API
### 基础信息
- **API 地址**: http://1.12.50.92:8005
- **API Key**: tuhui_dispatch_key_2026
- **认证方式**: Header: X-API-Key
### 核心接口
| 接口 | 方法 | 说明 |
|------|------|------|
| `/dispatch/queue` | GET | 获取派单队列 |
| `/online/designers` | GET | 获取在线设计师 |
| `/tasks` | POST | 创建任务 |
| `/tasks/{id}/assign` | POST | 分配任务 |
| `/tasks/{id}` | GET | 查询任务状态 |
| `/tasks/{id}/complete` | POST | 完成任务 |
---
## 🔄 工作流程
### 转人工派单流程
```
客户:这个能做吗 [图片]
AI: 抱歉,这个我做不了,帮您转接设计师
1. 查询在线设计师
GET /online/designers
返回:["橘子", "婷婷"]
2. 创建派单任务
POST /tasks
返回:{"task_id": "ea853bd9"}
3. 分配给设计师
POST /tasks/ea853bd9/assign
{"designer_name": "橘子"}
4. 企业微信通知设计师
5. 回复客户
"好的,已帮您安排设计师处理,请稍候"
```
---
## 📝 API 调用示例
### 1. 查询在线设计师
```python
from services.service_tuhui_dispatch import get_tuhui_dispatch_client
client = get_tuhui_dispatch_client()
designers = await client.get_online_designers()
# 返回:["橘子", "婷婷"]
```
### 2. 创建任务
```python
task_id = await client.create_task(
task_name="图片处理 -1234",
description="客户需要做高清修复",
task_type="image_process",
priority=2
)
# 返回:"ea853bd9"
```
### 3. 分配任务
```python
success = await client.assign_task(
task_id="ea853bd9",
designer_name="橘子",
notes="AI 客服自动派单"
)
# 返回True
```
### 4. 查询任务状态
```python
status = await client.get_task_status("ea853bd9")
# 返回:{"status": "assigned", "assigned_to": "橘子", ...}
```
### 5. 完成任务
```python
success = await client.complete_task(
task_id="ea853bd9",
notes="客户已确认,效果满意"
)
# 返回True
```
---
## 🔧 集成代码位置
### 派单客户端
文件:`/root/ai_customer_service/ai_cs/services/service_tuhui_dispatch.py`
**类**: `TuhuiDispatchClient`
**方法**:
- `get_online_designers()` - 查询在线设计师
- `create_task()` - 创建任务
- `assign_task()` - 分配任务
- `get_task_status()` - 查询状态
- `complete_task()` - 完成任务
---
### 工作流集成
文件:`/root/ai_customer_service/ai_cs/core/workflow.py`
**方法**:
- `transfer_to_designer_workflow()` - 转人工派单工作流
- `_get_online_designers()` - 查询在线设计师
- `_dispatch_to_designer()` - 派单给设计师
---
## 📊 派单逻辑
### 1. 查询在线设计师
```python
designers = await workflow._get_online_designers()
# 返回:["橘子", "婷婷"]
```
### 2. 创建派单任务
```python
dispatch_task_id = await workflow.dispatch_client.create_task(
task_name=f"图片处理-{customer_id[-4:]}",
description=f"{reason}\\n客户{customer_id}\\n图片{image_url}",
task_type="image_process",
priority=2
)
```
### 3. 分配给设计师
```python
success = await workflow.dispatch_client.assign_task(
task_id=dispatch_task_id,
designer_name=designer_name, # "橘子"
notes=f"AI 客服自动派单\\n原因{reason}\\n客户{customer_id}"
)
```
### 4. 企业微信通知
```python
await _wechat_notify(
f"📋 **新任务派单**\\n"
f"设计师:{designer_name}\\n"
f"任务 ID: {dispatch_task_id}\\n"
f"客户:{customer_id}\\n"
f"原因:{reason}\\n"
f"请及时处理"
)
```
---
## ⚠️ 注意事项
1. **API Key**: 固定为 `tuhui_dispatch_key_2026`
2. **超时设置**: 默认 10 秒
3. **错误处理**: 所有 API 调用都有 try-except
4. **企业微信通知**: 派单成功后自动发送
5. **任务命名**: 格式为 `图片处理-{客户 ID 后 4 位}`
---
## 🔍 日志查看
```bash
# 查看派单日志
grep "派单" /tmp/ai-cs.log
# 查看在线设计师查询
grep "在线设计师" /tmp/ai-cs.log
# 查看任务创建
grep "创建任务" /tmp/ai-cs.log
```
---
## 📈 派单统计
### 查询派单队列
```bash
curl -X GET "http://1.12.50.92:8005/dispatch/queue" \
-H "X-API-Key: tuhui_dispatch_key_2026"
```
**返回**:
```json
{
"pending_tasks": {"count": 3, "tasks": [...]},
"online_designers": {"count": 2, "designers": ["橘子", "婷婷"]},
"suggestion": "橘子"
}
```
---
## 🎯 完整示例
### AI 客服转人工派单
```python
# 客户说"做不了"
await workflow.transfer_to_designer_workflow(
customer_id="customer_123",
image_url="https://xxx.com/image.jpg",
acc_id="shop_001",
acc_type="AliWorkbench",
reason="图片过于模糊AI 无法处理"
)
# 执行流程:
# 1. 查询在线设计师 → ["橘子", "婷婷"]
# 2. 创建任务 → "ea853bd9"
# 3. 分配给"橘子"
# 4. 企业微信通知
# 5. 回复客户:"好的,已帮您安排设计师处理"
```
---
## 📞 技术支持
**派单系统服务器**: 1.12.50.92:8005
**查看派单系统日志**:
```bash
tail -f /var/log/dispatch_api.log
```
**查看派单进程**:
```bash
ps aux | grep dispatch
```
**重启派单服务**:
```bash
pkill -f dispatch_api
cd /root/tuhui/backend
nohup python3 -m uvicorn dispatch_api:app --host 0.0.0.0 --port 8005 > /var/log/dispatch_api.log 2>&1 &
```
---
**文档版本**: v1.0
**更新日期**: 2026-02-27