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

fixes retry_async message unpacking #175

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

bradenkinard
Copy link
Contributor

@bradenkinard bradenkinard commented Nov 13, 2023

This fixes #174 by applying the same message appending logic as in the hotfix made here for retry_sync.

Summary by CodeRabbit

  • Refactor
    • Improved error handling and message storage in the retry mechanism for asynchronous operations.

Copy link
Contributor

coderabbitai bot commented Nov 13, 2023

Walkthrough

The patch updates the retry_async function to fix a bug related to error handling. Specifically, it changes how messages are appended to a list within kwargs, addressing an issue with the OpenAI SDK update to 1.0 where the previous method of using dict(**response.choices[0].message) was no longer valid.

Changes

File Change Summary
instructor/patch.py Modified retry_async function to append response.choices[0].message directly to kwargs["messages"].

Assessment against linked issues (Beta)

Objective Addressed Explanation
Resolve a bug in retry_async related to ValidationError or JSONDecodeError handling due to OpenAI SDK update to 1.0 (174)
Address the issue with dict(**response.choices[0].message) throwing an error (174)
Apply a similar hotfix to retry_async as was previously applied to retry_sync (174)

🐇 In the code's weave, a bug did hide,
Now fixed and patched with a coder's pride.
As autumn leaves fall, our software stands tall,
With every commit, we're improving it all! 🍂🔧


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 55efa8c and dd8f1fd.
Files selected for processing (1)
  • instructor/patch.py (1 hunks)
Additional comments: 1
instructor/patch.py (1)
  • 89-95: The change from using dict with ** unpacking to directly appending the message to kwargs["messages"] list is a simplification that should help avoid potential issues with unpacking and improve readability. However, ensure that response.choices[0].message is always available and that the structure of response is consistent with this expectation. If response.choices or response.choices[0].message could be None or not present, this could raise an AttributeError or IndexError. It might be necessary to add error handling for these cases.

Additionally, the message being appended is now just the response.choices[0].message, whereas previously it seems like a dictionary with role and content keys was being appended. Ensure that this change in the structure of the messages in kwargs["messages"] is intentional and does not affect downstream processing.

@jxnl
Copy link
Collaborator

jxnl commented Nov 13, 2023

thanks will add some more tests so this does not happen next time

@jxnl jxnl merged commit 209c06d into instructor-ai:main Nov 13, 2023
@jxnl
Copy link
Collaborator

jxnl commented Nov 13, 2023

@bradenkinard bradenkinard deleted the retry-async-hotfix branch July 30, 2024 13:41
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.

Validation error retry hotfix needs to be applied to retry_async
2 participants