python - 为什么在调用 Azure OpenAI GPT 时使用 "Unrecognized request argument supplied: functions"时会收到错误 `functions`?

标签 python azure gpt-3 azure-openai large-language-model

我在调用 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",
        )

但我收到错误:

openai.error.InvalidRequestError:
Unrecognized request argument supplied: 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"]
        }
    }
]

最佳答案

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

openai.api_version = "2023-07-01-preview"

关于python - 为什么在调用 Azure OpenAI GPT 时使用 "Unrecognized request argument supplied: functions"时会收到错误 `functions`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76757194/

相关文章:

Python TCP 服务器

azure - 在 Azure Blob 存储中托管 ClickOnce 并使用自定义域

python - OpenAI 使用 python 返回空模型进行微调

openai-api - NodeJS 中的 OpenAI API : How do I migrate from text-davinci-003 to gpt-3. 5-turbo?

python - selenium python 绑定(bind)是否需要 firefox

python - 等价于 =+ 的字符串,但将现有字符串附加到新字符串而不是添加到新字符串之前

python - 如何判断哪个 Keras 模型更好?

c# - 由于对象的当前状态,操作无效。使用 dotnet core 5 在 eventhub 中获取 microsoft.azure.amqp

azure - 如何授予应用程序注册访问 Azure KeyVault 的权限?

openai-api - GPT3 微调模型返回额外的问题和答案