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

Anthropic IncompleteOutputException was never triggered for tools and JSON modes #848

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

palako
Copy link
Contributor

@palako palako commented Jul 16, 2024

The parse_anthropic_tools and parse_anthropic_json code tries to do a model_validate_json which fails to parse when the output was interrupted due to max_tokens being reached.

The proposed change checks for max_tokens in the completion object before attempting to parse, and raises the correct exception, which will be then re-raised correctly at from_response given that it's not a ValueError anymore.


🚀 This description was created by Ellipsis for commit 34b20a5

Summary:

Fixes IncompleteOutputException not being triggered for parse_anthropic_tools and parse_anthropic_json when max_tokens is reached.

Key points:

  • Files Modified: instructor/function_calls.py
  • Functions Modified: parse_anthropic_tools, parse_anthropic_json
  • Changes:
    • Added check for max_tokens in completion object.
    • Raise IncompleteOutputException if completion.stop_reason is max_tokens.
    • Ensures correct exception handling before attempting to parse the output.

Generated with ❤️ by ellipsis.dev

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 34b20a5 in 26 seconds

More details
  • Looked at 26 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. instructor/function_calls.py:140
  • Draft comment:
    The addition of the check for max_tokens before parsing the completion is a good practice to handle incomplete outputs effectively. This ensures that the parsing logic is only applied to complete data, preventing potential errors or misinterpretations of incomplete data.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The PR introduces a check for the max_tokens stop reason before attempting to parse the completion in both parse_anthropic_tools and parse_anthropic_json methods. This is a logical addition to handle cases where the output is incomplete due to reaching the maximum token limit, which would otherwise lead to errors during parsing. The use of IncompleteOutputException is appropriate as it directly addresses the issue of incomplete outputs. The changes are consistent across both methods, ensuring uniform behavior in handling incomplete outputs in different parsing scenarios.

Workflow ID: wflow_VFVUXNkIIWYMjd0h


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

@jxnl jxnl merged commit 4860ca8 into jxnl:main Jul 26, 2024
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.

None yet

3 participants