为什么在调用 Azure OpenAI GPT 时使用“函数”时会收到错误“无法识别的请求参数提供:函数”?

Fra*_*urt 9 python azure gpt-3 azure-openai large-language-model

我尝试functions在调用 Azure OpenAI GPT 时使用,如https://platform.openai.com/docs/api-reference/chat/create#chat/create-functions中所述

我用:

import openai
openai.api_type = "azure"
openai.api_base = "https://XXXXXXXX.openai.azure.com/"
openai.api_version = "2023-06-01-preview"
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.ChatCompletion.create(
            engine="gpt-35-turbo-XXX",
            model="gpt-35-turbo-0613-XXXX"
            messages=messages,
            functions=functions,
            function_call="auto",
        )
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

openai.error.InvalidRequestError:
Unrecognized request argument supplied: functions
Run Code Online (Sandbox Code Playgroud)

为什么?


运行上面示例代码的数据(messages并且functions需要定义):

messages = [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}]
functions = [
    {
        "name": "fetch_pages",
        "description": "Fetch the content of specified pages from the document.",
        "parameters": {
            "type": "object",
            "properties": {
                "pages": {
                    "type": "array",
                    "items": {
                        "type": "number"
                    },
                    "description": "The list of pages to fetch."
                }
            },
            "required": ["pages"]
        }
    },
    {
        "name": "fetch_section",
        "description": "Fetch the content of a specified section.",
        "parameters": {
            "type": "object",
            "properties": {
                "section_title": {
                    "type": "string",
                    "description": "The title of the section to fetch."
                }
            },
            "required": ["section_title"]
        }
    },
    {
        "name": "search",
        "description": "Search the document for a string query.",
        "parameters": {
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "The search term."
                }
            },
            "required": ["query"]
        }
    }
]
Run Code Online (Sandbox Code Playgroud)

小智 15

2023 年 7 月 1 日预览版中添加了对 Azure API 的功能支持。您的示例中需要更新 API 版本:

openai.api_version = "2023-07-01-preview"
Run Code Online (Sandbox Code Playgroud)