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

feat: fix anthropic reasking #560

Merged
merged 4 commits into from
Apr 3, 2024
Merged

feat: fix anthropic reasking #560

merged 4 commits into from
Apr 3, 2024

Conversation

jxnl
Copy link
Collaborator

@jxnl jxnl commented Apr 3, 2024

#559


Ellipsis 🚀 This PR description was created by Ellipsis for commit abbfbcd.

Summary:

This PR introduces a fix for anthropic reasking by adding a utility function to merge consecutive user messages, modifying the parse_anthropic_json function, updating tests, and modifying the import logic in __init__.py.

Key points:

  • Added merge_consecutive_messages function in utils.py to merge consecutive user messages.
  • Used merge_consecutive_messages in process_response.py and retry.py.
  • Modified parse_anthropic_json in function_calls.py to assert completion is an instance of Message.
  • Modified test_simple.py to use from_anthropic function and added a field validator to User class.
  • Added tests for merge_consecutive_messages in test_utils.py.
  • Modified import logic in __init__.py to check for anthropic and groq modules.

Generated with ❤️ by ellipsis.dev

Copy link

cloudflare-workers-and-pages bot commented Apr 3, 2024

Deploying instructor with  Cloudflare Pages  Cloudflare Pages

Latest commit: b4c64fa
Status: ✅  Deploy successful!
Preview URL: https://fcaafdc9.instructor.pages.dev
Branch Preview URL: https://fix-anthropic-reask.instructor.pages.dev

View logs

@jxnl jxnl marked this pull request as ready for review April 3, 2024 22:31
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Apr 3, 2024
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me!

  • Reviewed the entire pull request up to b4c64fa
  • Looked at 271 lines of code in 6 files
  • Took 1 minute and 36 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 4 additional comments because they didn't meet confidence threshold of 85%.
1. instructor/utils.py:125:
  • Assessed confidence : 0%
  • Comment:
    The function merge_consecutive_messages is implemented correctly and used appropriately in other files. It merges consecutive messages from the same role into a single message, reducing redundancy and making the code cleaner.
  • Reasoning:
    The function merge_consecutive_messages in utils.py is used in multiple places (process_response.py, retry.py). This function merges consecutive messages from the same role into a single message. This is a good practice as it reduces redundancy and makes the code cleaner.
2. instructor/function_calls.py:135:
  • Assessed confidence : 0%
  • Comment:
    The modification to the function parse_anthropic_json is appropriate. Importing Message from anthropic.types and asserting that completion is an instance of Message ensures that the completion argument is of the expected type, reducing the likelihood of runtime errors.
  • Reasoning:
    The function parse_anthropic_json in function_calls.py has been modified to import Message from anthropic.types and assert that completion is an instance of Message. This is a good practice as it ensures that the completion argument is of the expected type, reducing the likelihood of runtime errors.
3. instructor/process_response.py:339:
  • Assessed confidence : 0%
  • Comment:
    The modification to the function handle_response_model is appropriate. Merging consecutive user messages into a single message when the mode is Mode.ANTHROPIC_JSON ensures that the messages array alternates between user and assistant roles, which is a requirement for this mode.
  • Reasoning:
    The function handle_response_model in process_response.py has been modified to merge consecutive user messages into a single message when the mode is Mode.ANTHROPIC_JSON. This is a good practice as it ensures that the messages array alternates between user and assistant roles, which is a requirement for this mode.
4. instructor/retry.py:110:
  • Assessed confidence : 0%
  • Comment:
    The modification to the function retry_sync is appropriate. Merging consecutive messages into a single message after extending kwargs['messages'] with reask_messages(response, mode, e) ensures that the messages array alternates between user and assistant roles, which is a requirement for this mode.
  • Reasoning:
    The function retry_sync in retry.py has been modified to merge consecutive messages into a single message after extending kwargs['messages'] with reask_messages(response, mode, e). This is a good practice as it ensures that the messages array alternates between user and assistant roles, which is a requirement for this mode.

Workflow ID: wflow_TU98OKSrOB9dCQ0B


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

@jxnl jxnl merged commit 1f7926d into main Apr 3, 2024
5 of 12 checks passed
@jxnl jxnl deleted the fix-anthropic-reask branch April 3, 2024 22:37
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me!

  • Performed an incremental review on abbfbcd
  • Looked at 70 lines of code in 3 files
  • Took 1 minute and 50 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 1 additional comments because they didn't meet confidence threshold of 85%.
1. instructor/client_anthropic.py:25:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The PR description mentions changes to utils.py, process_response.py, and retry.py related to the merge_consecutive_messages function. However, these changes are not visible in the diff. Please ensure these changes are included in the commit.
  • Reasoning:
    The PR description mentions that a utility function merge_consecutive_messages has been added to utils.py and used in process_response.py and retry.py. However, the diff does not show any changes to these files. It's possible that the PR author forgot to include these changes in the commit. I need to comment on this discrepancy and ask the author to include these changes.

Workflow ID: wflow_1knsn5geWIYg71uN


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

PrathamSoni pushed a commit to EndexAI/instructor that referenced this pull request Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant