Skip to content

Commit 1d45867

Browse files
authored
Merge branch 'next' into dp-671-add-deprecated-support-for-replicatestream-in-the-v2-python
2 parents 9b9d6b9 + d5ed889 commit 1d45867

18 files changed

+142
-58
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 36
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-87c7c57bd75c54990c679c9e87d009851cdff572815a55d1b6ee4d4ee20adaa1.yml
3-
openapi_spec_hash: d987f14befa536004eece7b49caad993
4-
config_hash: a916e7f3559ab312c7b6696cd6b35fb5
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-1029a7d9615d8a4fa72ca7bb2c0762d98cef9919c6f35079f87cc2db2b8ce9f5.yml
3+
openapi_spec_hash: f8b9ef3c211e9113e141f1894436eba6
4+
config_hash: 407acf62c906ee301314f2d23cdb58b1

scripts/bootstrap

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ set -e
44

55
cd "$(dirname "$0")/.."
66

7-
if ! command -v rye >/dev/null 2>&1 && [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then
7+
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] && [ -t 0 ]; then
88
brew bundle check >/dev/null 2>&1 || {
9-
echo "==> Installing Homebrew dependencies…"
10-
brew bundle
9+
echo -n "==> Install Homebrew dependencies? (y/N): "
10+
read -r response
11+
case "$response" in
12+
[yY][eE][sS]|[yY])
13+
brew bundle
14+
;;
15+
*)
16+
;;
17+
esac
18+
echo
1119
}
1220
fi
1321

