Skip to content

Commit b5c9493

Browse files
committed
Pin everything to a version
This is a yucky API but it's better than breaking everyone's stuff.
1 parent a0ff4b3 commit b5c9493

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

README.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ You can run a model and get its output:
1414
$ python
1515
>>> import replicate
1616
>>> model = replicate.models.get("stability-ai/stable-diffusion")
17-
>>> model.predict(prompt="a 19th century portrait of a wombat gentleman")
17+
>>> version = model.versions.get("27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478")
18+
>>> version.predict(prompt="a 19th century portrait of a wombat gentleman")
1819
['https://replicate.com/api/models/stability-ai/stable-diffusion/files/50fcac81-865d-499e-81ac-49de0cb79264/out-0.png']
1920
```
2021

2122
Some models, like [replicate/resnet](/replicate/resnet), receive images as inputs. To pass a file as an input, use a file handle or URL
2223

2324
```python
2425
>>> model = replicate.models.get("replicate/resnet")
25-
>>> model.predict(image=open("mystery.jpg", "rb"))
26+
>>> version = model.versions.get("dd782a3d531b61af491d1026434392e8afb40bfb53b8af35f727e80661489767")
27+
>>> version.predict(image=open("mystery.jpg", "rb"))
2628
[['n02123597', 'Siamese_cat', 0.8829364776611328],
2729
['n02123394', 'Persian_cat', 0.09810526669025421],
2830
['n02123045', 'tabby', 0.005758069921284914]]
@@ -31,24 +33,28 @@ Some models, like [replicate/resnet](/replicate/resnet), receive images as input
3133
You can run a model and feed the output into another model:
3234

3335
```python
34-
>>> image = replicate.models.get("afiaka87/laionide-v4").predict(prompt="avocado armchair")
35-
>>> upscaled_image = replicate.models.get("jingyunliang/swinir").predict(image=image)
36+
>>> laionide = replicate.models.get("afiaka87/laionide-v4").versions.get("b21cbe271e65c1718f2999b038c18b45e21e4fba961181fbfae9342fc53b9e05")
37+
>>> swinir = replicate.models.get("jingyunliang/swinir").versions.get("660d922d33153019e8c263a3bba265de882e7f4f70396546b6c9c8f9d47a021a")
38+
>>> image = laionide.predict(prompt="avocado armchair")
39+
>>> upscaled_image = swinir.predict(image=image)
3640
```
3741

3842
Run a model and get its output while it's running:
3943

4044
```python
4145
model = replicate.models.get("pixray/text2image")
42-
for image in model.predict(prompts="san francisco sunset"):
46+
version = model.versions.get("5c347a4bfa1d4523a58ae614c2194e15f2ae682b57e3797a5bb468920aa70ebf")
47+
for image in version.predict(prompts="san francisco sunset"):
4348
display(image)
4449
```
4550

4651
You can start a model and run it in the background:
4752

4853
```python
4954
>>> model = replicate.models.get("kvfrans/clipdraw")
55+
>>> version = model.versions.get("5797a99edc939ea0e9242d5e8c9cb3bc7d125b1eac21bda852e5cb79ede2cd9b")
5056
>>> prediction = replicate.predictions.create(
51-
... version=model.versions.list()[0],
57+
... version=version,
5258
... input={"prompt":"Watercolor painting of an underwater submarine"})
5359

5460
>>> prediction
@@ -83,8 +89,9 @@ You can cancel a running prediction:
8389

8490
```python
8591
>>> model = replicate.models.get("kvfrans/clipdraw")
92+
>>> version = model.versions.get("5797a99edc939ea0e9242d5e8c9cb3bc7d125b1eac21bda852e5cb79ede2cd9b")
8693
>>> prediction = replicate.predictions.create(
87-
... version=model.versions.list()[0],
94+
... version=version,
8895
... input={"prompt":"Watercolor painting of an underwater submarine"})
8996

9097
>>> prediction.status
@@ -97,17 +104,6 @@ You can cancel a running prediction:
97104
'canceled'
98105
```
99106

100-
By default, `model.predict()` uses the latest version. If you're running a model in production, you should pin to a particular version to ensure its API or behavior doesn't change.
101-
102-
If you want to pin to a particular version, you can get a version with its ID, then call the `predict()` method on that version:
103-
104-
```
105-
>>> model = replicate.models.get("replicate/hello-world")
106-
>>> version = model.versions.get("5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa")
107-
>>> version.predict(text="python")
108-
"hello python"
109-
```
110-
111107
You can list all the predictions you've run:
112108

113109
```

0 commit comments

Comments
 (0)