Skip to content

ChatCompletion doesn't handle enum with None #554

Description

@Lurrobert

Describe the bug

if for example the enum for the function looks like this:
enums = ['Life cycle', 'App developer', 'Games reporting', 'User', None]
which is later used in the functions call:

...
"parameters": {
                "type": "object",
                "properties": {
                    "parent": {
                        "type": "string",
                        "enum": enums,
                    },
...

the case with None is not handled and server responds with the 500

Logs:

"outputs": [
    {
     "ename": "APIError",
     "evalue": "The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error. (Please include the request ID cdee293f61742a79122d04d81a0b9465 in your email.) {\n  \"error\": {\n    \"message\": \"The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error. (Please include the **request ID cdee293f61742a79122d04d81a0b9465** in your email.)\",\n    \"type\": \"server_error\",\n    \"param\": null,\n    \"code\": null\n  }\n}\n 500 {'error': {'message': 'The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error. (Please include the request ID cdee293f61742a79122d04d81a0b9465 in your email.)',
...

request ID cdee293f61742a79122d04d81a0b9465

To Reproduce

  1. create an enum with None as a variable
  2. trigger a function call

Code snippets

functions = [
        {
            "name": "get_relevant_action",
            "description": "",
            "parameters": {
                "type": "object",
                "properties": {
                    "parent": {
                        "type": "string",
                        "enum": ['Life cycle', 'App developer', 'Games reporting', 'User', None],
                        "description": "parent text of the button to click",
                    }
                },
                "required": ["parent"],
            },
        }
    ]

response = openai.ChatCompletion.create(
    model="gpt-4",
    messages=messages,
    functions=functions,
    function_call={"name": "get_relevant_action"},
)
response_message = response["choices"][0]["message"]

OS

macos

Python version

3.10

Library version

v0.27.8

Activity

  1. changed the title [-]ChatCompletion doesn't handle enum == None[/-] [+]ChatCompletion doesn't handle enum with None[/+] on Jul 29, 2023
  2. logankilpatrick commented on Sep 6, 2023

    @logankilpatrick
    Contributor

    This is working as expected, you specify the type as string and then pass a non string type in the list thus the JSON is not valid (which is a step we check behind the scenes) for functions. You can use a simple validator like this one: https://www.jsonschemavalidator.net/ to test this.

  3. added and removed
    bugSomething isn't working
    on Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions