Skip to content

Commit 2651383

Browse files
chore(internal): codegen related update (#45)
1 parent 3a16763 commit 2651383

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ for agent in first_page.agents:
138138
# Remove `await` for non-async usage.
139139
```
140140

141+
## File uploads
142+
143+
Request parameters that correspond to file uploads can be passed as `bytes`, a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
144+
145+
```python
146+
from pathlib import Path
147+
from contextual import ContextualAI
148+
149+
client = ContextualAI()
150+
151+
client.datastores.documents.ingest(
152+
datastore_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
153+
file=Path("/path/to/file"),
154+
)
155+
```
156+
157+
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.
158+
141159
## Handling errors
142160

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

src/contextual/_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/ContextualAI/contextual-client-python/tree/main#file-uploads"
3838
) from None
3939

4040

0 commit comments

Comments
 (0)