Repository navigation
Replies: 1 comment
|
针对你定位的 transform 层,我们做了一组可复核的测量,结果对你的根因描述是一个有价值的收窄: 测量 A(transform 纯函数 A/B):给
测量 B(0.84.1 真实端到端):同一 context 走真 装置与判决: 对你根因的收窄含义:以 Pi 规范 thinking 块进入 transform 的 reasoning 不会丢(0.82.1 亦然)。所以你抓到的"丢失"更可能发生在上一层—— 另一个对你网关重要的事实:即使转换修好,pi-ai 两个版本的 wire 形态都是内联进 content,不是独立 边界说明:我们没有复现你的 nginx/thinking 后端组合;上面是 transform 层与官方端点上的测量,不是对你环境的定论。 |
Uh oh!
There was an error while loading. Please reload this page.
Bug Report: pi-ai DeepSeek 路由在回传跨 provider 历史消息时丢失 reasoning_content,后端返回 400
1. 环境
dsh-llm-pi-ai适配器@earendil-works/pi-ai0.82.1(dist/api/transform-messages.js)deepseek-v4-flashdeepseek-official(dsh-llm-deepseek适配器)产生的 assistant 消息(带 reasoning 内容块)2. 症状
deepseek路由发消息,harness 侧报TRANSPORT "Connection error."(约 330ms、0 token)POST /deepseek/chat/completions → 400 0(空响应体)tool_calls、无reasoning_content)复现 400,后端错误体:{"error":{"message":"The `reasoning_content` in the thinking mode must be passed back to the API.","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}3. 根因(两层)
3.1 harness 侧:
packages/llm/llm-pi-ai/src/replay.ts的foreignAssistant把 harness 的
reasoning内容块转成 pi-aithinking块时没有携带thinkingSignature:pi-ai 只有在 thinking 块带
thinkingSignature时才会在 OpenAI Chat Completions 线上发出reasoning_content(dist/api/openai-completions.js第 869-875 行)。3.2 pi-ai 侧:
dist/api/transform-messages.js的transformMessages对跨模型(foreign) assistant 消息,thinking 块一律被转成普通文本并入
content(第 87-90 行):于是线上 assistant 消息变成
content: "思考+回复文本"、reasoning_content缺失;随后requiresReasoningContentOnAssistantMessages兜底(openai-completions.js 第 924-928 行)只补空字符串reasoning_content: "",DeepSeek thinking 模式后端拒绝空值 → 400。4. 证据
六变体对照探测(同 endpoint/model/key,逐项隔离差异,三次一致):
stream: true)reasoning_effort: high)reasoning_content必须回传)harness 请求消息统计(439 条):192 条 assistant 消息中 110 条同时含 reasoning 块与 tool-call 块,全部来自跨 provider 历史。
5. 修复(已实现并验证)
5.1 harness:
packages/llm/llm-pi-ai/src/replay.tsforeignAssistant的 reasoning 分支:replayedAssistant的 reasoning 分支:replay 未记录字段名时同样默认:5.2 pi-ai:
dist/api/transform-messages.js(上游对应src/api/transform-messages.ts)foreign thinking 块带 signature 且目标模型要求回传 reasoning_content 时保留块,不再转文本:
5.3 测试
tests/convert.spec.ts:更新两处 thinking 块断言(thinkingSignature: 'reasoning_content')tests/adapter.spec.ts:新增 wire 级测试passes foreign assistant reasoning back as reasoning_content on the wire,断言真实请求体messages[0]为{ role: 'assistant', content: 'answer', reasoning_content: 'think hard' }convert.spec.ts(68)+adapter.spec.ts(46)全部通过6. 复现步骤
deepseek路由(OpenAI-completions、DeepSeek thinking 模式后端)deepseek-official)产生带 reasoning 的 assistant 历史TRANSPORT "Connection error.";网关侧 400,后端报reasoning_content必须回传All reactions