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

Add conversion from ParsedChatCompletion to ChatCompletion #140

Conversation

sternakt
Copy link
Collaborator

@sternakt sternakt commented Dec 3, 2024

Why are these changes needed?

This PR introduces a _convert_to_chat_completion method that will convert ParsedChatCompletion objects into ChatCompletion objects. The ChatCompletion objects are picklable superclass of ParsedChatCompletion which contain all the fields that we use from the response in the client, so this approach enables caching of the responses generated while using response_format option.

Related issue number

Closes #133

Checks

Copy link
Collaborator

@ohdearquant ohdearquant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like straightforward change, only comment is on the aesthetic.

self._oai_client.beta.chat.completions.parse(*args, **kwargs) is a bit long. but if that's the standard approach, then this is fine.

@marklysze
Copy link
Collaborator

marklysze commented Dec 3, 2024

Tested with response format and without, as well as with non-OpenAI client. Working as expected, thanks @sternakt.

Additionally, tested with 3.5 turbo and the exception was handled okay (as 3.5 turbo doesn't support json schemas).

@marklysze marklysze added this pull request to the merge queue Dec 3, 2024
Merged via the queue into main with commit 0a9e847 Dec 3, 2024
214 checks passed
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.

[Issue]: Unable to cache ParsedChatCompletion Objects in OpenAIWrapper
3 participants