Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cliVersion": "4.0.1",
"cliVersion": "4.2.2",
"generatorName": "fernapi/fern-python-sdk",
"generatorVersion": "4.59.4",
"generatorConfig": {
Expand Down
60 changes: 39 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The Runcaptain Python library provides convenient access to the Runcaptain APIs
- [Usage](#usage)
- [Async Client](#async-client)
- [Exception Handling](#exception-handling)
- [Streaming](#streaming)
- [Advanced](#advanced)
- [Access Raw Response Data](#access-raw-response-data)
- [Retries](#retries)
Expand Down Expand Up @@ -40,14 +41,12 @@ client = Captain(
organization_id="YOUR_ORGANIZATION_ID",
key="YOUR_KEY",
)
client.query.collection_v2(
collection_name="my_documents",
query="What are the key terms in the contract?",
inference=True,
stream=True,
rerank=True,
top_k=10,
response = client.query.collection_v2stream(
collection_name="collection_name",
query="query",
)
for chunk in response.data:
yield chunk
```

## Async Client
Expand All @@ -66,14 +65,12 @@ client = AsyncCaptain(


async def main() -> None:
await client.query.collection_v2(
collection_name="my_documents",
query="What are the key terms in the contract?",
inference=True,
stream=True,
rerank=True,
top_k=10,
response = await client.query.collection_v2stream(
collection_name="collection_name",
query="query",
)
async for chunk in response.data:
yield chunk


asyncio.run(main())
Expand All @@ -88,12 +85,31 @@ will be thrown.
from runcaptain.core.api_error import ApiError

try:
client.query.collection_v2(...)
client.query.collection_v2stream(...)
except ApiError as e:
print(e.status_code)
print(e.body)
```

## Streaming

The SDK supports streaming responses, as well, the response will be a generator that you can loop over.

```python
from runcaptain import Captain

client = Captain(
organization_id="YOUR_ORGANIZATION_ID",
key="YOUR_KEY",
)
response = client.query.collection_v2stream(
collection_name="collection_name",
query="query",
)
for chunk in response.data:
yield chunk
```

## Advanced

### Access Raw Response Data
Expand All @@ -107,10 +123,12 @@ from runcaptain import Captain
client = Captain(
...,
)
response = client.query.with_raw_response.collection_v2(...)
print(response.headers) # access the response headers
print(response.status_code) # access the response status code
print(response.data) # access the underlying object
with client.query.with_raw_response.collection_v2stream(...) as response:
print(
response.headers
) # access the response headersprint(response.status_code) # access the response status code
for chunk in response.data:
print(chunk) # access the underlying object(s)
```

### Retries
Expand All @@ -128,7 +146,7 @@ A request is deemed retryable when any of the following HTTP status codes is ret
Use the `max_retries` request option to configure this behavior.

```python
client.query.collection_v2(..., request_options={
client.query.collection_v2stream(..., request_options={
"max_retries": 1
})
```
Expand All @@ -148,7 +166,7 @@ client = Captain(


# Override timeout for a specific method
client.query.collection_v2(..., request_options={
client.query.collection_v2stream(..., request_options={
"timeout_in_seconds": 1
})
```
Expand Down
Loading