SalesGPT API 集成与测试实战指南
目录
API 服务配置
1. 修改配置文件
# run_api.py 关键配置项
model_name = "gpt-4" # 替换为GPT-4模型
CONFIG_PATH = "examples/chinese_config.py" # 使用中文配置文件
2. 启动API服务
python run_api.py
# 成功启动显示信息
INFO: Uvicorn running on http://0.0.0.0:8000
接口测试方法
1. 基础测试指令
curl -X POST "http://localhost:8000/chat" \
-H "Content-Type: application/json" \
-d '{"message": "你好"}'
2. 带上下文测试
curl -X POST "http://localhost:8000/chat" \
-H "Content-Type: application/json" \
-d '{
"message": "我想了解记忆海绵床垫",
"conversation_history": [
{"role": "user", "content": "你好"},
{"role": "assistant", "content": "您好!我是张三..."}
]
}'
响应数据结构
典型响应示例
{
"response": {
"name": "张三",
"content": "我们最新款LuxuryCloud床垫采用...",
"stage": "产品推荐"
},
"metadata": {
"tool_used": true,
"products": ["LuxuryCloud", "EcoSleep"]
}
}
字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| name | string | 销售代表姓名 |
| content | string | 对话内容 |
| stage | string | 当前销售阶段 |
| tool_used | bool | 是否调用产品搜索工具 |
| products | array | 匹配产品列表 |
企业系统集成
1. 网页集成示例
// 前端调用示例
fetch('http://your-domain:8000/chat', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
message: userInput,
session_id: "abc123"
})
})
2. 电话系统对接
# 语音系统集成示例
import requests
def handle_call(audio_text):
response = requests.post(
"http://10.0.0.10:8000/chat",
json={"message": audio_text}
)
return response.json()['response']['content']
常见问题排查
1. 服务未启动
✅ 检查端口占用:
lsof -i :8000
2. 返回英文内容
✅ 确认配置路径包含chinese_config.py
✅ 检查提示词模板中的语言设定
3. 工具调用失败
✅ 验证产品文档路径是否正确
✅ 检查USE_TOOLS参数是否为True
4. 响应延迟过高
# 优化建议
升级服务器配置(推荐4核8G以上)
启用对话缓存机制
性能基准:
GPT-4模型平均响应时间:2.8s/次
单机并发支持:50-80路对话

被折叠的 条评论
为什么被折叠?



