You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Azure OpenAI进行函数调用报错:Unrecognized request argument supplied: functions

解决Azure OpenAI函数调用的InvalidRequestError错误

出现InvalidRequestError: Unrecognized request argument supplied: functions错误的核心原因是:Azure OpenAI API的函数调用参数命名与原生OpenAI不同,原生OpenAI用functions参数,但Azure OpenAI需要使用tools和tool_choice(可选)来实现相同功能。

修改后的代码示例

response = openai.ChatCompletion.create(
    engine="XXX",  # 部署ChatGPT或GPT-4时选择的部署名称
    messages=[
        {"role": "system", "content": "Assistant is a large language model trained by OpenAI."},
        {"role": "user", "content": "Calculate the circumference of circle with radius 5?"}
    ],
    # 将原functions替换为tools,并增加type字段
    tools=[
        {
            "type": "function",
            "function": {
                "name": "circumference_calc",
                "description": "Calculate the circumference of circle given the radius",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "radius": {
                            "description": "The radius of the circle",
                            "type": "number"
                        }
                    },
                    "required": ["radius"]
                }
            }
        }
    ],
    # 可选:强制模型调用指定函数,若无需强制可省略
    tool_choice={"type": "function", "function": {"name": "circumference_calc"}}
)

关键修改点

  • 把原functions参数替换为tools,每个工具对象必须包含type: "function"字段,函数定义放在function子对象中
  • 如果需要强制模型调用函数而非直接回答,添加tool_choice参数指定目标函数;若让模型自行判断是否调用函数,可省略该参数或设置为"auto"

内容的提问来源于stack exchange,提问作者Deejay217

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 10:20:11