2026-03-25 17:21:12 +08:00
|
|
|
|
# 手动测试问题
|
|
|
|
|
|
|
2026-03-30 12:50:38 +08:00
|
|
|
|
## 页面(pages/tool/ai-nutritionist)
|
2026-03-25 17:21:12 +08:00
|
|
|
|
|
2026-03-30 12:46:24 +08:00
|
|
|
|
- 1. 请求后页面显示:"未能获取到有效回复。"
|
|
|
|
|
|
fetch("http://127.0.0.1:20822/api/front/coze/chat/stream", {
|
|
|
|
|
|
"headers": {
|
|
|
|
|
|
"accept": "*/*",
|
|
|
|
|
|
"authori-zation": "6f6767b2edc64949b0e4888c199ac0bb",
|
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
|
"sec-fetch-dest": "empty",
|
|
|
|
|
|
"sec-fetch-mode": "cors",
|
|
|
|
|
|
"sec-fetch-site": "same-site"
|
|
|
|
|
|
},
|
|
|
|
|
|
"referrer": "https://servicewechat.com/wx7ecf3e3699353c69/devtools/page-frame.html",
|
|
|
|
|
|
"referrerPolicy": "strict-origin-when-cross-origin",
|
|
|
|
|
|
"body": "{\"botId\":\"7591133240535449654\",\"userId\":11,\"additionalMessages\":[{\"role\":\"user\",\"content\":\"透析患者可以喝牛奶吗?\",\"content_type\":\"text\"}],\"stream\":true,\"autoSaveHistory\":true}",
|
|
|
|
|
|
"method": "POST",
|
|
|
|
|
|
"mode": "cors",
|
|
|
|
|
|
"credentials": "omit"
|
|
|
|
|
|
});
|
2026-03-25 17:21:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
2026-03-30 12:46:24 +08:00
|
|
|
|
## 修复记录
|
2026-03-25 17:21:12 +08:00
|
|
|
|
|
2026-03-30 12:46:24 +08:00
|
|
|
|
### 问题 1 修复:流式对话显示"未能获取到有效回复"
|
|
|
|
|
|
|
|
|
|
|
|
**根因分析**:两个问题导致前端无法正确接收流式数据:
|
|
|
|
|
|
|
|
|
|
|
|
1. **Delta 事件过滤条件过严** — `ai-nutritionist.vue` 中 `sendToAIStream()` 对 `conversation.message.delta` 事件要求 `evt.role === 'assistant' && evt.type === 'answer'`。但 Coze SDK 在流式增量事件中可能不返回 `role` 和 `type` 字段(后端发送的精简 JSON 仅在字段非 null 时才包含),导致所有增量内容被静默丢弃。
|
2026-03-25 17:21:12 +08:00
|
|
|
|
|
2026-03-30 12:46:24 +08:00
|
|
|
|
2. **未处理非分块响应降级** — `cozeChatStream()` 中 `success` 回调未处理响应体。在微信开发者工具或某些不支持 `onChunkReceived` 的环境下,流式数据仅在 `res.data` 中一次性返回,但被完全忽略。
|
2026-03-25 17:21:12 +08:00
|
|
|
|
|
2026-03-30 12:46:24 +08:00
|
|
|
|
**修复内容**:
|
|
|
|
|
|
- `ai-nutritionist.vue`:将 delta 过滤改为 `const role = evt.role || 'assistant'`,缺失字段时默认为预期值。
|
|
|
|
|
|
- `models-api.js`:增加 `_gotChunks` 标记,当 `onChunkReceived` 未触发时,在 `success` 回调中解析 `res.data` 作为降级处理;增加 `responseType: 'text'` 确保响应体为字符串。
|
2026-03-25 17:21:12 +08:00
|
|
|
|
|
|
|
|
|
|
# 参考文档
|
|
|
|
|
|
|
2026-03-30 12:46:24 +08:00
|
|
|
|
- 3. /Users/a123/msh-system/.cursor/plans/optimize_ai_nutritionist_speed_b6e9a618.plan.md
|
2026-03-25 17:21:12 +08:00
|
|
|
|
- 1. /Users/a123/msh-system/docs/测试问题分析报告_2026-03-22.md
|
|
|
|
|
|
- 2. /Users/a123/msh-system/docs/功能开发详细设计_2026-03-25.md
|