Skip to content

Functions: Arguments are absent when called via ChatCompletion.acreate #488

@valaises

Description

@valaises

Describe the bug

Hi! If you create a chat using acreate, provide functions, up-to-date model, the arguments field is always empty regardless, reproduces every single time. Altho, if you are using simple synchronous create on the same setup, it works perfectly.

To Reproduce

ChatCompletion.acreate

gen = await openai.ChatCompletion.acreate(
    model='gpt-3.5-turbo-0613',
    messages=[{"role": "user", "content": "What's the weather like in Boston?"}],
    stream=True,
    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"],
            },
        }
    ],
    function_call='auto'
)

  resp = gen.__anext__()
  delta = resp.choices[0].delta
  print(f'DELTA:\n{delta}')

OUTPUT (ARGUMENTS ARE ABSENT)

DELTA:
{
  "role": "assistant",
  "content": null,
  "function_call": {
    "name": "get_current_weather",
    "arguments": ""
  }
}

ChatCompletion.create

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo-0613",
    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"],
            },
        }
    ],
    function_call="auto",
)

message = response["choices"][0]["message"]
print(message)

OUTPUT (ARGUMENTS ARE PRESENT)

{
  "role": "assistant",
  "content": null,
  "function_call": {
    "name": "get_current_weather",
    "arguments": "{\n  \"location\": \"Boston\"\n}"
  }
}

Code snippets

No response

OS

Ubuntu 20.04.5 LTS

Python version

Python 3.9.15

Library version

openai-python 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