Commit 0e168281 by luoqi

fix(ai): qwen fetch 中间件仅"非工具调用"才注入 response_format=json_object

之前无条件给所有 qwen 请求注入 json_object(给结构化输出框架用),把助手的
tool-calling(streamText+tools)也污染了 → DashScope 报 400(json mode 与工具调用互斥,
且硬性要求 messages 含 "json")。改为:仅当请求无 tools 且未自带 response_format 时才注入。
结构化框架(generateObject,json mode 无 tools)不受影响;助手 agent loop 带 tools 跳过。

验证:助手 model=qwen 问召回池 → 自主 list_recall_queue → 正常列出 TOP 患者,无报错。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
parent 7b79d63d
......@@ -73,7 +73,13 @@ export class AiProviderService {
try {
const b = JSON.parse(options.body) as Record<string, unknown>;
b.enable_thinking = false;
b.response_format = { type: 'json_object' }; // DashScope 认 json_object(json_schema 不强制)
// ⚠️ 仅"非工具调用"才强制 json_object(结构化输出框架 generateObject 用 json mode、无 tools)。
// tool-calling / agent(streamText + tools)不能用 JSON mode:① 与工具调用互斥
// ② DashScope 还会硬性要求 messages 含 "json" 字样 → 400。带 tools 时跳过注入。
const hasTools = Array.isArray(b.tools) && b.tools.length > 0;
if (!hasTools && b.response_format === undefined) {
b.response_format = { type: 'json_object' }; // DashScope 认 json_object(json_schema 不强制)
}
options = { ...options, body: JSON.stringify(b) };
} catch {
/* 非 JSON body 不动 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment