openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

BadRequestError: Unsupported data type when creating an Azure OpenAI assistant

Open vishnumg opened this issue 1 year ago • 3 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [X] This is an issue with the Python library

Describe the bug

Attempting to create an Azure OpenAI assistant using the OpenAI Python library results in a BadRequestError: Unsupported data type.

Environment:

  • Python 3.12.3
  • Operating System: Windows 10
  • openai==1.35.7
  • Azure OpenAI API version: 2023-05-15

.env File:

OPENAI_API_VERSION=2023-05-15
AZURE_OPENAI_ENDPOINT=https://ai-111xxxxxx468527.openai.azure.com/
AZURE_OPENAI_API_KEY=6bXXXXXXXXXXXXXXXXXXXd41

Code:

import os
import time
import glob
from openai import AzureOpenAI
from dotenv import load_dotenv

load_dotenv()

client = AzureOpenAI(
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),
    api_version="2023-05-15",
    azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT")
)

assistant = client.beta.assistants.create(
    instructions="",
    model="gpt-4",
    tools=[]
)

Error Traceback:

Traceback (most recent call last):
  File "project_dir\metadata_assistant.py", line 16, in <module>
    assistant = client.beta.assistants.create(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "project_dir\.venv\Lib\site-packages\openai\resources\beta\assistants.py", line 156, in create
    return self._post(
           ^^^^^^^^^^^
  File "project_dir\.venv\Lib\site-packages\openai\_base_client.py", line 1250, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "project_dir\.venv\Lib\site-packages\openai\_base_client.py", line 931, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "project_dir\.venv\Lib\site-packages\openai\_base_client.py", line 1030, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Unsupported data type

Expected Behavior: The assistant should be created without any errors.

Actual Behavior: The following error is raised:

openai.BadRequestError: Unsupported data type

To Reproduce

  1. Set up the Azure OpenAI client using the provided API key and endpoint.
  2. Attempt to create an assistant using client.beta.assistants.create() method.

Code snippets

No response

OS

Windows

Python version

3.12.3

Library version

1.35.7

vishnumg avatar Jun 30 '24 20:06 vishnumg

@vishnumg Assistants is still in preview, so you'll need to target the preview API version == "2024-05-01-preview" (API reference).

That being said, I can't reproduce the error that you're seeing here. Can you try the preview API version and see if that works for you?

kristapratico avatar Jul 08 '24 22:07 kristapratico

@vishnumg your API version is 2023, before Assistants existed

hayescode avatar Jul 17 '24 05:07 hayescode

Would you please clarify this @leonprompter ? I had a similar issue here 'https://github.com/microsoft/semantic-kernel/discussions/9002#discussioncomment-10774526' and am interested in related solutions if you don't mind.

selfishark avatar Oct 07 '24 10:10 selfishark

I'm getting the same error and I'm unable to make any progress. I've tried different python versions and endpoints. I've verified the endpoints work but I am unable to create an assistant instance.

sebkouba avatar Nov 15 '24 12:11 sebkouba

I think this should be resolved now, please re-open if this is still an issue.

RobertCraigie avatar Feb 17 '25 11:02 RobertCraigie