Openclaw 3.24版本接入Deepseek V4 Pro/ Flash 报错码 400,即使关了reasoning:false依然报错,可能是版本太低的缘故。
The reasoning_content in the thinking mode must be passed back to the API
openclaw全局安装目录:C:\Users\user\AppData\Roaming\npm\node_modules\openclaw
Step 1: 创建补丁文件
在目录中新建文件deepseek-fix.mjs,代码如下:
// DeepSeek V4 reasoning_content auto-padding patch
// 在 openclaw 入口前加载此文件修复 400 错误
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
// 拦截 fetch — 在请求发送前补齐 reasoning_content
const _fetch = globalThis.fetch.bind(globalThis);
globalThis.fetch = async function patchedFetch(url, init = {}) {
const urlStr = typeof url === 'string' ? url : url.href || '';
const isDeepSeek = urlStr.includes('api.deepseek.com');
if (isDeepSeek && init.body && typeof init.body === 'string') {
try {
const body = JSON.parse(init.body);
if (body.messages && Array.isArray(body.messages)) {
let changed = false;
for (const msg of body.messages) {
if (msg.role === 'assistant' && !('reasoning_content' in msg)) {
msg.reasoning_content = '';
changed = true;
}
}
if (changed) {
init.body = JSON.stringify(body);
}
}
} catch (_) {
// body 不是 JSON,放行
}
}
return _fetch(url, init);
};
console.log('[deepseek-fix] Patch applied — reasoning_content auto-padding for DeepSeek V4');
Step 2:修改 OpenClaw 入口
修改 dist\index.js,在文件第一行加:
import '../deepseek-fix.mjs';
Step 3: 验证
重新启动 OpenClaw,看到 [deepseek-fix] Patch applied 就说明生效了。
原理:拦截 fetch,所有发往 api.deepseek.com 的请求在发出前自动扫描 messages,assistant 消息缺 reasoning_content 就加空字符串——跟 Python 版逻辑一样,换成 JS 实现。
结论:方法就是在主目录添加补丁,引入入口文件。
8804

被折叠的 条评论
为什么被折叠?



