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

fix: limit image size, fixes exception for large images (fixes #185) #188

Merged
merged 2 commits into from
Oct 10, 2024

Conversation

ErikBjare
Copy link
Owner

@ErikBjare ErikBjare commented Oct 9, 2024

Important

Adds a 5MB image size limit and provider check in _content_files_list() in message.py to prevent exceptions with large images.

  • Behavior:
    • Adds a 5MB size limit for image files in _content_files_list() in message.py. If exceeded, appends a warning message to content.
    • Raises ValueError if neither openai nor anthropic is specified in _content_files_list().
  • Refactoring:
    • Refactors file reading and base64 encoding to store in data variable for reuse in message.py.

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

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 9a4d2f6 in 21 seconds

More details
  • Looked at 60 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_4pA8j01BQW1yowxI


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.

# anthropic limit is 5MB
# TODO: use compression to reduce file size
# print(f"{len(data)=}")
if len(data) > 5_000_000:
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking the size of data (base64 encoded) is incorrect for file size validation. Base64 encoding increases the size by approximately 33%. Instead, check len(data_bytes) to ensure the original file size is within limits.

Copy link
Owner Author

Choose a reason for hiding this comment

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

@ellipsis-dev I did that originally, but it didn't match the numbers returned by the API (roughly the 33% difference), maybe add a comment about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ErikBjare, I have addressed your comments in pull request #189


You can configure Ellipsis to address comments with a direct commit or a side PR, see docs.

@codecov-commenter
Copy link

codecov-commenter commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

Project coverage is 80.78%. Comparing base (f258602) to head (0f4a8b7).
Report is 4 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
gptme/message.py 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #188      +/-   ##
==========================================
+ Coverage   80.39%   80.78%   +0.39%     
==========================================
  Files          56       56              
  Lines        3305     3315      +10     
==========================================
+ Hits         2657     2678      +21     
+ Misses        648      637      -11     
Flag Coverage Δ
anthropic/claude-3-haiku-20240307 79.69% <57.14%> (+0.36%) ⬆️
openai/gpt-4o-mini 79.12% <57.14%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

ellipsis-dev bot added a commit that referenced this pull request Oct 9, 2024
…ixes exception when viewing large images (#185));
gptme/message.py Outdated Show resolved Hide resolved
@ErikBjare ErikBjare changed the title fix: limit image size, fixes exception when viewing large images (#185) fix: limit image size, fixes exception when viewing large images (fixes #185) Oct 10, 2024
@ErikBjare ErikBjare changed the title fix: limit image size, fixes exception when viewing large images (fixes #185) fix: limit image size, fixes exception for large images (fixes #185) Oct 10, 2024
@ErikBjare ErikBjare merged commit 45cfbac into master Oct 10, 2024
7 checks passed
@ErikBjare ErikBjare deleted the dev/large-image-check branch October 10, 2024 10:39
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.

2 participants