如何使用 Azure OpenAI 进行函数调用

Dee*_*217 10 azure-openai

这是我的代码


response = openai.ChatCompletion.create(
    engine="XXX", # The deployment name you chose when you deployed the ChatGPT or GPT-4 model.
    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=[{'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']}]
)
Run Code Online (Sandbox Code Playgroud)

结果是 :

InvalidRequestError:提供了无法识别的请求参数:函数

写了上面的代码

Nik*_*sMH 24

更新(2023 年 7 月 13 日):2023-07-01-preview Azure 现在支持以下模型上API 版本的函数调用:

  • gpt-4-0613
  • gpt-4-32k-0613
  • gpt-35-turbo-0613(感谢乔尔)
  • gpt-35-turbo-16k-0613

之前的回答:

只有版本gpt-3.5-turbo-0613并且gpt-4-0613具有函数调用(ref),并且 Azure OpenAI Services 目前仅支持这些(ref):

  • gpt-3.5-turbo-0301
  • gpt-4-0314
  • gpt-4-32k-0314

希望 Azure OpenAI 服务团队能够0613尽快支持该版本。

更新(2023 年 7 月 3 日):尽管0613现在已经发布,但它们似乎仍然不支持functions作为参数,正如其他一些人在这里指出的那样。我已经使用 进行了测试2023-06-01-preview,这应该是最新的 API 接口(根据这些规范),但没有运气。我还发现该版本2023-07-01-preview现在也可以工作,但也没有运气。(现在已经改变了。请参阅顶部的更新^)