Skip to content

Commit 0e4a103

Browse files
feat(api): api update
1 parent dadf411 commit 0e4a103

File tree

4 files changed

+62
-18
lines changed

4 files changed

+62
-18
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 35
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-efbc8cc2d74644b213e161d3e11e0589d1cef181fb318ea02c8eb6b00f245713.yml
3-
openapi_spec_hash: 13da0c06c900b61cd98ab678e024987a
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-88cf5fe1f5accb56ae9fbb31c0df00d1552762d4c558d16d8547894ae95e8ccb.yml
3+
openapi_spec_hash: 43283d20f335a04241cce165452ff50e
44
config_hash: 84794ed69d841684ff08a8aa889ef103

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Methods:
116116

117117
- <code title="post /predictions">client.predictions.<a href="./src/replicate/resources/predictions.py">create</a>(\*\*<a href="src/replicate/types/prediction_create_params.py">params</a>) -> <a href="./src/replicate/types/prediction.py">Prediction</a></code>
118118
- <code title="get /predictions">client.predictions.<a href="./src/replicate/resources/predictions.py">list</a>(\*\*<a href="src/replicate/types/prediction_list_params.py">params</a>) -> <a href="./src/replicate/types/prediction.py">SyncCursorURLPageWithCreatedFilters[Prediction]</a></code>
119-
- <code title="post /predictions/{prediction_id}/cancel">client.predictions.<a href="./src/replicate/resources/predictions.py">cancel</a>(\*, prediction_id) -> None</code>
119+
- <code title="post /predictions/{prediction_id}/cancel">client.predictions.<a href="./src/replicate/resources/predictions.py">cancel</a>(\*, prediction_id) -> <a href="./src/replicate/types/prediction.py">Prediction</a></code>
120120
- <code title="get /predictions/{prediction_id}">client.predictions.<a href="./src/replicate/resources/predictions.py">get</a>(\*, prediction_id) -> <a href="./src/replicate/types/prediction.py">Prediction</a></code>
121121

122122
# Trainings

src/replicate/resources/predictions.py

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import httpx
1010

1111
from ..types import prediction_list_params, prediction_create_params
12-
from .._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
12+
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
1313
from .._utils import maybe_transform, strip_not_given, async_maybe_transform
1414
from .._compat import cached_property
1515
from .._resource import SyncAPIResource, AsyncAPIResource
@@ -317,9 +317,32 @@ def cancel(
317317
extra_query: Query | None = None,
318318
extra_body: Body | None = None,
319319
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
320-
) -> None:
320+
) -> Prediction:
321321
"""
322-
Cancel a prediction
322+
Cancel a prediction that is currently running.
323+
324+
Example cURL request that creates a prediction and then cancels it:
325+
326+
```console
327+
# First, create a prediction
328+
PREDICTION_ID=$(curl -s -X POST \\
329+
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
330+
-H "Content-Type: application/json" \\
331+
-d '{
332+
"input": {
333+
"prompt": "a video that may take a while to generate"
334+
}
335+
}' \\
336+
https://api.replicate.com/v1/models/minimax/video-01/predictions | jq -r '.id')
337+
338+
# Echo the prediction ID
339+
echo "Created prediction with ID: $PREDICTION_ID"
340+
341+
# Cancel the prediction
342+
curl -s -X POST \\
343+
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
344+
https://api.replicate.com/v1/predictions/$PREDICTION_ID/cancel
345+
```
323346
324347
Args:
325348
extra_headers: Send extra headers
@@ -332,13 +355,12 @@ def cancel(
332355
"""
333356
if not prediction_id:
334357
raise ValueError(f"Expected a non-empty value for `prediction_id` but received {prediction_id!r}")
335-
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
336358
return self._post(
337359
f"/predictions/{prediction_id}/cancel",
338360
options=make_request_options(
339361
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
340362
),
341-
cast_to=NoneType,
363+
cast_to=Prediction,
342364
)
343365

344366
def get(
@@ -735,9 +757,32 @@ async def cancel(
735757
extra_query: Query | None = None,
736758
extra_body: Body | None = None,
737759
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
738-
) -> None:
760+
) -> Prediction:
739761
"""
740-
Cancel a prediction
762+
Cancel a prediction that is currently running.
763+
764+
Example cURL request that creates a prediction and then cancels it:
765+
766+
```console
767+
# First, create a prediction
768+
PREDICTION_ID=$(curl -s -X POST \\
769+
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
770+
-H "Content-Type: application/json" \\
771+
-d '{
772+
"input": {
773+
"prompt": "a video that may take a while to generate"
774+
}
775+
}' \\
776+
https://api.replicate.com/v1/models/minimax/video-01/predictions | jq -r '.id')
777+
778+
# Echo the prediction ID
779+
echo "Created prediction with ID: $PREDICTION_ID"
780+
781+
# Cancel the prediction
782+
curl -s -X POST \\
783+
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
784+
https://api.replicate.com/v1/predictions/$PREDICTION_ID/cancel
785+
```
741786
742787
Args:
743788
extra_headers: Send extra headers
@@ -750,13 +795,12 @@ async def cancel(
750795
"""
751796
if not prediction_id:
752797
raise ValueError(f"Expected a non-empty value for `prediction_id` but received {prediction_id!r}")
753-
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
754798
return await self._post(
755799
f"/predictions/{prediction_id}/cancel",
756800
options=make_request_options(
757801
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
758802
),
759-
cast_to=NoneType,
803+
cast_to=Prediction,
760804
)
761805

762806
async def get(

tests/api_resources/test_predictions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_method_cancel(self, client: Replicate) -> None:
112112
prediction = client.predictions.cancel(
113113
prediction_id="prediction_id",
114114
)
115-
assert prediction is None
115+
assert_matches_type(Prediction, prediction, path=["response"])
116116

117117
@pytest.mark.skip()
118118
@parametrize
@@ -124,7 +124,7 @@ def test_raw_response_cancel(self, client: Replicate) -> None:
124124
assert response.is_closed is True
125125
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
126126
prediction = response.parse()
127-
assert prediction is None
127+
assert_matches_type(Prediction, prediction, path=["response"])
128128

129129
@pytest.mark.skip()
130130
@parametrize
@@ -136,7 +136,7 @@ def test_streaming_response_cancel(self, client: Replicate) -> None:
136136
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
137137

138138
prediction = response.parse()
139-
assert prediction is None
139+
assert_matches_type(Prediction, prediction, path=["response"])
140140

141141
assert cast(Any, response.is_closed) is True
142142

@@ -287,7 +287,7 @@ async def test_method_cancel(self, async_client: AsyncReplicate) -> None:
287287
prediction = await async_client.predictions.cancel(
288288
prediction_id="prediction_id",
289289
)
290-
assert prediction is None
290+
assert_matches_type(Prediction, prediction, path=["response"])
291291

292292
@pytest.mark.skip()
293293
@parametrize
@@ -299,7 +299,7 @@ async def test_raw_response_cancel(self, async_client: AsyncReplicate) -> None:
299299
assert response.is_closed is True
300300
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
301301
prediction = await response.parse()
302-
assert prediction is None
302+
assert_matches_type(Prediction, prediction, path=["response"])
303303

304304
@pytest.mark.skip()
305305
@parametrize
@@ -311,7 +311,7 @@ async def test_streaming_response_cancel(self, async_client: AsyncReplicate) ->
311311
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
312312

313313
prediction = await response.parse()
314-
assert prediction is None
314+
assert_matches_type(Prediction, prediction, path=["response"])
315315

316316
assert cast(Any, response.is_closed) is True
317317

0 commit comments

Comments
 (0)