Skip to content

File Upload/Download (to support Batches)#764

Draft
toddkummer wants to merge 3 commits into
crmne:mainfrom
toddkummer:files-api
Draft

File Upload/Download (to support Batches)#764
toddkummer wants to merge 3 commits into
crmne:mainfrom
toddkummer:files-api

Conversation

@toddkummer
Copy link
Copy Markdown

@toddkummer toddkummer commented May 7, 2026

What this does

This adds the ability to upload and download files, with only the OpenAI provider supported. This feature is a building block for the Batches API, which requires files to be uploaded and downloaded (for OpenAI Batches).

The logic could be simplified a bit and contained within the Batches functionality, but given that it is a provider supported endpoint it seemed to make sense to support it.

OpenAI Files API Documenation

Uploading Files

This adds a convenience method to the RubyLLM module to upload files:

uploaded = RubyLLM.upload_file(
  "spec/fixtures/openai_batch.jsonl",
  provider: :openai,
  purpose: "batch"
)

puts uploaded.id
puts uploaded.filename
puts uploaded.byte_size
puts uploaded.created_at

This delegates to the new ProviderFile class. (That name was chosen to avoid conflicts with File.) The ProviderFile class follows the convention of having a class method to invoke the logic and being the model instantiated to handle the response.

The ProviderFile#file_info method also returns an instance of the ProviderFile class. That method is not exposed through the RubyLLM module. (It just didn't feel important enough.)

Downloading Files

The RubyLLM module also includes a convenience method to download files:

saved_path = RubyLLM.download_file(
  "file_123",
  provider: :openai,
  path: "tmp/downloaded.jsonl"
)

puts saved_path

There are a number of ways to download a file.

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

Required for new features

PRs for new features or enhancements without a prior approved issue will be closed.

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
    • Manual testing
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

AI-generated code

  • I used AI tools to help write this code
  • I have reviewed and understand all generated code (required if above is checked)

API changes

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

toddkummer and others added 3 commits May 7, 2026 16:24
Includes top-level upload/download helpers, File metadata handling,
OpenAI file API integration, download support in Connection, and
specs/VCR coverage for upload, metadata lookup, and file content
download workflows.

The main class is named ProviderFile to avoid conflicts with File.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 77.58621% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.91%. Comparing base (4942d6c) to head (1bc90ea).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lib/ruby_llm/downloads.rb 46.66% 24 Missing ⚠️
lib/ruby_llm.rb 75.00% 1 Missing ⚠️
lib/ruby_llm/providers/openai/files.rb 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #764      +/-   ##
==========================================
- Coverage   87.05%   86.91%   -0.14%     
==========================================
  Files         119      122       +3     
  Lines        5594     5710     +116     
  Branches     1407     1436      +29     
==========================================
+ Hits         4870     4963      +93     
- Misses        724      747      +23     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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