Skip to content

Commit aef2230

Browse files
committed
Merge remote-tracking branch 'origin/next' into sam/run-helper
2 parents a5c02d4 + 13162be commit aef2230

File tree

16 files changed

+1440
-6
lines changed

16 files changed

+1440
-6
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 30
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-2088d647e7b0fd37dcf58ef48b8f01ed1a82ff797b9697ad10a7b6a5105e9e0f.yml
3-
openapi_spec_hash: 718f540e7c44501e1a8c7156ee45d595
4-
config_hash: 927b6ebc00ee115763ad69483bbf5566
1+
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
4+
config_hash: 8ef6787524fd12bfeb27f8c6acef3dca

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,24 @@ for prediction in first_page.results:
136136
# Remove `await` for non-async usage.
137137
```
138138

139+
## File uploads
140+
141+
Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
142+
143+
```python
144+
from pathlib import Path
145+
from replicate import Replicate
146+
147+
client = Replicate()
148+
149+
client.files.create(
150+
content=Path("/path/to/file"),
151+
filename="filename",
152+
)
153+
```
154+
155+
The async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically.
156+
139157
## Handling errors
140158

141159
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `replicate.APIConnectionError` is raised.

api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,11 @@ from replicate.types.webhooks.default import SecretGetResponse
154154
Methods:
155155

156156
- <code title="get /webhooks/default/secret">client.webhooks.default.secret.<a href="./src/replicate/resources/webhooks/default/secret.py">get</a>() -> <a href="./src/replicate/types/webhooks/default/secret_get_response.py">SecretGetResponse</a></code>
157+
158+
# Files
159+
160+
Types:
161+
162+
```python
163+
from replicate.types import FileCreateResponse, FileListResponse, FileGetResponse
164+
```

src/replicate/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def _reset_client() -> None: # type: ignore[reportUnusedFunction]
238238

239239
from ._module_client import (
240240
run as run,
241+
files as files,
241242
models as models,
242243
account as account,
243244
hardware as hardware,

src/replicate/_client.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
)
3636

3737
if TYPE_CHECKING:
38-
from .resources import models, account, hardware, webhooks, trainings, collections, deployments, predictions
38+
from .resources import files, models, account, hardware, webhooks, trainings, collections, deployments, predictions
39+
from .resources.files import FilesResource, AsyncFilesResource
3940
from .resources.account import AccountResource, AsyncAccountResource
4041
from .resources.hardware import HardwareResource, AsyncHardwareResource
4142
from .resources.trainings import TrainingsResource, AsyncTrainingsResource
@@ -160,6 +161,12 @@ def webhooks(self) -> WebhooksResource:
160161

161162
return WebhooksResource(self)
162163

164+
@cached_property
165+
def files(self) -> FilesResource:
166+
from .resources.files import FilesResource
167+
168+
return FilesResource(self)
169+
163170
@cached_property
164171
def with_raw_response(self) -> ReplicateWithRawResponse:
165172
return ReplicateWithRawResponse(self)
@@ -428,6 +435,12 @@ def webhooks(self) -> AsyncWebhooksResource:
428435

429436
return AsyncWebhooksResource(self)
430437

438+
@cached_property
439+
def files(self) -> AsyncFilesResource:
440+
from .resources.files import AsyncFilesResource
441+
442+
return AsyncFilesResource(self)
443+
431444
@cached_property
432445
def with_raw_response(self) -> AsyncReplicateWithRawResponse:
433446
return AsyncReplicateWithRawResponse(self)
@@ -647,6 +660,12 @@ def webhooks(self) -> webhooks.WebhooksResourceWithRawResponse:
647660

648661
return WebhooksResourceWithRawResponse(self._client.webhooks)
649662

663+
@cached_property
664+
def files(self) -> files.FilesResourceWithRawResponse:
665+
from .resources.files import FilesResourceWithRawResponse
666+
667+
return FilesResourceWithRawResponse(self._client.files)
668+
650669

651670
class AsyncReplicateWithRawResponse:
652671
_client: AsyncReplicate
@@ -702,6 +721,12 @@ def webhooks(self) -> webhooks.AsyncWebhooksResourceWithRawResponse:
702721

703722
return AsyncWebhooksResourceWithRawResponse(self._client.webhooks)
704723

724+
@cached_property
725+
def files(self) -> files.AsyncFilesResourceWithRawResponse:
726+
from .resources.files import AsyncFilesResourceWithRawResponse
727+
728+
return AsyncFilesResourceWithRawResponse(self._client.files)
729+
705730

706731
class ReplicateWithStreamedResponse:
707732
_client: Replicate
@@ -757,6 +782,12 @@ def webhooks(self) -> webhooks.WebhooksResourceWithStreamingResponse:
757782

758783
return WebhooksResourceWithStreamingResponse(self._client.webhooks)
759784

785+
@cached_property
786+
def files(self) -> files.FilesResourceWithStreamingResponse:
787+
from .resources.files import FilesResourceWithStreamingResponse
788+
789+
return FilesResourceWithStreamingResponse(self._client.files)
790+
760791

761792
class AsyncReplicateWithStreamedResponse:
762793
_client: AsyncReplicate
@@ -812,6 +843,12 @@ def webhooks(self) -> webhooks.AsyncWebhooksResourceWithStreamingResponse:
812843

813844
return AsyncWebhooksResourceWithStreamingResponse(self._client.webhooks)
814845

846+
@cached_property
847+
def files(self) -> files.AsyncFilesResourceWithStreamingResponse:
848+
from .resources.files import AsyncFilesResourceWithStreamingResponse
849+
850+
return AsyncFilesResourceWithStreamingResponse(self._client.files)
851+
815852

816853
Client = Replicate
817854

src/replicate/_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
3434
if not is_file_content(obj):
3535
prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`"
3636
raise RuntimeError(
37-
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead."
37+
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead. See https://github.com/replicate/replicate-python-stainless/tree/main#file-uploads"
3838
) from None
3939

4040

src/replicate/_module_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing_extensions import cast, override
77

88
if TYPE_CHECKING:
9+
from .resources.files import FilesResource
910
from .resources.account import AccountResource
1011
from .resources.hardware import HardwareResource
1112
from .resources.trainings import TrainingsResource
@@ -19,6 +20,12 @@
1920
from ._utils import LazyProxy
2021

2122

23+
class FilesResourceProxy(LazyProxy["FilesResource"]):
24+
@override
25+
def __load__(self) -> FilesResource:
26+
return _load_client().files
27+
28+
2229
class ModelsResourceProxy(LazyProxy["ModelsResource"]):
2330
@override
2431
def __load__(self) -> ModelsResource:
@@ -81,6 +88,7 @@ def _run(*args, **kwargs):
8188

8289
run = _run
8390

91+
files: FilesResource = FilesResourceProxy().__as_proxied__()
8492
models: ModelsResource = ModelsResourceProxy().__as_proxied__()
8593
account: AccountResource = AccountResourceProxy().__as_proxied__()
8694
hardware: HardwareResource = HardwareResourceProxy().__as_proxied__()

src/replicate/resources/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
from .files import (
4+
FilesResource,
5+
AsyncFilesResource,
6+
FilesResourceWithRawResponse,
7+
AsyncFilesResourceWithRawResponse,
8+
FilesResourceWithStreamingResponse,
9+
AsyncFilesResourceWithStreamingResponse,
10+
)
311
from .models import (
412
ModelsResource,
513
AsyncModelsResource,
@@ -114,4 +122,10 @@
114122
"AsyncWebhooksResourceWithRawResponse",
115123
"WebhooksResourceWithStreamingResponse",
116124
"AsyncWebhooksResourceWithStreamingResponse",
125+
"FilesResource",
126+
"AsyncFilesResource",
127+
"FilesResourceWithRawResponse",
128+
"AsyncFilesResourceWithRawResponse",
129+
"FilesResourceWithStreamingResponse",
130+
"AsyncFilesResourceWithStreamingResponse",
117131
]

0 commit comments

Comments
 (0)