Skip to content

Azure API does not support functions in chat? #517

@Billijk

Description

@Billijk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions