400 "auto" tool choice requires --enable-auto-tool-choice and --tool-call-parser...

2026年03月17日 12:53 processing

错误信息

400 "auto" tool choice requires --enable-auto-tool-choice and --tool-call-parser to be set

AI 解决方案

报错分析报告

1.错误翻译


原文:"auto" tool choice requires --enable-auto-tool-choice and --tool-call-parser to be set
译文:"auto"工具选择模式需要设置--enable-auto-tool-choice和--tool-call-parser参数

2. 原因分析


  • 根本原因:使用"auto"工具选择模式时,未同时启用两个必要参数(--enable-auto-tool-choice开启自动工具选择、--tool-call-parser指定工具调用解析器)。

  • 发生位置:调用支持工具选择的API/命令时,指定tool_choice="auto"但缺少配套参数配置。
  • 3.解决方案


    根据使用场景选择以下修复方式:

    #### 场景1:CLI命令调用

    # 修复后的命令(添加缺失参数)
    your-cli-command --tool-choice auto --enable-auto-tool-choice --tool-call-parser <解析器名称>
    

    #### 场景2:Python代码调用(以OpenAI兼容库为例)

    from openai import OpenAI
    
    client = OpenAI()
    response = client.chat.completions.create(
        model="your-model",
        messages=[{"role": "user", "content": "query"}],
        tool_choice="auto",
        extra_body={
            "enable_auto_tool_choice": True,  # 对应--enable-auto-tool-choice
            "tool_call_parser": "json"         # 对应--tool-call-parser(示例值)
        }
    )
    

    4.️ 预防措施


  • 参数校验:使用"auto"工具选择前,查阅文档确认所需配套参数(如enable_auto_tool_choicetool_call_parser)。

  • 工具辅助:用--help命令或IDE参数提示检查必填项,避免遗漏(如your-cli-command --help查看参数说明)。
  • ---
    <解析器名称>需替换为实际支持的解析器(如jsonxml,依平台而定)。