Skip to content

Fix logic for preparing model with no default example #162

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

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion replicate/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ def prepare_model(self, attrs: Union[Model, Dict]) -> Model:
attrs.id = f"{attrs.owner}/{attrs.name}"
elif isinstance(attrs, dict):
attrs["id"] = f"{attrs['owner']}/{attrs['name']}"
attrs.get("default_example", {}).pop("version", None)

if attrs is not None:
if "default_example" in attrs and attrs["default_example"]:
attrs["default_example"].pop("version")

if "latest_version" in attrs and attrs["latest_version"] == {}:
attrs.pop("latest_version")

model = super().prepare_model(attrs)

Expand Down
96 changes: 83 additions & 13 deletions tests/cassettes/test_models_get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interactions:
uri: https://api.replicate.com/v1/models/stability-ai/sdxl
response:
content: "{\"url\":\"https://replicate.com/stability-ai/sdxl\",\"owner\":\"stability-ai\",\"name\":\"sdxl\",\"description\":\"A
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
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
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
seed: 12103\\ntxt2img mode\\n 0%| | 0/40 [00:00<?, ?it/s]\\n 2%|\u258E
\ | 1/40 [00:00<00:34, 1.14it/s]\\n 5%|\u258C | 2/40 [00:01<00:18,
Expand Down Expand Up @@ -126,15 +126,19 @@ interactions:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 810c642d9b2127a1-SEA
- 810dc917ae5730b2-SEA
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Wed, 04 Oct 2023 09:27:50 GMT
- Wed, 04 Oct 2023 13:31:29 GMT
NEL:
- '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}'
Report-To:
- '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=2x%2FXmN26nRsy38iWuFuDrusfZvpPL4EGtLHKcR6FgmqkKmNlfy0XzmqlbVdC3RhSlvpDrSaVvX14t1R8Q22HLe69O7Oc9LsjUxDiQnZBLBsawHN8kLT9vWxvDZkB%2FzoEIIor"}],"group":"cf-nel","max_age":604800}'
Server:
- cloudflare
Strict-Transport-Security:
Expand All @@ -145,14 +149,80 @@ interactions:
- GET, HEAD, OPTIONS
content-security-policy-report-only:
- 'script-src ''report-sample'' ''self'' https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js;
default-src ''self''; style-src ''report-sample'' ''self'' ''unsafe-inline'';
font-src ''report-sample'' ''self'' data:; connect-src ''report-sample'' ''self''
https://replicate.delivery https://*.replicate.delivery https://*.rudderlabs.com
https://*.rudderstack.com https://*.mux.com https://*.sentry.io; media-src
''report-sample'' ''self'' https://replicate.delivery https://*.replicate.delivery
https://*.mux.com https://*.sentry.io; worker-src ''none''; img-src ''report-sample''
''self'' data: https://replicate.delivery https://*.replicate.delivery https://*.githubusercontent.com
https://github.com; report-uri'
style-src ''report-sample'' ''self'' ''unsafe-inline''; worker-src ''none'';
connect-src ''report-sample'' ''self'' https://replicate.delivery https://*.replicate.delivery
https://*.rudderlabs.com https://*.rudderstack.com https://*.mux.com https://*.sentry.io;
default-src ''self''; img-src ''report-sample'' ''self'' data: https://replicate.delivery
https://*.replicate.delivery https://*.githubusercontent.com https://github.com;
media-src ''report-sample'' ''self'' https://replicate.delivery https://*.replicate.delivery
https://*.mux.com https://*.sentry.io; font-src ''report-sample'' ''self''
data:; report-uri'
cross-origin-opener-policy:
- same-origin
ratelimit-remaining:
- '2999'
ratelimit-reset:
- '1'
referrer-policy:
- same-origin
vary:
- Cookie, origin
via:
- 1.1 vegur, 1.1 google
x-content-type-options:
- nosniff
x-frame-options:
- DENY
http_version: HTTP/1.1
status_code: 200
- request:
body: ''
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
host:
- api.replicate.com
user-agent:
- replicate-python/0.13.0
method: GET
uri: https://api.replicate.com/v1/models/mattt/empty
response:
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":{}}'
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 810dc9188f8930b2-SEA
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Wed, 04 Oct 2023 13:31:30 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15552000
Transfer-Encoding:
- chunked
allow:
- GET, HEAD, OPTIONS
content-security-policy-report-only:
- 'script-src ''report-sample'' ''self'' https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js;
img-src ''report-sample'' ''self'' data: https://replicate.delivery https://*.replicate.delivery
https://*.githubusercontent.com https://github.com; font-src ''report-sample''
''self'' data:; connect-src ''report-sample'' ''self'' https://replicate.delivery
https://*.replicate.delivery https://*.rudderlabs.com https://*.rudderstack.com
https://*.mux.com https://*.sentry.io; default-src ''self''; worker-src ''none'';
style-src ''report-sample'' ''self'' ''unsafe-inline''; media-src ''report-sample''
''self'' https://replicate.delivery https://*.replicate.delivery https://*.mux.com
https://*.sentry.io; report-uri'
cross-origin-opener-policy:
- same-origin
nel:
Expand All @@ -164,9 +234,9 @@ interactions:
referrer-policy:
- same-origin
report-to:
- '{"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"}]}'
- '{"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"}]}'
reporting-endpoints:
- heroku-nel=https://nel.heroku.com/reports?ts=1696411670&sid=1b10b0ff-8a76-4548-befa-353fc6c6c045&s=hew4kkx7a9xsK1vI5SagVT8O9LLd7o1QNMpC%2B35Z5Js%3D
- heroku-nel=https://nel.heroku.com/reports?ts=1696426290&sid=1b10b0ff-8a76-4548-befa-353fc6c6c045&s=gGrMFvEMSiSF9uc0VwymrNEX38nLOLRF%2F2kYd8NuGOw%3D
vary:
- Cookie, origin
via:
Expand Down
Loading