- Add Coze TTS endpoint and service; expose binary MP3 from controller. - Bypass ResponseFilter for /audio/speech so MP3 bodies are not UTF-8 wrapped. - UniApp: cozeTextToSpeech, TTS UI and play flow; SSE HTTP errors and diagnostics. - Document TTS in docs/features.md; extend test-0325-1 with curl verification. Made-with: Cursor
2.3 KiB
2.3 KiB
手动测试问题
页面(pages/tool/ai-nutritionist)
-
- 请求Request URL: http://127.0.0.1:20822/api/front/coze/chat/stream, 参数:{"botId":"7591133240535449654","userId":11,"additionalMessages":[{"role":"user","content":"透析患者可以喝牛奶吗?","content_type":"text"}],"stream":true,"autoSaveHistory":true},请求后页面显示:"未能获取到有效回复。"
修复记录
1. 流式对话显示"未能获取到有效回复"
根因分析(三个层次):
-
HTTP 状态码未检查 —
cozeChatStream()的success回调不检查res.statusCode。后端发生异常时(如botID is marked non-null but is null),SpringGlobalExceptionHandler返回 HTTP 500 + JSON 错误体,前端parseSseResponseBody找不到data:行后静默忽略,直接触发_onComplete(),最终展示"未能获取到有效回复"。 -
SSE 解析错误全部静默吞噬 —
parseSseLines()/parseSseResponseBody()的 catch 块为空,JSON 解析失败时无任何输出,排查困难。 -
错误提示固定话术,掩盖真实原因 —
onError回调展示固定文字"抱歉,处理您的请求时出现错误",而非后端实际错误信息。
修复内容:
models-api.js—cozeChatStream()的success回调添加res.statusCode !== 200检查,提取后端message/msg字段作为错误信息调用_onError;在 chunk 接收、SSE 解析、降级解析各环节添加console.log/console.warn诊断日志。ai-nutritionist.vue—sendToAIStream()的onError改为展示err.message而非固定话术。
后端独立验证命令(用于确认 SSE 是否正常):
curl -N -X POST 'http://127.0.0.1:20822/api/front/coze/chat/stream' \
-H "Content-Type: application/json" \
-d '{"botId":"7591133240535449654","userId":"11","additionalMessages":[{"role":"user","content":"透析患者可以喝牛奶吗?"}]}'
若后端正常,应逐行输出 data:{"event":"conversation.message.delta","content":"..."} 流;若返回 {"code":500,"message":"..."} 则说明后端有问题需优先排查。
参考文档
-
- /Users/a123/msh-system/.cursor/plans/optimize_ai_nutritionist_speed_b6e9a618.plan.md