src/replicate/_client.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from ._qs import Querystring
3030
from .types import client_search_params
3131
from ._types import (
32-
NOT_GIVEN,
3332
Body,
3433
Omit,
3534
Query,
@@ -39,6 +38,8 @@
3938
Transport,
4039
ProxiesTypes,
4140
RequestOptions,
41+
omit,
42+
not_given,
4243
)
4344
from ._utils import (
4445
is_given,
@@ -103,7 +104,7 @@ def __init__(
103104
*,
104105
bearer_token: str | None = None,
105106
base_url: str | httpx.URL | None = None,
106-
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
107+
timeout: float | Timeout | None | NotGiven = not_given,
107108
max_retries: int = DEFAULT_MAX_RETRIES,
108109
default_headers: Mapping[str, str] | None = None,
109110
default_query: Mapping[str, object] | None = None,
@@ -241,7 +242,7 @@ def run(
241242
*,
242243
file_encoding_strategy: Optional["FileEncodingStrategy"] = None,
243244
use_file_output: bool = True,
244-
wait: Union[int, bool, NotGiven] = NOT_GIVEN,
245+
wait: Union[int, bool, NotGiven] = not_given,
245246
**params: Unpack[PredictionCreateParamsWithoutVersion],
246247
) -> Any:
247248
"""
@@ -357,9 +358,9 @@ def copy(
357358
*,
358359
bearer_token: str | None = None,
359360
base_url: str | httpx.URL | None = None,
360-
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
361+
timeout: float | Timeout | None | NotGiven = not_given,
361362
http_client: httpx.Client | None = None,
362-
max_retries: int | NotGiven = NOT_GIVEN,
363+
max_retries: int | NotGiven = not_given,
363364
default_headers: Mapping[str, str] | None = None,
364365
set_default_headers: Mapping[str, str] | None = None,
365366
default_query: Mapping[str, object] | None = None,
@@ -407,13 +408,13 @@ def search(
407408
self,
408409
*,
409410
query: str,
410-
limit: int | NotGiven = NOT_GIVEN,
411+
limit: int | Omit = omit,
411412
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
412413
# The extra values given here take precedence over values defined on the client or passed to this method.
413414
extra_headers: Headers | None = None,
414415
extra_query: Query | None = None,
415416
extra_body: Body | None = None,
416-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
417+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
417418
) -> SearchResponse:
418419
"""
419420
Search for public models, collections, and docs using a text query.
@@ -510,7 +511,7 @@ def __init__(
510511
*,
511512
bearer_token: str | None = None,
512513
base_url: str | httpx.URL | None = None,
513-
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
514+
timeout: float | Timeout | None | NotGiven = not_given,
514515
max_retries: int = DEFAULT_MAX_RETRIES,
515516
default_headers: Mapping[str, str] | None = None,
516517
default_query: Mapping[str, object] | None = None,
@@ -648,7 +649,7 @@ async def run(
648649
*,
649650
use_file_output: bool = True,
650651
file_encoding_strategy: Optional["FileEncodingStrategy"] = None,
651-
wait: Union[int, bool, NotGiven] = NOT_GIVEN,
652+
wait: Union[int, bool, NotGiven] = not_given,
652653
**params: Unpack[PredictionCreateParamsWithoutVersion],
653654
) -> Any:
654655
"""
@@ -764,9 +765,9 @@ def copy(
764765
*,
765766
bearer_token: str | None = None,
766767
base_url: str | httpx.URL | None = None,
767-
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
768+
timeout: float | Timeout | None | NotGiven = not_given,
768769
http_client: httpx.AsyncClient | None = None,
769-
max_retries: int | NotGiven = NOT_GIVEN,
770+
max_retries: int | NotGiven = not_given,
770771
default_headers: Mapping[str, str] | None = None,
771772
set_default_headers: Mapping[str, str] | None = None,
772773
default_query: Mapping[str, object] | None = None,
@@ -814,13 +815,13 @@ async def search(
814815
self,
815816
*,
816817
query: str,
817-
limit: int | NotGiven = NOT_GIVEN,
818+
limit: int | Omit = omit,
818819
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
819820
# The extra values given here take precedence over values defined on the client or passed to this method.
820821
extra_headers: Headers | None = None,
821822
extra_query: Query | None = None,
822823
extra_body: Body | None = None,
823-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
824+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
824825
) -> SearchResponse:
825826
"""
826827
Search for public models, collections, and docs using a text query.

src/replicate/resources/deployments/predictions.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def create(
5454
webhook: str | Omit = omit,
5555
webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | Omit = omit,
5656
prefer: str | Omit = omit,
57+
replicate_max_lifetime: str | Omit = omit,
5758
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5859
# The extra values given here take precedence over values defined on the client or passed to this method.
5960
extra_headers: Headers | None = None,
@@ -111,7 +112,7 @@ def create(
111112
[server-sent events (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
112113
113114
This field is no longer needed as the returned prediction will always have a
114-
`stream` entry in its `url` property if the model supports streaming.
115+
`stream` entry in its `urls` property if the model supports streaming.
115116
116117
webhook: An HTTPS URL for receiving a webhook when the prediction has new output. The
117118
webhook will be a POST request where the request body is the same as the
@@ -162,7 +163,15 @@ def create(
162163
raise ValueError(f"Expected a non-empty value for `deployment_owner` but received {deployment_owner!r}")
163164
if not deployment_name:
164165
raise ValueError(f"Expected a non-empty value for `deployment_name` but received {deployment_name!r}")
165-
extra_headers = {**strip_not_given({"Prefer": prefer}), **(extra_headers or {})}
166+
extra_headers = {
167+
**strip_not_given(
168+
{
169+
"Prefer": prefer,
170+
"Replicate-Max-Lifetime": replicate_max_lifetime,
171+
}
172+
),
173+
**(extra_headers or {}),
174+
}
166175
return self._post(
167176
f"/deployments/{deployment_owner}/{deployment_name}/predictions",
168177
body=maybe_transform(
@@ -211,6 +220,7 @@ async def create(
211220
webhook: str | Omit = omit,
212221
webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | Omit = omit,
213222
prefer: str | Omit = omit,
223+
replicate_max_lifetime: str | Omit = omit,
214224
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
215225
# The extra values given here take precedence over values defined on the client or passed to this method.
216226
extra_headers: Headers | None = None,
@@ -268,7 +278,7 @@ async def create(
268278
[server-sent events (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
269279
270280
This field is no longer needed as the returned prediction will always have a
271-
`stream` entry in its `url` property if the model supports streaming.
281+
`stream` entry in its `urls` property if the model supports streaming.
272282
273283
webhook: An HTTPS URL for receiving a webhook when the prediction has new output. The
274284
webhook will be a POST request where the request body is the same as the
@@ -319,7 +329,15 @@ async def create(
319329
raise ValueError(f"Expected a non-empty value for `deployment_owner` but received {deployment_owner!r}")
320330
if not deployment_name:
321331
raise ValueError(f"Expected a non-empty value for `deployment_name` but received {deployment_name!r}")
322-
extra_headers = {**strip_not_given({"Prefer": prefer}), **(extra_headers or {})}
332+
extra_headers = {
333+
**strip_not_given(
334+
{
335+
"Prefer": prefer,
336+
"Replicate-Max-Lifetime": replicate_max_lifetime,
337+
}
338+
),
339+
**(extra_headers or {}),
340+
}
323341
return await self._post(
324342
f"/deployments/{deployment_owner}/{deployment_name}/predictions",
325343
body=await async_maybe_transform(

src/replicate/resources/models/predictions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def create(
118118
[server-sent events (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
119119
120120
This field is no longer needed as the returned prediction will always have a
121-
`stream` entry in its `url` property if the model supports streaming.
121+
`stream` entry in its `urls` property if the model supports streaming.
122122
123123
webhook: An HTTPS URL for receiving a webhook when the prediction has new output. The
124124
webhook will be a POST request where the request body is the same as the
@@ -280,7 +280,7 @@ async def create(
280280
[server-sent events (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
281281
282282
This field is no longer needed as the returned prediction will always have a
283-
`stream` entry in its `url` property if the model supports streaming.
283+
`stream` entry in its `urls` property if the model supports streaming.
284284
285285
webhook: An HTTPS URL for receiving a webhook when the prediction has new output. The
286286
webhook will be a POST request where the request body is the same as the

src/replicate/resources/predictions.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from replicate.lib._files import FileEncodingStrategy, encode_json, async_encode_json
1212

1313
from ..types import prediction_list_params, prediction_create_params
14-
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
14+
from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
1515
from .._utils import maybe_transform, strip_not_given, async_maybe_transform
1616
from .._compat import cached_property
1717
from .._resource import SyncAPIResource, AsyncAPIResource
@@ -63,17 +63,17 @@ def create(
6363
*,
6464
input: object,
6565
version: str,
66-
stream: bool | NotGiven = NOT_GIVEN,
67-
webhook: str | NotGiven = NOT_GIVEN,
68-
webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | NotGiven = NOT_GIVEN,
69-
prefer: str | NotGiven = NOT_GIVEN,
66+
stream: bool | Omit = omit,
67+
webhook: str | Omit = omit,
68+
webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | Omit = omit,
69+
prefer: str | Omit = omit,
7070
file_encoding_strategy: Optional["FileEncodingStrategy"] = None,
7171
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
7272
# The extra values given here take precedence over values defined on the client or passed to this method.
7373
extra_headers: Headers | None = None,
7474
extra_query: Query | None = None,
7575
extra_body: Body | None = None,
76-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
76+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
7777
) -> Prediction:
7878
"""
7979
Create a prediction for the model version and inputs you provide.
@@ -138,7 +138,7 @@ def create(
138138
[server-sent events (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
139139
140140
This field is no longer needed as the returned prediction will always have a
141-
`stream` entry in its `url` property if the model supports streaming.
141+
`stream` entry in its `urls` property if the model supports streaming.
142142
143143
webhook: An HTTPS URL for receiving a webhook when the prediction has new output. The
144144
webhook will be a POST request where the request body is the same as the
@@ -208,14 +208,14 @@ def create(
208208
def list(
209209
self,
210210
*,
211-
created_after: Union[str, datetime] | NotGiven = NOT_GIVEN,
212-
created_before: Union[str, datetime] | NotGiven = NOT_GIVEN,
211+
created_after: Union[str, datetime] | Omit = omit,
212+
created_before: Union[str, datetime] | Omit = omit,
213213
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
214214
# The extra values given here take precedence over values defined on the client or passed to this method.
215215
extra_headers: Headers | None = None,
216216
extra_query: Query | None = None,
217217
extra_body: Body | None = None,
218-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
218+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
219219
) -> SyncCursorURLPageWithCreatedFilters[Prediction]:
220220
"""
221221
Get a paginated list of all predictions created by the user or organization
@@ -330,7 +330,7 @@ def cancel(
330330
extra_headers: Headers | None = None,
331331
extra_query: Query | None = None,
332332
extra_body: Body | None = None,
333-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
333+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
334334
) -> Prediction:
335335
"""
336336
Cancel a prediction that is currently running.
@@ -386,7 +386,7 @@ def get(
386386
extra_headers: Headers | None = None,
387387
extra_query: Query | None = None,
388388
extra_body: Body | None = None,
389-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
389+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
390390
) -> Prediction:
391391
"""
392392
Get the current state of a prediction.
@@ -448,7 +448,9 @@ def get(
448448
Terminated predictions (with a status of `succeeded`, `failed`, or `canceled`)
449449
will include a `metrics` object with a `predict_time` property showing the
450450
amount of CPU or GPU time, in seconds, that the prediction used while running.
451-
It won't include time waiting for the prediction to start.
451+
It won't include time waiting for the prediction to start. The `metrics` object
452+
will also include a `total_time` property showing the total time, in seconds,
453+
that the prediction took to complete.
452454
453455
All input parameters, output values, and logs are automatically removed after an
454456
hour, by default, for predictions created through the API.
@@ -514,17 +516,17 @@ async def create(
514516
*,
515517
input: object,
516518
version: str,
517-
stream: bool | NotGiven = NOT_GIVEN,
518-
webhook: str | NotGiven = NOT_GIVEN,
519-
webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | NotGiven = NOT_GIVEN,
520-
prefer: str | NotGiven = NOT_GIVEN,
519+
stream: bool | Omit = omit,
520+
webhook: str | Omit = omit,
521+
webhook_events_filter: List[Literal["start", "output", "logs", "completed"]] | Omit = omit,
522+
prefer: str | Omit = omit,
521523
file_encoding_strategy: Optional["FileEncodingStrategy"] = None,
522524
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
523525
# The extra values given here take precedence over values defined on the client or passed to this method.
524526
extra_headers: Headers | None = None,
525527
extra_query: Query | None = None,
526528
extra_body: Body | None = None,
527-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
529+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
528530
) -> Prediction:
529531
"""
530532
Create a prediction for the model version and inputs you provide.
@@ -589,7 +591,7 @@ async def create(
589591
[server-sent events (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
590592
591593
This field is no longer needed as the returned prediction will always have a
592-
`stream` entry in its `url` property if the model supports streaming.
594+
`stream` entry in its `urls` property if the model supports streaming.
593595
594596
webhook: An HTTPS URL for receiving a webhook when the prediction has new output. The
595597
webhook will be a POST request where the request body is the same as the
@@ -661,14 +663,14 @@ async def create(
661663
def list(
662664
self,
663665
*,
664-
created_after: Union[str, datetime] | NotGiven = NOT_GIVEN,
665-
created_before: Union[str, datetime] | NotGiven = NOT_GIVEN,
666+
created_after: Union[str, datetime] | Omit = omit,
667+
created_before: Union[str, datetime] | Omit = omit,
666668
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
667669
# The extra values given here take precedence over values defined on the client or passed to this method.
668670
extra_headers: Headers | None = None,
669671
extra_query: Query | None = None,
670672
extra_body: Body | None = None,
671-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
673+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
672674
) -> AsyncPaginator[Prediction, AsyncCursorURLPageWithCreatedFilters[Prediction]]:
673675
"""
674676
Get a paginated list of all predictions created by the user or organization
@@ -783,7 +785,7 @@ async def cancel(
783785
extra_headers: Headers | None = None,
784786
extra_query: Query | None = None,
785787
extra_body: Body | None = None,
786-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
788+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
787789
) -> Prediction:
788790
"""
789791
Cancel a prediction that is currently running.
@@ -839,7 +841,7 @@ async def get(
839841
extra_headers: Headers | None = None,
840842
extra_query: Query | None = None,
841843
extra_body: Body | None = None,
842-
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
844+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
843845
) -> Prediction:
844846
"""
845847
Get the current state of a prediction.
@@ -901,7 +903,9 @@ async def get(
901903
Terminated predictions (with a status of `succeeded`, `failed`, or `canceled`)
902904
will include a `metrics` object with a `predict_time` property showing the
903905
amount of CPU or GPU time, in seconds, that the prediction used while running.
904-
It won't include time waiting for the prediction to start.
906+
It won't include time waiting for the prediction to start. The `metrics` object
907+
will also include a `total_time` property showing the total time, in seconds,
908+
that the prediction took to complete.
905909
906910
All input parameters, output values, and logs are automatically removed after an
907911
hour, by default, for predictions created through the API.

0 commit comments

Comments
 (0)