] API错误 (400 ): [2025-12-28T14:26:45.415Z] [ERROR] API错误 (400 ): { { "error": { ...

2025年12月28日 22:27 状态: processing

🚨 错误信息

[2025-12-28T14:26:44.281Z] [INFO] 需要截图 [2025-12-28T14:26:44.281Z] [INFO] 需要截图 [2025-12-28T14:26:44.676Z] [INFO] 开始发送请求到LLM API: https://www.dmxapi.cn/v1/chat/completions [2025-12-28T14:26:44.676Z] [INFO] 开始发送请求到LLM API: https://www.dmxapi.cn/v1/chat/completions [2025-12-28T14:26:45.415Z] [ERROR] API错误 (400 ): [2025-12-28T14:26:45.415Z] [ERROR] API错误 (400 ): { { "error": { "error": { "message": "Param Incorrect", "message": "Param Incorrect", "type": "rix_api_error", "param": "tools contains duplicate names: web_search", "code": "400" "type": "rix_api_error", } } [2025-12-28T14:26:45.415Z] [ERROR] LLM处理错误: API错误: 400 详细信息: { "error": { "message": "Param Incorrect", "type": "rix_api_error", "param": "tools contains duplicate names: web_search", "code": "400" } "param": "tools contains duplicate names: web_search", } [2025-12-28T14:26:45.415Z] [ERROR] LLM处理错误: API错误: 400 详细信息: { "error": { "message": "Param Incorrect", "code": "400" } } "type": "rix_api_error", "param": "tools contains duplicate names: web_search", "code": "400" [2025-12-28T14:26:45.415Z] [ERROR] 错误堆栈: Error: API错误: 400 详细信息: { } } [2025-12-28T14:26:45.415Z] [ERROR] 错误堆栈: Error: API错误: 400 "error": { "message": "Param Incorrect", 详细信息: { "error": { "type": "rix_api_error", "param": "tools contains duplicate names: web_search", "message": "Param Incorrect", "type": "rix_api_error", "code": "400" } } at voiceChat.sendToLLM (file:///D:/xiangmu/my-neuro_20250930_195805/my-neuro-bundle-V5.4.6/live-2d/app.js:1534:39) "param": "tools contains duplicate names: web_search", "code": "400" [2025-12-28T14:26:45.415Z] [ERROR] 用户显示错误: 未知错误: API错误: 400 详细信息: { } } at voiceChat.sendToLLM (file:///D:/xiangmu/my-neuro_20250930_195805/my-neuro-bundle-V5.4.6/live-2d/app.js:1534:39) "error": { "message": "Param Incorrect", "type": "rix_api_error", ... [2025-12-28T14:26:45.415Z] [ERROR] 用户显示错误: 未知错误: API错误: 400 详细信息: { "error": { "message": "Param Incorrect", "type": "rix_api_error", ...

🤖 AI解决方案

报错信息分析

1. 错误翻译


markdown
原文:tools contains duplicate names: web_search
译文:工具参数包含重复的名称:web_search

2. 原因分析


  • 根本原因:在向 DMXAPI (https://www.dmxapi.cn/v1/chat/completions) 发送请求时,tools 参数中包含了多个名为 web_search 的工具,导致API返回400错误。

  • 问题定位:错误发生在 /live-2d/app.js 文件的第1534行(voiceChat.sendToLLM 函数中)。请求体中的 tools 数组存在重复定义。
  • 3. 解决方案


    修复 tools 参数,确保数组中的每个工具都有唯一的 name 值:

    javascript
    // 修改前(错误示例):
    const tools = [
    {
    type: "function",
    function: {
    name: "web_search",
    description: "搜索网络信息"
    // ... 其他参数
    }
    },
    {
    type: "function",
    function: {
    name: "web_search", // ❌ 重复的名称
    description: "另一个搜索工具"
    // ... 其他参数
    }
    }
    ];

    // 修改后(正确示例):
    const tools = [
    {
    type: "function",
    function: {
    name: "web_search",
    description: "搜索网络信息"
    // ... 其他参数
    }
    },
    // 如果需要多个搜索工具,使用不同的名称
    {
    type: "function",
    function: {
    name: "advanced_web_search", // ✅ 唯一的名称
    description: "高级网络搜索"
    // ... 其他参数
    }
    }
    ];

    或者,如果不需要重复工具,直接移除重复项:

    javascript
    const tools = [
    {
    type: "function",
    function: {
    name: "web_search",
    description: "搜索网络信息"
    // ... 其他参数
    }
    }
    // 移除重复的 web_search 工具
    ];

    4. ️ 预防措施


  • 工具命名规范

  • - 为每个工具函数定义唯一的 name 属性
    - 建立命名约定(如:module_action 格式)

  • ️ 请求参数校验

  • javascript
    // 在发送请求前添加校验
    function validateTools(tools) {
    const names = tools.map(t => t.function?.name);
    const uniqueNames = [...new Set(names)];

    if (names.length !== uniqueNames.length) {
    console.error('发现重复的工具名称:', tools);
    return false;
    }
    return true;
    }

    // 使用校验
    if (validateTools(tools)) {
    // 发送请求
    }

    建议:检查项目中所有调用DMXAPI的代码,确保 tools 参数不包含重复名称,特别是当工具配置来自多个模块或配置文件时。