-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
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
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working