Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pydantic-V1 "warnings" error #1882

Closed
1 task done
Konnor-Young opened this issue Nov 21, 2024 · 2 comments
Closed
1 task done

Pydantic-V1 "warnings" error #1882

Konnor-Young opened this issue Nov 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Konnor-Young
Copy link

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

  • This is an issue with the Python library

Describe the bug

I am getting this Error:

File "/Users/konnoryoung/Documents/projects/contract-ai-poc/.errors/lib/python3.9/site-packages/openai/lib/streaming/_assistants.py", line 943, in accumulate_event
block = current_message_snapshot.content[content_delta.index]
IndexError: list index out of range

Which comes from the try/except block in the "accumulate_event" function:

try:
    block = current_message_snapshot.content[content_delta.index]
except IndexError:
    current_message_snapshot.content.insert(
    content_delta.index,
    cast(
        MessageContent,
        construct_type(
            # mypy doesn't allow Content for some reason
            type_=cast(Any, MessageContent),
            value=model_dump(content_delta, exclude_unset=True, warnings=False),
            ),
        ),
    )
    new_content.append(content_delta)

That wouldn't stop my code from running except that it raises another exception:

File "/Users/konnoryoung/Documents/projects/contract-ai-poc/.errors/lib/python3.9/site-packages/openai/_models.py", line 313, in model_dump
raise ValueError("warnings is only supported in Pydantic v2")
ValueError: warnings is only supported in Pydantic v2

Which comes from the if statement:

if warnings != True:
    raise ValueError("warnings is only supported in Pydantic v2")

In the if not PYDANTIC_V2 version of the model_dump method of the BaseModel class in the _model.py file.

To Reproduce

1- Pydantic < 2 (I have v1.9.0)
2- Create an assistant
3- Create a thread
4- Attempt to run an Async Stream (my code is below)

Code snippets

from __future__ import annotations

import asyncio

import openai

client = openai.AsyncOpenAI()

assistant_id= """ GetID OR Create an Assistant """
thread_id= """  GetID OR Create a Thread """
async def main() -> None:
    async with client.beta.threads.runs.stream(
        thread_id=thread_id,
        assistant_id=assistant_id,
        ) as stream:
            async for event in stream:
                print()

asyncio.run(main())

OS

masOS

Python version

Python 3.9.6

Library version

openai v1.55.0

@Konnor-Young Konnor-Young added the bug Something isn't working label Nov 21, 2024
@RobertCraigie
Copy link
Collaborator

Thanks for the example, I can reproduce the issue. Working on a fix.

@RobertCraigie
Copy link
Collaborator

@Konnor-Young this will be fixed in the next release! #1886

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants