Skip to content

Commit 30225f4

Browse files
authored
Fix logic for preparing model with no default example (#162)
Resolves #161 (comment) Signed-off-by: Mattt Zmuda <[email protected]>
1 parent f890859 commit 30225f4

File tree

4 files changed

+1473
-1333
lines changed

4 files changed

+1473
-1333
lines changed

replicate/model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,13 @@ def prepare_model(self, attrs: Union[Model, Dict]) -> Model:
143143
attrs.id = f"{attrs.owner}/{attrs.name}"
144144
elif isinstance(attrs, dict):
145145
attrs["id"] = f"{attrs['owner']}/{attrs['name']}"
146-
attrs.get("default_example", {}).pop("version", None)
146+
147+
if attrs is not None:
148+
if "default_example" in attrs and attrs["default_example"]:
149+
attrs["default_example"].pop("version")
150+
151+
if "latest_version" in attrs and attrs["latest_version"] == {}:
152+
attrs.pop("latest_version")
147153

148154
model = super().prepare_model(attrs)
149155

tests/cassettes/test_models_get.yaml

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interactions:
1616
uri: https://api.replicate.com/v1/models/stability-ai/sdxl
1717
response:
1818
content: "{\"url\":\"https://replicate.com/stability-ai/sdxl\",\"owner\":\"stability-ai\",\"name\":\"sdxl\",\"description\":\"A
19-
text-to-image generative AI model that creates beautiful 1024x1024 images\",\"visibility\":\"public\",\"github_url\":\"https://github.com/replicate/cog-sdxl\",\"paper_url\":\"https://arxiv.org/abs/2307.01952\",\"license_url\":\"https://github.com/Stability-AI/generative-models/blob/main/model_licenses/LICENSE-SDXL1.0\",\"run_count\":6465507,\"cover_image_url\":\"https://tjzk.replicate.delivery/models_models_cover_image/61004930-fb88-4e09-9bd4-74fd8b4aa677/sdxl_cover.png\",\"default_example\":{\"completed_at\":\"2023-07-26T21:04:37.933562Z\",\"created_at\":\"2023-07-26T21:04:23.762683Z\",\"error\":null,\"id\":\"vu42q7dbkm6iicbpal4v6uvbqm\",\"input\":{\"width\":1024,\"height\":1024,\"prompt\":\"An
19+
text-to-image generative AI model that creates beautiful 1024x1024 images\",\"visibility\":\"public\",\"github_url\":\"https://github.com/replicate/cog-sdxl\",\"paper_url\":\"https://arxiv.org/abs/2307.01952\",\"license_url\":\"https://github.com/Stability-AI/generative-models/blob/main/model_licenses/LICENSE-SDXL1.0\",\"run_count\":6517655,\"cover_image_url\":\"https://tjzk.replicate.delivery/models_models_cover_image/61004930-fb88-4e09-9bd4-74fd8b4aa677/sdxl_cover.png\",\"default_example\":{\"completed_at\":\"2023-07-26T21:04:37.933562Z\",\"created_at\":\"2023-07-26T21:04:23.762683Z\",\"error\":null,\"id\":\"vu42q7dbkm6iicbpal4v6uvbqm\",\"input\":{\"width\":1024,\"height\":1024,\"prompt\":\"An
2020
astronaut riding a rainbow unicorn, cinematic, dramatic\",\"refine\":\"expert_ensemble_refiner\",\"scheduler\":\"DDIM\",\"num_outputs\":1,\"guidance_scale\":7.5,\"high_noise_frac\":0.8,\"prompt_strength\":0.8,\"num_inference_steps\":50},\"logs\":\"Using
2121
seed: 12103\\ntxt2img mode\\n 0%| | 0/40 [00:00<?, ?it/s]\\n 2%|\u258E
2222
\ | 1/40 [00:00<00:34, 1.14it/s]\\n 5%|\u258C | 2/40 [00:01<00:18,
@@ -126,15 +126,19 @@ interactions:
126126
CF-Cache-Status:
127127
- DYNAMIC
128128
CF-RAY:
129-
- 810c642d9b2127a1-SEA
129+
- 810dc917ae5730b2-SEA
130130
Connection:
131131
- keep-alive
132132
Content-Encoding:
133133
- gzip
134134
Content-Type:
135135
- application/json
136136
Date:
137-
- Wed, 04 Oct 2023 09:27:50 GMT
137+
- Wed, 04 Oct 2023 13:31:29 GMT
138+
NEL:
139+
- '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}'
140+
Report-To:
141+
- '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=2x%2FXmN26nRsy38iWuFuDrusfZvpPL4EGtLHKcR6FgmqkKmNlfy0XzmqlbVdC3RhSlvpDrSaVvX14t1R8Q22HLe69O7Oc9LsjUxDiQnZBLBsawHN8kLT9vWxvDZkB%2FzoEIIor"}],"group":"cf-nel","max_age":604800}'
138142
Server:
139143
- cloudflare
140144
Strict-Transport-Security:
@@ -145,14 +149,80 @@ interactions:
145149
- GET, HEAD, OPTIONS
146150
content-security-policy-report-only:
147151
- 'script-src ''report-sample'' ''self'' https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js;
148-
default-src ''self''; style-src ''report-sample'' ''self'' ''unsafe-inline'';
149-
font-src ''report-sample'' ''self'' data:; connect-src ''report-sample'' ''self''
150-
https://replicate.delivery https://*.replicate.delivery https://*.rudderlabs.com
151-
https://*.rudderstack.com https://*.mux.com https://*.sentry.io; media-src
152-
''report-sample'' ''self'' https://replicate.delivery https://*.replicate.delivery
153-
https://*.mux.com https://*.sentry.io; worker-src ''none''; img-src ''report-sample''
154-
''self'' data: https://replicate.delivery https://*.replicate.delivery https://*.githubusercontent.com
155-
https://github.com; report-uri'
152+
style-src ''report-sample'' ''self'' ''unsafe-inline''; worker-src ''none'';
153+
connect-src ''report-sample'' ''self'' https://replicate.delivery https://*.replicate.delivery
154+
https://*.rudderlabs.com https://*.rudderstack.com https://*.mux.com https://*.sentry.io;
155+
default-src ''self''; img-src ''report-sample'' ''self'' data: https://replicate.delivery
156+
https://*.replicate.delivery https://*.githubusercontent.com https://github.com;
157+
media-src ''report-sample'' ''self'' https://replicate.delivery https://*.replicate.delivery
158+
https://*.mux.com https://*.sentry.io; font-src ''report-sample'' ''self''
159+
data:; report-uri'
160+
cross-origin-opener-policy:
161+
- same-origin
162+
ratelimit-remaining:
163+
- '2999'
164+
ratelimit-reset:
165+
- '1'
166+
referrer-policy:
167+
- same-origin
168+
vary:
169+
- Cookie, origin
170+
via:
171+
- 1.1 vegur, 1.1 google
172+
x-content-type-options:
173+
- nosniff
174+
x-frame-options:
175+
- DENY
176+
http_version: HTTP/1.1
177+
status_code: 200
178+
- request:
179+
body: ''
180+
headers:
181+
accept:
182+
- '*/*'
183+
accept-encoding:
184+
- gzip, deflate
185+
connection:
186+
- keep-alive
187+
host:
188+
- api.replicate.com
189+
user-agent:
190+
- replicate-python/0.13.0
191+
method: GET
192+
uri: https://api.replicate.com/v1/models/mattt/empty
193+
response:
194+
content: '{"url":"https://replicate.com/mattt/empty","owner":"mattt","name":"empty","description":null,"visibility":"public","github_url":null,"paper_url":null,"license_url":null,"run_count":0,"cover_image_url":null,"default_example":null,"latest_version":{}}'
195+
headers:
196+
CF-Cache-Status:
197+
- DYNAMIC
198+
CF-RAY:
199+
- 810dc9188f8930b2-SEA
200+
Connection:
201+
- keep-alive
202+
Content-Encoding:
203+
- gzip
204+
Content-Type:
205+
- application/json
206+
Date:
207+
- Wed, 04 Oct 2023 13:31:30 GMT
208+
Server:
209+
- cloudflare
210+
Strict-Transport-Security:
211+
- max-age=15552000
212+
Transfer-Encoding:
213+
- chunked
214+
allow:
215+
- GET, HEAD, OPTIONS
216+
content-security-policy-report-only:
217+
- 'script-src ''report-sample'' ''self'' https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js;
218+
img-src ''report-sample'' ''self'' data: https://replicate.delivery https://*.replicate.delivery
219+
https://*.githubusercontent.com https://github.com; font-src ''report-sample''
220+
''self'' data:; connect-src ''report-sample'' ''self'' https://replicate.delivery
221+
https://*.replicate.delivery https://*.rudderlabs.com https://*.rudderstack.com
222+
https://*.mux.com https://*.sentry.io; default-src ''self''; worker-src ''none'';
223+
style-src ''report-sample'' ''self'' ''unsafe-inline''; media-src ''report-sample''
224+
''self'' https://replicate.delivery https://*.replicate.delivery https://*.mux.com
225+
https://*.sentry.io; report-uri'
156226
cross-origin-opener-policy:
157227
- same-origin
158228
nel:
@@ -164,9 +234,9 @@ interactions:
164234
referrer-policy:
165235
- same-origin
166236
report-to:
167-
- '{"group":"heroku-nel","max_age":3600,"endpoints":[{"url":"https://nel.heroku.com/reports?ts=1696411670&sid=1b10b0ff-8a76-4548-befa-353fc6c6c045&s=hew4kkx7a9xsK1vI5SagVT8O9LLd7o1QNMpC%2B35Z5Js%3D"}]}'
237+
- '{"group":"heroku-nel","max_age":3600,"endpoints":[{"url":"https://nel.heroku.com/reports?ts=1696426290&sid=1b10b0ff-8a76-4548-befa-353fc6c6c045&s=gGrMFvEMSiSF9uc0VwymrNEX38nLOLRF%2F2kYd8NuGOw%3D"}]}'
168238
reporting-endpoints:
169-
- heroku-nel=https://nel.heroku.com/reports?ts=1696411670&sid=1b10b0ff-8a76-4548-befa-353fc6c6c045&s=hew4kkx7a9xsK1vI5SagVT8O9LLd7o1QNMpC%2B35Z5Js%3D
239+
- heroku-nel=https://nel.heroku.com/reports?ts=1696426290&sid=1b10b0ff-8a76-4548-befa-353fc6c6c045&s=gGrMFvEMSiSF9uc0VwymrNEX38nLOLRF%2F2kYd8NuGOw%3D
170240
vary:
171241
- Cookie, origin
172242
via:

0 commit comments

Comments
 (0)