Skip to content

Commit 3e807ea

Browse files
feat(api): add models.update() operation
1 parent 1c5a2f3 commit 3e807ea

File tree

7 files changed

+425
-3
lines changed

7 files changed

+425
-3
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 36
1+
configured_endpoints: 37
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-7a537f433b0b71a42a3d53ce6182cc06790157bbb379461eed93cdb68659bc92.yml
33
openapi_spec_hash: 5c7633dce3ece58e21f74d826946914c
4-
config_hash: 407acf62c906ee301314f2d23cdb58b1
4+
config_hash: 2c7c9d1642de34f563e0774bb1cd0ff0

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Types:
8181
```python
8282
from replicate.types import (
8383
ModelCreateResponse,
84+
ModelUpdateResponse,
8485
ModelListResponse,
8586
ModelGetResponse,
8687
ModelSearchResponse,
@@ -90,6 +91,7 @@ from replicate.types import (
9091
Methods:
9192

9293
- <code title="post /models">replicate.models.<a href="./src/replicate/resources/models/models.py">create</a>(\*\*<a href="src/replicate/types/model_create_params.py">params</a>) -> <a href="./src/replicate/types/model_create_response.py">ModelCreateResponse</a></code>
94+
- <code title="patch /models/{model_owner}/{model_name}">replicate.models.<a href="./src/replicate/resources/models/models.py">update</a>(\*, model_owner, model_name, \*\*<a href="src/replicate/types/model_update_params.py">params</a>) -> <a href="./src/replicate/types/model_update_response.py">ModelUpdateResponse</a></code>
9395
- <code title="get /models">replicate.models.<a href="./src/replicate/resources/models/models.py">list</a>(\*\*<a href="src/replicate/types/model_list_params.py">params</a>) -> <a href="./src/replicate/types/model_list_response.py">SyncCursorURLPage[ModelListResponse]</a></code>
9496
- <code title="delete /models/{model_owner}/{model_name}">replicate.models.<a href="./src/replicate/resources/models/models.py">delete</a>(\*, model_owner, model_name) -> None</code>
9597
- <code title="get /models/{model_owner}/{model_name}">replicate.models.<a href="./src/replicate/resources/models/models.py">get</a>(\*, model_owner, model_name) -> <a href="./src/replicate/types/model_get_response.py">ModelGetResponse</a></code>

src/replicate/resources/models/models.py

Lines changed: 200 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ReadmeResourceWithStreamingResponse,
1515
AsyncReadmeResourceWithStreamingResponse,
1616
)
17-
from ...types import model_list_params, model_create_params, model_search_params
17+
from ...types import model_list_params, model_create_params, model_search_params, model_update_params
1818
from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given
1919
from ..._utils import maybe_transform, async_maybe_transform
2020
from .examples import (
@@ -55,6 +55,7 @@
5555
from ...types.model_list_response import ModelListResponse
5656
from ...types.model_create_response import ModelCreateResponse
5757
from ...types.model_search_response import ModelSearchResponse
58+
from ...types.model_update_response import ModelUpdateResponse
5859

5960
__all__ = ["ModelsResource", "AsyncModelsResource"]
6061

@@ -206,6 +207,99 @@ def create(
206207
cast_to=ModelCreateResponse,
207208
)
208209

210+
def update(
211+
self,
212+
*,
213+
model_owner: str,
214+
model_name: str,
215+
description: str | Omit = omit,
216+
github_url: str | Omit = omit,
217+
license_url: str | Omit = omit,
218+
paper_url: str | Omit = omit,
219+
readme: str | Omit = omit,
220+
weights_url: str | Omit = omit,
221+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
222+
# The extra values given here take precedence over values defined on the client or passed to this method.
223+
extra_headers: Headers | None = None,
224+
extra_query: Query | None = None,
225+
extra_body: Body | None = None,
226+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
227+
) -> ModelUpdateResponse:
228+
"""
229+
Update select properties of an existing model.
230+
231+
You can update the following properties:
232+
233+
- `description` - Model description
234+
- `readme` - Model README content
235+
- `github_url` - GitHub repository URL
236+
- `paper_url` - Research paper URL
237+
- `weights_url` - Model weights URL
238+
- `license_url` - License URL
239+
240+
Example cURL request:
241+
242+
```console
243+
curl -X PATCH \\
244+
https://api.replicate.com/v1/models/your-username/your-model-name \\
245+
-H "Authorization: Token $REPLICATE_API_TOKEN" \\
246+
-H "Content-Type: application/json" \\
247+
-d '{
248+
"description": "Detect hot dogs in images",
249+
"readme": "# Hot Dog Detector\n\n🌭 Ketchup, mustard, and onions...",
250+
"github_url": "https://github.com/alice/hot-dog-detector",
251+
"paper_url": "https://arxiv.org/abs/2504.17639",
252+
"weights_url": "https://huggingface.co/alice/hot-dog-detector",
253+
"license_url": "https://choosealicense.com/licenses/mit/"
254+
}'
255+
```
256+
257+
The response will be the updated model object with all of its properties.
258+
259+
Args:
260+
description: A description of the model.
261+
262+
github_url: A URL for the model's source code on GitHub.
263+
264+
license_url: A URL for the model's license.
265+
266+
paper_url: A URL for the model's paper.
267+
268+
readme: The README content of the model.
269+
270+
weights_url: A URL for the model's weights.
271+
272+
extra_headers: Send extra headers
273+
274+
extra_query: Add additional query parameters to the request
275+
276+
extra_body: Add additional JSON properties to the request
277+
278+
timeout: Override the client-level default timeout for this request, in seconds
279+
"""
280+
if not model_owner:
281+
raise ValueError(f"Expected a non-empty value for `model_owner` but received {model_owner!r}")
282+
if not model_name:
283+
raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}")
284+
return self._patch(
285+
f"/models/{model_owner}/{model_name}",
286+
body=maybe_transform(
287+
{
288+
"description": description,
289+
"github_url": github_url,
290+
"license_url": license_url,
291+
"paper_url": paper_url,
292+
"readme": readme,
293+
"weights_url": weights_url,
294+
},
295+
model_update_params.ModelUpdateParams,
296+
),
297+
options=make_request_options(
298+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
299+
),
300+
cast_to=ModelUpdateResponse,
301+
)
302+
209303
def list(
210304
self,
211305
*,
@@ -651,6 +745,99 @@ async def create(
651745
cast_to=ModelCreateResponse,
652746
)
653747

748+
async def update(
749+
self,
750+
*,
751+
model_owner: str,
752+
model_name: str,
753+
description: str | Omit = omit,
754+
github_url: str | Omit = omit,
755+
license_url: str | Omit = omit,
756+
paper_url: str | Omit = omit,
757+
readme: str | Omit = omit,
758+
weights_url: str | Omit = omit,
759+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
760+
# The extra values given here take precedence over values defined on the client or passed to this method.
761+
extra_headers: Headers | None = None,
762+
extra_query: Query | None = None,
763+
extra_body: Body | None = None,
764+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
765+
) -> ModelUpdateResponse:
766+
"""
767+
Update select properties of an existing model.
768+
769+
You can update the following properties:
770+
771+
- `description` - Model description
772+
- `readme` - Model README content
773+
- `github_url` - GitHub repository URL
774+
- `paper_url` - Research paper URL
775+
- `weights_url` - Model weights URL
776+
- `license_url` - License URL
777+
778+
Example cURL request:
779+
780+
```console
781+
curl -X PATCH \\
782+
https://api.replicate.com/v1/models/your-username/your-model-name \\
783+
-H "Authorization: Token $REPLICATE_API_TOKEN" \\
784+
-H "Content-Type: application/json" \\
785+
-d '{
786+
"description": "Detect hot dogs in images",
787+
"readme": "# Hot Dog Detector\n\n🌭 Ketchup, mustard, and onions...",
788+
"github_url": "https://github.com/alice/hot-dog-detector",
789+
"paper_url": "https://arxiv.org/abs/2504.17639",
790+
"weights_url": "https://huggingface.co/alice/hot-dog-detector",
791+
"license_url": "https://choosealicense.com/licenses/mit/"
792+
}'
793+
```
794+
795+
The response will be the updated model object with all of its properties.
796+
797+
Args:
798+
description: A description of the model.
799+
800+
github_url: A URL for the model's source code on GitHub.
801+
802+
license_url: A URL for the model's license.
803+
804+
paper_url: A URL for the model's paper.
805+
806+
readme: The README content of the model.
807+
808+
weights_url: A URL for the model's weights.
809+
810+
extra_headers: Send extra headers
811+
812+
extra_query: Add additional query parameters to the request
813+
814+
extra_body: Add additional JSON properties to the request
815+
816+
timeout: Override the client-level default timeout for this request, in seconds
817+
"""
818+
if not model_owner:
819+
raise ValueError(f"Expected a non-empty value for `model_owner` but received {model_owner!r}")
820+
if not model_name:
821+
raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}")
822+
return await self._patch(
823+
f"/models/{model_owner}/{model_name}",
824+
body=await async_maybe_transform(
825+
{
826+
"description": description,
827+
"github_url": github_url,
828+
"license_url": license_url,
829+
"paper_url": paper_url,
830+
"readme": readme,
831+
"weights_url": weights_url,
832+
},
833+
model_update_params.ModelUpdateParams,
834+
),
835+
options=make_request_options(
836+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
837+
),
838+
cast_to=ModelUpdateResponse,
839+
)
840+
654841
def list(
655842
self,
656843
*,
@@ -956,6 +1143,9 @@ def __init__(self, models: ModelsResource) -> None:
9561143
self.create = to_raw_response_wrapper(
9571144
models.create,
9581145
)
1146+
self.update = to_raw_response_wrapper(
1147+
models.update,
1148+
)
9591149
self.list = to_raw_response_wrapper(
9601150
models.list,
9611151
)
@@ -993,6 +1183,9 @@ def __init__(self, models: AsyncModelsResource) -> None:
9931183
self.create = async_to_raw_response_wrapper(
9941184
models.create,
9951185
)
1186+
self.update = async_to_raw_response_wrapper(
1187+
models.update,
1188+
)
9961189
self.list = async_to_raw_response_wrapper(
9971190
models.list,
9981191
)
@@ -1030,6 +1223,9 @@ def __init__(self, models: ModelsResource) -> None:
10301223
self.create = to_streamed_response_wrapper(
10311224
models.create,
10321225
)
1226+
self.update = to_streamed_response_wrapper(
1227+
models.update,
1228+
)
10331229
self.list = to_streamed_response_wrapper(
10341230
models.list,
10351231
)
@@ -1067,6 +1263,9 @@ def __init__(self, models: AsyncModelsResource) -> None:
10671263
self.create = async_to_streamed_response_wrapper(
10681264
models.create,
10691265
)
1266+
self.update = async_to_streamed_response_wrapper(
1267+
models.update,
1268+
)
10701269
self.list = async_to_streamed_response_wrapper(
10711270
models.list,
10721271
)

src/replicate/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
from .model_create_params import ModelCreateParams as ModelCreateParams
1313
from .model_list_response import ModelListResponse as ModelListResponse
1414
from .model_search_params import ModelSearchParams as ModelSearchParams
15+
from .model_update_params import ModelUpdateParams as ModelUpdateParams
1516
from .account_get_response import AccountGetResponse as AccountGetResponse
1617
from .client_search_params import ClientSearchParams as ClientSearchParams
1718
from .file_create_response import FileCreateResponse as FileCreateResponse
1819
from .file_download_params import FileDownloadParams as FileDownloadParams
1920
from .model_create_response import ModelCreateResponse as ModelCreateResponse
2021
from .model_search_response import ModelSearchResponse as ModelSearchResponse
22+
from .model_update_response import ModelUpdateResponse as ModelUpdateResponse
2123
from .training_get_response import TrainingGetResponse as TrainingGetResponse
2224
from .hardware_list_response import HardwareListResponse as HardwareListResponse
2325
from .prediction_list_params import PredictionListParams as PredictionListParams
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Required, TypedDict
6+
7+
__all__ = ["ModelUpdateParams"]
8+
9+
10+
class ModelUpdateParams(TypedDict, total=False):
11+
model_owner: Required[str]
12+
13+
model_name: Required[str]
14+
15+
description: str
16+
"""A description of the model."""
17+
18+
github_url: str
19+
"""A URL for the model's source code on GitHub."""
20+
21+
license_url: str
22+
"""A URL for the model's license."""
23+
24+
paper_url: str
25+
"""A URL for the model's paper."""
26+
27+
readme: str
28+
"""The README content of the model."""
29+
30+
weights_url: str
31+
"""A URL for the model's weights."""
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Optional
4+
from typing_extensions import Literal
5+
6+
from .._models import BaseModel
7+
8+
__all__ = ["ModelUpdateResponse"]
9+
10+
11+
class ModelUpdateResponse(BaseModel):
12+
cover_image_url: Optional[str] = None
13+
"""A URL for the model's cover image"""
14+
15+
default_example: Optional[object] = None
16+
"""The model's default example prediction"""
17+
18+
description: Optional[str] = None
19+
"""A description of the model"""
20+
21+
github_url: Optional[str] = None
22+
"""A URL for the model's source code on GitHub"""
23+
24+
is_official: Optional[bool] = None
25+
"""Boolean indicating whether the model is officially maintained by Replicate.
26+
27+
Official models are always on, have stable API interfaces, and predictable
28+
pricing.
29+
"""
30+
31+
latest_version: Optional[object] = None
32+
"""The model's latest version"""
33+
34+
license_url: Optional[str] = None
35+
"""A URL for the model's license"""
36+
37+
name: Optional[str] = None
38+
"""The name of the model"""
39+
40+
owner: Optional[str] = None
41+
"""The name of the user or organization that owns the model"""
42+
43+
paper_url: Optional[str] = None
44+
"""A URL for the model's paper"""
45+
46+
run_count: Optional[int] = None
47+
"""The number of times the model has been run"""
48+
49+
url: Optional[str] = None
50+
"""The URL of the model on Replicate"""
51+
52+
visibility: Optional[Literal["public", "private"]] = None
53+
"""Whether the model is public or private"""

0 commit comments

Comments
 (0)