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

made pydantic change #1879

Closed
wants to merge 2 commits into from
Closed

made pydantic change #1879

wants to merge 2 commits into from

Conversation

Konnor-Young
Copy link

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

In the model_dump_json method of the BaseModel class on line 365 the if statement was essentially set to always throw the ValueError if you have done what you are supposed to. I changed the "if warnings != True: -> raise ValueError" to "if warnings == True: -> raise ValueError" so now the code will properly handle when you have pydantic v1 and set your warnings to False.

Additional context & links

@Konnor-Young Konnor-Young requested a review from a team as a code owner November 20, 2024 18:25
@RobertCraigie
Copy link
Collaborator

Thanks for the PR but I'm sorry I don't quite understand the change here, this means that when you call .model_dump_json() you'll get an error and you can't set warnings to False in Pydantic v1 in the first place?

@Konnor-Young
Copy link
Author

Thanks for the PR but I'm sorry I don't quite understand the change here, this means that when you call .model_dump_json() you'll get an error and you can't set warnings to False in Pydantic v1 in the first place?

Thanks for the reply!

Sorry I was not as clear as I thought, this might be a bigger problem than I had originally looked at. So here is what was happening:
The Repo I am working on is not able to upgrade to Pydantic-V2.
When I am using the AsyncAssistantEventHelper it tries to call the "accumulate_event()" function which if it hits the IndexError tries to call model_dump with warnings set to False.
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), ), ), )

Since "warnings is only supported in Pydantic V2" This would be correct I would want warnings to be set to False. The problem is the "if warnings != True:", since warning is False, raises the ValueError telling me that warnings cannot be true when I have Pydantic V1. So I changed that line so that if Pydantic is not V2 and warnings is True then raise the error about not being able to set warnings to True with Pydantic V1.

After I made that change my code worked as intended and I no longer had issues. I just think that the statement is backwards because that if statement only runs if Pydantic is not V2 then only raises an error if warnings is set to not set True. Shouldn't it raise the error when the user is trying to use warnings in Pydantic V1?

@RobertCraigie
Copy link
Collaborator

What openai version were you using? If I remember correctly that was a bug that has since been fixed, can you try again with the latest version?

@Konnor-Young
Copy link
Author

What openai version were you using? If I remember correctly that was a bug that has since been fixed, can you try again with the latest version?

I just updated to version 1.55.0 then ran the functions, and I got the same errors as before. So then I went back into _models.py and changed that if statement back to == True instead of != True. Which resolved the error again

@RobertCraigie
Copy link
Collaborator

oh, can you open an issue with a minimal reproduction?

@Konnor-Young
Copy link
Author

oh, can you open an issue with a minimal reproduction?

I created that issue, here is the link: #1882 (comment)

@RobertCraigie
Copy link
Collaborator

thanks, closing this in favour of a different fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants