|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import httpx |
| 6 | + |
| 7 | +from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven |
| 8 | +from ..._compat import cached_property |
| 9 | +from ..._resource import SyncAPIResource, AsyncAPIResource |
| 10 | +from ..._response import ( |
| 11 | + to_raw_response_wrapper, |
| 12 | + to_streamed_response_wrapper, |
| 13 | + async_to_raw_response_wrapper, |
| 14 | + async_to_streamed_response_wrapper, |
| 15 | +) |
| 16 | +from ..._base_client import make_request_options |
| 17 | + |
| 18 | +__all__ = ["ExamplesResource", "AsyncExamplesResource"] |
| 19 | + |
| 20 | + |
| 21 | +class ExamplesResource(SyncAPIResource): |
| 22 | + @cached_property |
| 23 | + def with_raw_response(self) -> ExamplesResourceWithRawResponse: |
| 24 | + """ |
| 25 | + This property can be used as a prefix for any HTTP method call to return |
| 26 | + the raw response object instead of the parsed content. |
| 27 | +
|
| 28 | + For more information, see https://www.github.com/replicate/replicate-python-stainless#accessing-raw-response-data-eg-headers |
| 29 | + """ |
| 30 | + return ExamplesResourceWithRawResponse(self) |
| 31 | + |
| 32 | + @cached_property |
| 33 | + def with_streaming_response(self) -> ExamplesResourceWithStreamingResponse: |
| 34 | + """ |
| 35 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 36 | +
|
| 37 | + For more information, see https://www.github.com/replicate/replicate-python-stainless#with_streaming_response |
| 38 | + """ |
| 39 | + return ExamplesResourceWithStreamingResponse(self) |
| 40 | + |
| 41 | + def list( |
| 42 | + self, |
| 43 | + model_name: str, |
| 44 | + *, |
| 45 | + model_owner: str, |
| 46 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 47 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 48 | + extra_headers: Headers | None = None, |
| 49 | + extra_query: Query | None = None, |
| 50 | + extra_body: Body | None = None, |
| 51 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 52 | + ) -> None: |
| 53 | + """ |
| 54 | + List |
| 55 | + [example predictions](https://replicate.com/docs/topics/models/publish-a-model#what-are-examples) |
| 56 | + made using the model. These are predictions that were saved by the model author |
| 57 | + as illustrative examples of the model's capabilities. |
| 58 | +
|
| 59 | + If you want all the examples for a model, use this operation. |
| 60 | +
|
| 61 | + If you just want the model's default example, you can use the |
| 62 | + [`models.get`](#models.get) operation instead, which includes a |
| 63 | + `default_example` object. |
| 64 | +
|
| 65 | + Example cURL request: |
| 66 | +
|
| 67 | + ```console |
| 68 | + curl -s \\ |
| 69 | + -H "Authorization: Bearer $REPLICATE_API_TOKEN" \\ |
| 70 | + https://api.replicate.com/v1/models/replicate/hello-world/examples |
| 71 | + ``` |
| 72 | +
|
| 73 | + The response will be a pagination object containing a list of example |
| 74 | + predictions: |
| 75 | +
|
| 76 | + ```json |
| 77 | + { |
| 78 | + "next": "https://api.replicate.com/v1/models/replicate/hello-world/examples?cursor=...", |
| 79 | + "previous": "https://api.replicate.com/v1/models/replicate/hello-world/examples?cursor=...", |
| 80 | + "results": [...] |
| 81 | + } |
| 82 | + ``` |
| 83 | +
|
| 84 | + Each item in the `results` list is a [prediction object](#predictions.get). |
| 85 | +
|
| 86 | + Args: |
| 87 | + extra_headers: Send extra headers |
| 88 | +
|
| 89 | + extra_query: Add additional query parameters to the request |
| 90 | +
|
| 91 | + extra_body: Add additional JSON properties to the request |
| 92 | +
|
| 93 | + timeout: Override the client-level default timeout for this request, in seconds |
| 94 | + """ |
| 95 | + if not model_owner: |
| 96 | + raise ValueError(f"Expected a non-empty value for `model_owner` but received {model_owner!r}") |
| 97 | + if not model_name: |
| 98 | + raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}") |
| 99 | + extra_headers = {"Accept": "*/*", **(extra_headers or {})} |
| 100 | + return self._get( |
| 101 | + f"/models/{model_owner}/{model_name}/examples", |
| 102 | + options=make_request_options( |
| 103 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 104 | + ), |
| 105 | + cast_to=NoneType, |
| 106 | + ) |
| 107 | + |
| 108 | + |
| 109 | +class AsyncExamplesResource(AsyncAPIResource): |
| 110 | + @cached_property |
| 111 | + def with_raw_response(self) -> AsyncExamplesResourceWithRawResponse: |
| 112 | + """ |
| 113 | + This property can be used as a prefix for any HTTP method call to return |
| 114 | + the raw response object instead of the parsed content. |
| 115 | +
|
| 116 | + For more information, see https://www.github.com/replicate/replicate-python-stainless#accessing-raw-response-data-eg-headers |
| 117 | + """ |
| 118 | + return AsyncExamplesResourceWithRawResponse(self) |
| 119 | + |
| 120 | + @cached_property |
| 121 | + def with_streaming_response(self) -> AsyncExamplesResourceWithStreamingResponse: |
| 122 | + """ |
| 123 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 124 | +
|
| 125 | + For more information, see https://www.github.com/replicate/replicate-python-stainless#with_streaming_response |
| 126 | + """ |
| 127 | + return AsyncExamplesResourceWithStreamingResponse(self) |
| 128 | + |
| 129 | + async def list( |
| 130 | + self, |
| 131 | + model_name: str, |
| 132 | + *, |
| 133 | + model_owner: str, |
| 134 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 135 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 136 | + extra_headers: Headers | None = None, |
| 137 | + extra_query: Query | None = None, |
| 138 | + extra_body: Body | None = None, |
| 139 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 140 | + ) -> None: |
| 141 | + """ |
| 142 | + List |
| 143 | + [example predictions](https://replicate.com/docs/topics/models/publish-a-model#what-are-examples) |
| 144 | + made using the model. These are predictions that were saved by the model author |
| 145 | + as illustrative examples of the model's capabilities. |
| 146 | +
|
| 147 | + If you want all the examples for a model, use this operation. |
| 148 | +
|
| 149 | + If you just want the model's default example, you can use the |
| 150 | + [`models.get`](#models.get) operation instead, which includes a |
| 151 | + `default_example` object. |
| 152 | +
|
| 153 | + Example cURL request: |
| 154 | +
|
| 155 | + ```console |
| 156 | + curl -s \\ |
| 157 | + -H "Authorization: Bearer $REPLICATE_API_TOKEN" \\ |
| 158 | + https://api.replicate.com/v1/models/replicate/hello-world/examples |
| 159 | + ``` |
| 160 | +
|
| 161 | + The response will be a pagination object containing a list of example |
| 162 | + predictions: |
| 163 | +
|
| 164 | + ```json |
| 165 | + { |
| 166 | + "next": "https://api.replicate.com/v1/models/replicate/hello-world/examples?cursor=...", |
| 167 | + "previous": "https://api.replicate.com/v1/models/replicate/hello-world/examples?cursor=...", |
| 168 | + "results": [...] |
| 169 | + } |
| 170 | + ``` |
| 171 | +
|
| 172 | + Each item in the `results` list is a [prediction object](#predictions.get). |
| 173 | +
|
| 174 | + Args: |
| 175 | + extra_headers: Send extra headers |
| 176 | +
|
| 177 | + extra_query: Add additional query parameters to the request |
| 178 | +
|
| 179 | + extra_body: Add additional JSON properties to the request |
| 180 | +
|
| 181 | + timeout: Override the client-level default timeout for this request, in seconds |
| 182 | + """ |
| 183 | + if not model_owner: |
| 184 | + raise ValueError(f"Expected a non-empty value for `model_owner` but received {model_owner!r}") |
| 185 | + if not model_name: |
| 186 | + raise ValueError(f"Expected a non-empty value for `model_name` but received {model_name!r}") |
| 187 | + extra_headers = {"Accept": "*/*", **(extra_headers or {})} |
| 188 | + return await self._get( |
| 189 | + f"/models/{model_owner}/{model_name}/examples", |
| 190 | + options=make_request_options( |
| 191 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 192 | + ), |
| 193 | + cast_to=NoneType, |
| 194 | + ) |
| 195 | + |
| 196 | + |
| 197 | +class ExamplesResourceWithRawResponse: |
| 198 | + def __init__(self, examples: ExamplesResource) -> None: |
| 199 | + self._examples = examples |
| 200 | + |
| 201 | + self.list = to_raw_response_wrapper( |
| 202 | + examples.list, |
| 203 | + ) |
| 204 | + |
| 205 | + |
| 206 | +class AsyncExamplesResourceWithRawResponse: |
| 207 | + def __init__(self, examples: AsyncExamplesResource) -> None: |
| 208 | + self._examples = examples |
| 209 | + |
| 210 | + self.list = async_to_raw_response_wrapper( |
| 211 | + examples.list, |
| 212 | + ) |
| 213 | + |
| 214 | + |
| 215 | +class ExamplesResourceWithStreamingResponse: |
| 216 | + def __init__(self, examples: ExamplesResource) -> None: |
| 217 | + self._examples = examples |
| 218 | + |
| 219 | + self.list = to_streamed_response_wrapper( |
| 220 | + examples.list, |
| 221 | + ) |
| 222 | + |
| 223 | + |
| 224 | +class AsyncExamplesResourceWithStreamingResponse: |
| 225 | + def __init__(self, examples: AsyncExamplesResource) -> None: |
| 226 | + self._examples = examples |
| 227 | + |
| 228 | + self.list = async_to_streamed_response_wrapper( |
| 229 | + examples.list, |
| 230 | + ) |
0 commit comments