-
-
Notifications
You must be signed in to change notification settings - Fork 280
Add Replicate provider #435
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
base: main
Are you sure you want to change the base?
Conversation
config.around do |example| | ||
cassette_name = example.full_description.parameterize(separator: '_').delete_prefix('rubyllm_') | ||
VCR.use_cassette(cassette_name) do | ||
VCR.use_cassette(cassette_name, record: :new_episodes) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so existing stubs are kept and only new HTTP interactions are recorded onto the existing cassette. Makes it easier to contribute if you don’t have API keys for other providers. Specially for cassettes related to model lists like spec/fixtures/vcr_cassettes/models_refresh_updates_models_and_returns_a_chainable_models_instance.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to patch the models.rake
update logic to append the replicate models to existing ones (patch not committed). Without this patch, the whole file would get overwritten when regenerating and models would be missing, seeing as I don’t have credentials for all supported providers.
I believe this worked for regenerating the models.json
and aliases.json
files, but I don’t think it worked well for this file. I’m a bit lost as to how to solve this, any guidance is appreciated. 🙏
ac7a529
to
5dc8df3
Compare
Current replicate models output images Drop 'replicate' prefix from model names Force array on replicate webhook filters Run models rake tasks I hacked the models refresh logic to append the replicate models to existing ones. Without this patch, the whole file would get overwritten and models would be missing, seeing as I don’t have credentials for all supported providers. Fold image size into model params Record model list cassettes Add tests Return DeferredImage Poll in deferred image tests Imageable -> Blobbable Remove unnecessary test No need to set `@model_id` Update docs Typo
5dc8df3
to
f46795d
Compare
prediction = @connection.get(url).body | ||
return unless prediction['status'] == 'succeeded' | ||
|
||
image_url = Array(prediction['output']).first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some Replicate models return multiple images as an array, others just return a single URI.
Saving the RubyLLM::DeferredImage
only supports a single file. The multiple files use case deviates too much from the RubyLLM::Image
functionality. If that behavior is needed users should go the webhook route instead, as suggested in the docs.
What this does
This PR adds Replicate as a provider.
Replicate may stand out from other providers in several areas:
RubyLLM::DeferredImage
, whose method#to_blob
will returnnil
if the image isn’t ready, or binary data if it is.RubyLLM.image_from
, which knows how to fetch an image when it’s ready. This is useful because some providers, like Replicate, require authentication to fetch the finished result.RubyLLM.paint
—we’ll forward any unrecognized params to{ProviderInstance}#paint
.size
kwarg into these arbitrary kwargs to keep uniformity across providers.text-to-image
models.Please do let me know if any of the assumptions above don’t hold up or you’d like to do things differently.
Thanks for reading!
Type of change
Scope check
Quality check
overcommit --install
and all hooks passbundle exec rake vcr:record[provider_name]
bundle exec rspec
models.json
,aliases.json
)API changes
Related issues
Closes #410