Provide a singleton instance of Replicate as default entrypoint #188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Python library currently exports a singleton instance which can be used to run a model in a two liner:
Our JavaScript library has a different interface that requires the
replicate
instance to be instantiated. Our examples all include the line:This change removes the need to create the client instance, and brings it inline with the Python client making the library very quick to get up and running. Basic usage is now:
To ensure this is a backwards compatible change we use a
Proxy
instance to ensure that the library keeps working in its existing state though with a@deprecated
type annotation which will show up in editors.The constructor is still available via
replicate.Replicate()
for users that need to customize the configuration.Changes
I've made the following additional changes.
index.d.ts
but as a next step I'd like to generate this from the index.js file itself.Notes on ESM modules
In a next step I'd like to provide an ESM specific build which will remove the slightly janky flow (naming collision) for ESM & TypeScript users. (This is done in #191).