CategorizeLabel/demo/测试总结.md
2025-10-15 17:19:26 +08:00

142 lines
3.7 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.

# Batch API 测试总结
## 测试结果
**测试成功通义千问Batch API可以正常响应**
## 测试信息
### 执行时间
- 日期2025年10月15日
- 测试模型:`batch-test-model`(测试专用,不产生费用)
### 测试流程
1. **文件上传**
- 上传文件:`test_model.jsonl`2个测试请求
- 文件ID`file-batch-2a6da75ba3e947a4b48faeda`
- 状态:成功
2. **创建Batch任务**
- 任务ID`batch_430d7e65-635b-47f1-b914-70b9fdc21749`
- Endpoint`/v1/chat/ds-test`(测试模型专用)
- 初始状态:`validating`
3. **任务执行**
- 轮询次数2次
- 执行时间约10-20秒
- 最终状态:`completed`
4. **结果下载**
- 输出文件已保存到:`result.jsonl`
- 包含2条成功响应
- 测试响应内容:`"This is a test result."`
## 测试响应示例
```json
{
"id":"1834f621-35f0-459f-afca-7749ac426759",
"custom_id":"1",
"response":{
"status_code":200,
"request_id":"1834f621-35f0-459f-afca-7749ac426759",
"body":{
"created":1760511961,
"usage":{
"completion_tokens":6,
"prompt_tokens":20,
"total_tokens":26
},
"model":"batch-test-model",
"id":"chatcmpl-f18ede12-09e3-4369-8072-1613771bb609",
"choices":[{
"finish_reason":"stop",
"index":0,
"message":{
"content":"This is a test result."
}
}],
"object":"chat.completion"
}
},
"error":null
}
```
## 环境配置
### API Key设置
```powershell
# Windows PowerShell
$env:DASHSCOPE_API_KEY="sk-bd5ee62703bc41fc9b8a55d748dc1eb8"
```
### 依赖包
- `openai` SDK已安装
## 问题排查
### 遇到的问题及解决方案
1. **编码问题**
- 问题Windows控制台输出包含特殊字符导致编码错误
- 解决:将特殊字符(✓、❌等)替换为纯文本标记([OK]、[ERROR]等)
2. **文件路径问题**
- 问题:脚本在项目根目录运行时找不到输入文件
- 解决:使用`os.path.dirname(__file__)`获取脚本所在目录
3. **JSONL格式问题**
- 问题:文件末尾有空白行导致任务失败(错误码:`line_blank`
- 解决:移除文件末尾的空白行
## 结论
通义千问Batch API工作正常可以成功
- ✅ 上传文件
- ✅ 创建Batch任务
- ✅ 执行任务(快速完成)
- ✅ 下载结果
## 下一步建议
既然API本身工作正常如果主程序`main.py`)仍然遇到"一直等待无法响应"的问题,可能的原因包括:
1. **使用的是正式模型而非测试模型**
- 正式模型(如`qwen-plus`的Batch任务可能需要更长时间
- 当前config中配置的是`qwen-plus`模型
- 建议:等待时间可能需要数小时甚至更长
2. **轮询间隔和最大等待时间设置**
- 当前配置:
- `poll_interval: 60`1分钟
- `max_wait_time: 86400`24小时
- 这些设置看起来是合理的
3. **任务队列繁忙**
- Batch任务的执行时间取决于系统资源分配
- 在高峰期可能需要更长等待时间
## 建议的诊断步骤
1. **检查当前运行的Batch任务状态**
- 如果有正在运行的任务可以通过任务ID查询其状态
- 查看日志文件:`logs/classifier.log`
2. **使用测试模型验证完整流程**
- 修改config.yaml将模型改为`batch-test-model`
- 修改endpoint为`/v1/chat/ds-test`
- 运行主程序验证是否能快速完成
3. **检查实际产品数量**
- 如果`product_list.xlsx`中有大量产品
- Batch任务处理时间会相应增加
## 参考资料
- API文档`../docs/API/Tongyi-API.md`
- 测试脚本:`test_batch_api.py`
- 配置文件:`../config/config.yaml`