openai / openai-python

The official Python library for the OpenAI API
https://pypi.org/project/openai/
Apache License 2.0
23.09k stars 3.25k forks source link

Error note that json_schema is not available on gpt-4o-mini #1820

Closed RemixaWorld closed 4 weeks ago

RemixaWorld commented 4 weeks ago

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

Describe the bug

I used AsyncOpenAI Client to execute the tasks that required structed output (model as "gpt-4o-mini"). The first few runs of the same code returned normal results, but without any changes to the code, Suddenly I get a 400 error "response_format value as json_schema is enabled only for api versions 2024-08-01-preview and later".

To Reproduce

  1. Instantiate one AsyncOpenAI:
    aclient = AsyncOpenAI()
  2. Define the data model as follows:
    class Term(BaseModel):
    term: str
    definition: str
    class Terms(BaseModel):
    terms: List[Term]
  3. Use the following code to make the request:
    
    reference_text = "Machine learning is a very important subject."
    system_promt = "You are an expert in the field of machine learning.Please extract the terms and definitions from the reference text according to the appropriate format."
    user_prompt = "Given the following reference text:\n{}"

async def aquery(self, reference_text: str): response = await aclient.beta.chat.completions.parse( model="gpt-4o-mini", messages=[{"role": "system", "content": system_prompt}, {"role": "user", "content": user_prompt.format(reference_text)}], temperature=0.1, response_format=Terms ) return json.loads(response.choices[0].message.content)


### Code snippets

```Python
openai.BadRequestError: Error code: 400 - {'error': {'message': 'response_format value as json_schema is enabled only for api versions 2024-08-01-preview and later', 'type': '', 'param': '', 'code': 'BadRequest'}}

OS

Ubuntu 20.04.6 LTS

Python version

Python 3.10.15

Library version

openai v1.51.1