You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-38Lines changed: 39 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,21 @@
2
2
3
3
This is a Python client for [Replicate](https://replicate.com). It lets you run models from your Python code or Jupyter notebook, and do various other things on Replicate.
4
4
5
+
## Breaking Changes in 1.0.0
6
+
7
+
The 1.0.0 release contains breaking changes:
8
+
9
+
- The `replicate.run()` method now returns `FileOutput`s instead of URL strings by default for models that output files. `FileOutput` implements an iterable interface similar to `httpx.Response`, making it easier to work with files efficiently.
10
+
11
+
To revert to the previous behavior, you can opt out of `FileOutput` by passing `use_file_output=False` to `replicate.run()`:
In most cases, updating existing applications to call `output.url` should resolve any issues. But we recommend using the `FileOutput` objects directly as we have further improvements planned to this API and this approach is guaranteed to give the fastest results.
18
+
19
+
> [!TIP]
5
20
> **👋** Check out an interactive version of this tutorial on [Google Colab](https://colab.research.google.com/drive/1K91q4p-OhL96FHBAVLsv9FlwFdu6Pn3c).
6
21
>
7
22
> [](https://colab.research.google.com/drive/1K91q4p-OhL96FHBAVLsv9FlwFdu6Pn3c)
@@ -30,17 +45,18 @@ We recommend not adding the token directly to your source code, because you don'
30
45
31
46
## Run a model
32
47
33
-
Create a new Python file and add the following code,
34
-
replacing the model identifier and input with your own:
48
+
Create a new Python file and add the following code, replacing the model identifier and input with your own:
Is a file-like object returned from the `replicate.run()` method that makes it easier to work with models
299
-
that output files. It implements `Iterator` and `AsyncIterator` for reading the file data in chunks as well
300
-
as `read` and `aread()` to read the entire file into memory.
301
-
302
-
Lastly, the underlying datasource is available on the `url` attribute.
315
+
Is a [file-like](https://docs.python.org/3/glossary.html#term-file-object) object returned from the `replicate.run()` method that makes it easier to work with models that output files. It implements `Iterator` and `AsyncIterator` for reading the file data in chunks as well as `read()` and `aread()` to read the entire file into memory.
303
316
304
317
> [!NOTE]
305
-
> The `url` attribute can vary between a remote URL and a data-uri depending on whether the server has
306
-
> optimized the request. For small files <5mb using the syncronous API data-uris will be returned to
307
-
> remove the need to make subsequent requests for the file data. To disable this pass `wait=false`
308
-
> to the replicate.run() function.
318
+
> It is worth noting that at this time `read()` and `aread()` do not currently accept a `size` argument to read up to `size` bytes.
309
319
310
-
To access the file URL:
320
+
Lastly, the URL of the underlying data source is available on the `url` attribute though we recommend you use the object as an iterator or use its `read()` or `aread()` methods, as the `url` property may not always return HTTP URLs in future.
311
321
312
322
```python
313
323
print(output.url) #=> "data:image/png;base64,xyz123..." or "https://delivery.replicate.com/..."
@@ -439,13 +449,9 @@ Here's how to list of all the available hardware for running models on Replicate
439
449
440
450
## Fine-tune a model
441
451
442
-
Use the [training API](https://replicate.com/docs/fine-tuning)
443
-
to fine-tune models to make them better at a particular task.
444
-
To see what **language models** currently support fine-tuning,
445
-
check out Replicate's [collection of trainable language models](https://replicate.com/collections/trainable-language-models).
452
+
Use the [training API](https://replicate.com/docs/fine-tuning) to fine-tune models to make them better at a particular task. To see what **language models** currently support fine-tuning, check out Replicate's [collection of trainable language models](https://replicate.com/collections/trainable-language-models).
446
453
447
-
If you're looking to fine-tune **image models**,
448
-
check out Replicate's [guide to fine-tuning image models](https://replicate.com/docs/guides/fine-tune-an-image-model).
454
+
If you're looking to fine-tune **image models**, check out Replicate's [guide to fine-tuning image models](https://replicate.com/docs/guides/fine-tune-an-image-model).
449
455
450
456
Here's how to fine-tune a model on Replicate:
451
457
@@ -467,24 +473,19 @@ training = replicate.trainings.create(
467
473
468
474
## Customize client behavior
469
475
470
-
The `replicate` package exports a default shared client.
471
-
This client is initialized with an API token
472
-
set by the `REPLICATE_API_TOKEN` environment variable.
476
+
The `replicate` package exports a default shared client. This client is initialized with an API token set by the `REPLICATE_API_TOKEN` environment variable.
473
477
474
-
You can create your own client instance to
475
-
pass a different API token value,
476
-
add custom headers to requests,
477
-
or control the behavior of the underlying [HTTPX client](https://www.python-httpx.org/api/#client):
478
+
You can create your own client instance to pass a different API token value, add custom headers to requests, or control the behavior of the underlying [HTTPX client](https://www.python-httpx.org/api/#client):
0 commit comments