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: Patch Anthropic system message #1112

Closed
wants to merge 6 commits into from

Conversation

arcaputo3
Copy link
Contributor

@arcaputo3 arcaputo3 commented Oct 23, 2024

  • Enable OpenAI-style system messages with arrays for Anthropic
  • Allow prompt caching at the system message level for Anthropic
  • Remove Databricks assertion as they now mimic OpenAI broadly
  • Enable multimodality without response model and autodetect_images=False

Important

Enhance Anthropic system message handling with OpenAI-style support, prompt caching, and multimodality adjustments, while removing Databricks-specific assertion.

  • Behavior:
    • Enable OpenAI-style system messages with arrays for Anthropic in process_response.py.
    • Allow prompt caching at the system message level for Anthropic in process_response.py.
    • Remove Databricks assertion in client.py as they now mimic OpenAI broadly.
    • Enable multimodality without response model and autodetect_images=False in process_response.py.
  • Utilities:
    • Add combine_system_messages() and extract_system_messages() in utils.py to handle system messages.
  • Tests:
    • Add test_system.py to test Anthropic system message handling.
    • Add tests for combine_system_messages() and extract_system_messages() in test_utils.py.

This description was created by Ellipsis for 0b6d0d1. It will automatically update as commits are pushed.

- Enable OpenAI-style system messages with arrays for Anthropic
- Allow prompt caching at the system message level for Anthropic
- Remove Databricks assertion as they now mimic OpenAI broadly
- Enable multimodality without response model and `autodetect_images=False`
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 everything up to 0b6d0d1 in 23 seconds

More details
  • Looked at 531 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. instructor/process_response.py:335
  • Draft comment:
    The logic for handling system messages is duplicated in handle_anthropic_tools and handle_anthropic_json. Consider refactoring to avoid duplication.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    In instructor/process_response.py, the handle_anthropic_tools and handle_anthropic_json functions both use extract_system_messages and combine_system_messages. The logic for handling system messages is duplicated. Consider refactoring to avoid code duplication.
2. instructor/process_response.py:352
  • Draft comment:
    The logic for handling system messages is duplicated in handle_anthropic_tools and handle_anthropic_json. Consider refactoring to avoid duplication.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    In instructor/process_response.py, the handle_anthropic_tools and handle_anthropic_json functions both use extract_system_messages and combine_system_messages. The logic for handling system messages is duplicated. Consider refactoring to avoid code duplication.
3. tests/llm/test_anthropic/test_system.py:37
  • Draft comment:
    Assertions should include error messages for better debugging. This applies to all assertions in this file and in tests/test_utils.py.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The assertion statements in the test files lack error messages, which is against the rule that assertions should always have an error message.
4. tests/llm/test_anthropic/test_system.py:1
  • Draft comment:
    Ensure this new test file is added to the mkdocs.yml for documentation purposes.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The new test file should be added to the mkdocs.yml for documentation purposes.

Workflow ID: wflow_z14QsaO8RsmT88IQ


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@jxnl
Copy link
Collaborator

jxnl commented Oct 28, 2024

have you tested this all locally?

arcaputo3 and others added 2 commits October 28, 2024 13:13
@arcaputo3
Copy link
Contributor Author

have you tested this all locally?

yes I tried to make sure that this isn't a breaking change for standard system messages by merging them if they exist. tests are passing locally

@ivanleomk
Copy link
Collaborator

Forked this in #1130 and made changes there.

@ivanleomk ivanleomk closed this Oct 29, 2024
@arcaputo3
Copy link
Contributor Author

@ivanleomk thanks for the cleanup!

@arcaputo3 arcaputo3 deleted the patch-anthropic-system branch October 29, 2024 17:48
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.

3 participants