Skip to content

Conversation

@altxtech
Copy link
Contributor

@altxtech altxtech commented Nov 28, 2025

What this does

Add support for large file attachments with Gemini.

As per Gemini API, files larger than 20MB should be uploaded via the Files API before using them in prompting.

Implementation Strategy

Chat#add_message calls Provider#preprocess_message before registering new messages.

The Provider#preprocess_message is a hook that allows Providers to modify messages before saving them to the chat. The default implementation does nothing. For the Gemini provider it checks for large file attachments, uploads them and transforms them into URI attachments.

Rationale

We don't want to upload the file on every chat interaction, only once when the message is added to the chat, that's why I opted for this hook strategy.

Its also worth mentioning is that the FileUploadService creates its own connection instead of sharing with Provider. Did this to avoid modifying Connection and keeping this the scope of this PR small, but this would be a valid follow up refactor.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
    • For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

Related issues

Closes #426

@altxtech altxtech marked this pull request as ready for review November 28, 2025 20:40
@altxtech altxtech changed the title finalizing changes Gemini Large file support Nov 28, 2025
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.

[FEATURE] Support large videos (>20 MB) for Gemini

1 participant