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: anthropic batching code #1064

Merged
merged 4 commits into from
Oct 20, 2024
Merged

feat: anthropic batching code #1064

merged 4 commits into from
Oct 20, 2024

Conversation

jxnl
Copy link
Collaborator

@jxnl jxnl commented Oct 11, 2024

I'm pretty sure this works, but I would love some time for someone else to verify some of the loose ends. I don't know how to test this yet.


Important

Adds support for managing batch jobs on Anthropic alongside OpenAI, updating CLI and batch processing logic.

  • CLI Enhancements:
    • Added --use-anthropic flag in batch.py to switch between OpenAI and Anthropic.
    • Updated create_from_file, cancel, and download_file commands to support Anthropic API.
    • Modified generate_table and get_jobs to handle Anthropic batch jobs.
  • Batch Processing:
    • Updated BatchJob class in batch.py to parse and create batch jobs for both OpenAI and Anthropic.
    • Removed openai_models type and generalized model handling.
    • Adjusted RequestBody and BatchModel to accommodate Anthropic requests.
  • Documentation:
    • Updated batch.md to include instructions for using Anthropic API.
    • Added examples for creating, listing, and managing batch jobs with Anthropic.

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

@jxnl jxnl requested a review from ivanleomk October 11, 2024 03:36
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.

❌ Changes requested. Reviewed everything up to 1bdc2d5 in 39 seconds

More details
  • Looked at 692 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. docs/cli/batch.md:1
  • Draft comment:
    If this is a new file, ensure it's added to mkdocs.yml for documentation consistency.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The mkdocs.yml file needs to be updated to include the new batch.md file for documentation consistency.
2. instructor/batch.py:114
  • Draft comment:
    Add comments to explain the logic in create_from_messages, especially around handling different modes for OpenAI and Anthropic.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The function create_from_messages in batch.py is quite complex and would benefit from comments explaining the logic, especially around the handling of different modes for OpenAI and Anthropic.
3. instructor/cli/batch.py:39
  • Draft comment:
    The use of str() around getattr calls is unnecessary and can be removed for cleaner code. This applies to lines 39, 40, and 41.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The generate_table function in batch.py uses getattr to access attributes, which is a good practice to avoid errors if the attribute doesn't exist. However, the use of str() around these calls is unnecessary and can be removed for cleaner code.
4. instructor/cli/batch.py:104
  • Draft comment:
    Avoid using eval for parsing JSON data. Use json.loads instead for security reasons.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_0XQLXZjyvf4ZN6vE


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

"[bold green]Creating Anthropic batch job...", spinner="dots"
):
with open(file_path, "r") as file:
requests = [eval(line) for line in file]
Copy link
Contributor

Choose a reason for hiding this comment

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

Using eval to parse JSON is a security risk. Consider using json.loads(line) instead.

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! Incremental review on fbf81a7 in 20 seconds

More details
  • Looked at 56 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. instructor/cli/batch.py:103
  • Draft comment:
    Using eval to parse file content is a security risk. Consider using json.loads instead for safer parsing.
  • Reason this comment was not posted:
    Comment was on unchanged code.
2. instructor/cli/batch.py:13
  • Draft comment:
    list[Any] is not compatible with Python versions below 3.9. Use List[Any] for compatibility.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The generate_table function uses list[Any] which is not compatible with Python versions below 3.9. It should be replaced with List[Any] for compatibility.
3. instructor/cli/batch.py:13
  • Draft comment:
    For compatibility with Python versions below 3.9, use List[Any] instead of list[Any]. This also applies to other instances in the codebase.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The generate_table function uses list[Any] which is not compatible with Python versions below 3.9. It should be updated for compatibility.

Workflow ID: wflow_j3F1tpwsSjPIJ9Ne


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

@jxnl jxnl added the enhancement New feature or request label Oct 11, 2024
Copy link

Deploying instructor-py with  Cloudflare Pages  Cloudflare Pages

Latest commit: e2e6b6c
Status:⚡️  Build in progress...

View logs

@jxnl jxnl merged commit 0a18c1a into main Oct 20, 2024
7 of 15 checks passed
@jxnl jxnl deleted the anthropic-batch branch October 20, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants