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 .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.9"
".": "0.1.0-alpha.10"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 76
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/digitalocean%2Fgradientai-e8b3cbc80e18e4f7f277010349f25e1319156704f359911dc464cc21a0d077a6.yml
openapi_spec_hash: c773d792724f5647ae25a5ae4ccec208
config_hash: 0bc3af28d4abd9be8bcc81f615bc832d
config_hash: 9b44ce3fd39c43f2001bc11934e6b1b0
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.1.0-alpha.10 (2025-06-28)

Full Changelog: [v0.1.0-alpha.9...v0.1.0-alpha.10](https://github.com/digitalocean/gradientai-python/compare/v0.1.0-alpha.9...v0.1.0-alpha.10)

### Features

* **api:** manual updates ([0e5effc](https://github.com/digitalocean/gradientai-python/commit/0e5effc727cebe88ea38f0ec4c3fcb45ffeb4924))
* **api:** manual updates ([d510ae0](https://github.com/digitalocean/gradientai-python/commit/d510ae03f13669af7f47093af06a00609e9b7c07))
* **api:** manual updates ([c5bc3ca](https://github.com/digitalocean/gradientai-python/commit/c5bc3caa477945dc19bbf90661ffeea86370189d))

## 0.1.0-alpha.9 (2025-06-28)

Full Changelog: [v0.1.0-alpha.8...v0.1.0-alpha.9](https://github.com/digitalocean/gradientai-python/compare/v0.1.0-alpha.8...v0.1.0-alpha.9)
Expand Down
123 changes: 86 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ print(api_client.agents.list())
completion = inference_client.chat.completions.create(
messages=[
{
"content": "string",
"role": "system",
"role": "user",
"content": "What is the capital of France?",
}
],
model="llama3-8b-instruct",
model="llama3.3-70b-instruct",
)

print(completion.choices[0].message)

```
Expand Down Expand Up @@ -72,13 +73,13 @@ async def main() -> None:
completion = await client.agents.chat.completions.create(
messages=[
{
"content": "string",
"role": "system",
"role": "user",
"content": "What is the capital of France?",
}
],
model="llama3-8b-instruct",
model="llama3.3-70b-instruct",
)
print(completion.id)
print(completion.choices)


asyncio.run(main())
Expand Down Expand Up @@ -114,41 +115,61 @@ async def main() -> None:
completion = await client.agents.chat.completions.create(
messages=[
{
"content": "string",
"role": "system",
"role": "user",
"content": "What is the capital of France?",
}
],
model="llama3-8b-instruct",
model="llama3.3-70b-instruct",
)
print(completion.id)
print(completion.choices)


asyncio.run(main())
```

## Streaming
Support for streaming responses are available by Server Side Events (SSE) for Serverless Inference and Agents.
```
import os
## Streaming responses

We provide support for streaming responses using Server Side Events (SSE).

```python
from gradientai import GradientAI

client = GradientAI(
inference_key=os.environ.get("GRADIENTAI_INFERENCE_KEY")
)
client = GradientAI()

response = client.chat.completions.create(
stream = client.agents.chat.completions.create(
messages=[
{
"role": "user",
"content": "What is the capital of France?",
}
],
model="llama3.3-70b-instruct",
messages=[{ "role": "user", "content": "Write a story about a brave squirrel."}],
stream=True,
)
for completion in stream:
print(completion.choices)
```

for chunk in response:
if len(chunk.choices) > 0:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
The async client uses the exact same interface.

```
```python
from gradientai import AsyncGradientAI

client = AsyncGradientAI()

stream = await client.agents.chat.completions.create(
messages=[
{
"role": "user",
"content": "What is the capital of France?",
}
],
model="llama3.3-70b-instruct",
stream=True,
)
async for completion in stream:
print(completion.choices)
```

## Using types

Expand Down Expand Up @@ -197,8 +218,14 @@ from gradientai import GradientAI
client = GradientAI()

try:
client.agents.versions.list(
uuid="REPLACE_ME",
client.agents.chat.completions.create(
messages=[
{
"role": "user",
"content": "What is the capital of France?",
}
],
model="llama3.3-70b-instruct",
)
except gradientai.APIConnectionError as e:
print("The server could not be reached")
Expand Down Expand Up @@ -242,8 +269,14 @@ client = GradientAI(
)

# Or, configure per-request:
client.with_options(max_retries=5).agents.versions.list(
uuid="REPLACE_ME",
client.with_options(max_retries=5).agents.chat.completions.create(
messages=[
{
"role": "user",
"content": "What is the capital of France?",
}
],
model="llama3.3-70b-instruct",
)
```

Expand All @@ -267,8 +300,14 @@ client = GradientAI(
)

# Override per-request:
client.with_options(timeout=5.0).agents.versions.list(
uuid="REPLACE_ME",
client.with_options(timeout=5.0).agents.chat.completions.create(
messages=[
{
"role": "user",
"content": "What is the capital of France?",
}
],
model="llama3.3-70b-instruct",
)
```

Expand Down Expand Up @@ -310,13 +349,17 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
from gradientai import GradientAI

client = GradientAI()
response = client.agents.versions.with_raw_response.list(
uuid="REPLACE_ME",
response = client.agents.chat.completions.with_raw_response.create(
messages=[{
"role": "user",
"content": "What is the capital of France?",
}],
model="llama3.3-70b-instruct",
)
print(response.headers.get('X-My-Header'))

version = response.parse() # get the object that `agents.versions.list()` would have returned
print(version.agent_versions)
completion = response.parse() # get the object that `agents.chat.completions.create()` would have returned
print(completion.choices)
```

These methods return an [`APIResponse`](https://github.com/digitalocean/gradientai-python/tree/main/src/gradientai/_response.py) object.
Expand All @@ -330,8 +373,14 @@ The above interface eagerly reads the full response body when you make the reque
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.

```python
with client.agents.versions.with_streaming_response.list(
uuid="REPLACE_ME",
with client.agents.chat.completions.with_streaming_response.create(
messages=[
{
"role": "user",
"content": "What is the capital of France?",
}
],
model="llama3.3-70b-instruct",
) as response:
print(response.headers.get("X-My-Header"))

Expand Down
28 changes: 14 additions & 14 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ Methods:
- <code title="post /v2/gen-ai/agents/{parent_agent_uuid}/child_agents/{child_agent_uuid}">client.agents.routes.<a href="./src/gradientai/resources/agents/routes.py">add</a>(path_child_agent_uuid, \*, path_parent_agent_uuid, \*\*<a href="src/gradientai/types/agents/route_add_params.py">params</a>) -> <a href="./src/gradientai/types/agents/route_add_response.py">RouteAddResponse</a></code>
- <code title="get /v2/gen-ai/agents/{uuid}/child_agents">client.agents.routes.<a href="./src/gradientai/resources/agents/routes.py">view</a>(uuid) -> <a href="./src/gradientai/types/agents/route_view_response.py">RouteViewResponse</a></code>

# Chat

## Completions

Types:

```python
from gradientai.types.chat import ChatCompletionChunk, CompletionCreateResponse
```

Methods:

- <code title="post /chat/completions">client.chat.completions.<a href="./src/gradientai/resources/chat/completions.py">create</a>(\*\*<a href="src/gradientai/types/chat/completion_create_params.py">params</a>) -> <a href="./src/gradientai/types/chat/completion_create_response.py">CompletionCreateResponse</a></code>

# ModelProviders

## Anthropic
Expand Down Expand Up @@ -389,20 +403,6 @@ Methods:
- <code title="get /v2/gen-ai/indexing_jobs/{indexing_job_uuid}/data_sources">client.knowledge_bases.indexing_jobs.<a href="./src/gradientai/resources/knowledge_bases/indexing_jobs.py">retrieve_data_sources</a>(indexing_job_uuid) -> <a href="./src/gradientai/types/knowledge_bases/indexing_job_retrieve_data_sources_response.py">IndexingJobRetrieveDataSourcesResponse</a></code>
- <code title="put /v2/gen-ai/indexing_jobs/{uuid}/cancel">client.knowledge_bases.indexing_jobs.<a href="./src/gradientai/resources/knowledge_bases/indexing_jobs.py">update_cancel</a>(path_uuid, \*\*<a href="src/gradientai/types/knowledge_bases/indexing_job_update_cancel_params.py">params</a>) -> <a href="./src/gradientai/types/knowledge_bases/indexing_job_update_cancel_response.py">IndexingJobUpdateCancelResponse</a></code>

# Chat

## Completions

Types:

```python
from gradientai.types.chat import ChatCompletionChunk, CompletionCreateResponse
```

Methods:

- <code title="post /chat/completions">client.chat.completions.<a href="./src/gradientai/resources/chat/completions.py">create</a>(\*\*<a href="src/gradientai/types/chat/completion_create_params.py">params</a>) -> <a href="./src/gradientai/types/chat/completion_create_response.py">CompletionCreateResponse</a></code>

# Inference

## APIKeys
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "c63a5cfe-b235-4fbe-8bbb-82a9e02a482a-python"
version = "0.1.0-alpha.9"
version = "0.1.0-alpha.10"
description = "The official Python library for GradientAI"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
Loading