openai-python: Azure API does not support functions in chat?

Describe the bug

New functions parameter in ChatCompletion is not recognized when calling MS Azure endpoints. I got this error when I pass in my functions:

  File "call_chatgpt.py", line 52, in chatgpt
    chat_completion = openai.ChatCompletion.create(
  File "/root/anaconda3/lib/python3.8/site-packages/openai/api_resources/chat_completion.py", line 25, in create
    return super().create(*args, **kwargs)
  File "/root/anaconda3/lib/python3.8/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
    response, _, api_key = requestor.request(
  File "/root/anaconda3/lib/python3.8/site-packages/openai/api_requestor.py", line 298, in request
    resp, got_stream = self._interpret_response(result, stream)
  File "/root/anaconda3/lib/python3.8/site-packages/openai/api_requestor.py", line 700, in _interpret_response
    self._interpret_response_line(
  File "/root/anaconda3/lib/python3.8/site-packages/openai/api_requestor.py", line 763, in _interpret_response_line
    raise self.handle_error_response(
openai.error.InvalidRequestError: Unrecognized request argument supplied: functions

To Reproduce

  1. run the code snippet
  2. get the error

Code snippets

import openai

AZURE_KEY = "<key here>"
AZURE_ENDPOINT = "<endpoint here>"

messages = [{"role": "user", "content": "What's the weather like in Boston?"}]
functions = [
    {
        "name": "get_current_weather",
        "description": "Get the current weather in a given location",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "The city and state, e.g. San Francisco, CA",
                },
                "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
            },
            "required": ["location"],
        },
    }
]
openai.api_type = "azure"
openai.api_key = AZURE_KEY
openai.api_base = AZURE_ENDPOINT
openai.api_version = "2023-05-15"

chat_completion = openai.ChatCompletion.create(
    engine="gpt-35-turbo",
    messages=messages,
    functions=functions
)

OS

linux

Python version

python 3.8

Library version

v0.27.8

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

remember update this config openai.api_version = "2023-07-01-preview"

here what is working for me:

openai.api_version = "2023-07-01-preview"
response = openai.ChatCompletion.create(
    engine="gpt-35-turbo-0613",
    messages=[{"role": "user", "content": "Efficient operations on the ground and friendly, attentive employees everywhere."}],
    functions=functions,
    function_call="auto",
)

is there a known workaround ? or we need to wait for azure to support functions ?

remember update this config openai.api_version = "2023-07-01-preview"

You save me.

The question came up again.