Commit 61bccb4
Fix ActiveStorage::Blob re-upload if used in
## What this does
Fixes #665
When an `ActiveStorage::Blob` is passed to `ask` or
`create_user_message` via `with:`, it is downloaded and re-uploaded as a
new blob. This is because the blob gets wrapped in a
`RubyLLM::Attachment` during content building, so it goes to the `else`
branch in `prepare_for_active_storage` and
`convert_to_active_storage_format` is called, which always creates a new
IO hash.
=> Fix by updating `convert_to_active_storage_format` to detect
`ActiveStorage` objects and return it directly so it can be reused.
## Type of change
- [x] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation
- [ ] Performance improvement
## Scope check
- [x] I read the [Contributing
Guide](https://github.com/crmne/ruby_llm/blob/main/CONTRIBUTING.md)
- [x] This aligns with RubyLLM's focus on **LLM communication**
- [x] This isn't application-specific logic that belongs in user code
- [x] This benefits most users, not just my specific use case
## Quality check
- [x] I ran `overcommit --install` and all hooks pass
- [x] I tested my changes thoroughly
- [ ] For provider changes: Re-recorded VCR cassettes with `bundle exec
rake vcr:record[provider_name]`
- [x] All tests pass: `bundle exec rspec`
- [ ] I updated documentation if needed
- [x] I didn't modify auto-generated files manually (`models.json`,
`aliases.json`)
## AI-generated code
- [x] I used AI tools to help write this code
- [x] I have reviewed and understand all generated code (required if
above is checked)
## API changes
- [ ] Breaking change
- [ ] New public methods/classes
- [ ] Changed method signatures
- [x] No API changes
Co-authored-by: nebel95 <nebel95@wallwisher.com>
Co-authored-by: Carmine Paolino <carmine@paolino.me>with: param (#683)1 parent f63c65a commit 61bccb4
2 files changed
Lines changed: 30 additions & 5 deletions
File tree
- lib/ruby_llm/active_record
- spec/ruby_llm/active_record
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
425 | 432 | | |
426 | 433 | | |
427 | 434 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
91 | 109 | | |
92 | 110 | | |
93 | 111 | | |
| |||
0 commit comments