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

Refactor anthropic message format to support tool messages & Allows Anthropic Bedrock clients #579

Merged
merged 5 commits into from
Apr 11, 2024

Conversation

lazyhope
Copy link
Contributor

@lazyhope lazyhope commented Apr 8, 2024

Instead of concatenating strings with "\n\n", we use the following format to merge consecutive Anthropic messages of the same roles:

{
  "role": "user", 
  "content": [
    {"type": "text", "text": "Hello, Claude"},
    {"type": "text", "text": "How is it going?"}
  ]
}

Which also allows other message types like image objects, tool invocation (for assistant), tool results, etc. As a comparsion, this version of tool support is able to pass the anthropic tests which currently fails.


Ellipsis 🚀 This PR description was created by Ellipsis for commit 9705a6f.

Summary:

This PR refactors the anthropic message format to support tool messages, updates the reask_messages and merge_consecutive_messages functions, and modifies the corresponding tests.

Key points:

  • Refactored reask_messages function in /instructor/retry.py to include the original response and format error messages differently.
  • Updated merge_consecutive_messages function in /instructor/utils.py to handle the new message format.
  • Updated tests in /tests/test_utils.py to reflect these changes.

Generated with ❤️ by ellipsis.dev

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Apr 8, 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 9705a6f
  • Looked at 117 lines of code in 3 files
  • Took 46 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/retry.py:45:
  • Assessed confidence : 50%
  • Comment:
    The error message in the assertion could be more descriptive. Instead of 'Tool use ID not found in the response', it could be 'Expected tool use ID in the response but none found'.
assert tool_use_id is not None, "Expected tool use ID in the response but none found"
  • Reasoning:
    The changes in the PR seem to be logically correct and follow the best practices. The code is not overly complicated and the variable names are descriptive. The function naming follows a consistent pattern. The changes in the library code are reflected in the tests. The assertions have well-formatted error messages. However, I noticed that the error message in the assertion at line 45 in retry.py could be more descriptive. Instead of 'Tool use ID not found in the response', it could be 'Expected tool use ID in the response but none found'.

Workflow ID: wflow_rMlGfFzdJ9S22wtA


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

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 8, 2024
@lazyhope lazyhope changed the title Refactor anthropic message format to support tool messages Refactor anthropic message format to support tool messages & Allows Anthropic Bedrock clients Apr 8, 2024
Copy link
Collaborator

@jxnl jxnl left a comment

Choose a reason for hiding this comment

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

  1. skip anthropic bedrock tests
  2. add some logic to avoid doing the merge for openai keys

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 8, 2024
@jxnl
Copy link
Collaborator

jxnl commented Apr 10, 2024

is this good to merge?

@lazyhope
Copy link
Contributor Author

is this good to merge?

Yeah, I was waiting for it to be merged these days 😂

@jxnl jxnl merged commit 2edae25 into instructor-ai:main Apr 11, 2024
0 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants