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.7"
".": "0.1.0-alpha.8"
}
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: f0976fbc552ea878bb527447b5e663c9
config_hash: e1b3d85ba9ae21d729a914c789422ba7
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.1.0-alpha.8 (2025-06-27)

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

### Features

* **client:** setup streaming ([3fd6e57](https://github.com/digitalocean/gradientai-python/commit/3fd6e575f6f5952860e42d8c1fa22ccb0b10c623))

## 0.1.0-alpha.7 (2025-06-27)

Full Changelog: [v0.1.0-alpha.6...v0.1.0-alpha.7](https://github.com/digitalocean/gradientai-python/compare/v0.1.0-alpha.6...v0.1.0-alpha.7)
Expand Down
2 changes: 1 addition & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Methods:
Types:

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

Methods:
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.7"
version = "0.1.0-alpha.8"
description = "The official Python library for GradientAI"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
4 changes: 4 additions & 0 deletions src/gradientai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def __init__(
_strict_response_validation=_strict_response_validation,
)

self._default_stream_cls = Stream

@cached_property
def agents(self) -> AgentsResource:
from .resources.agents import AgentsResource
Expand Down Expand Up @@ -355,6 +357,8 @@ def __init__(
_strict_response_validation=_strict_response_validation,
)

self._default_stream_cls = AsyncStream

@cached_property
def agents(self) -> AsyncAgentsResource:
from .resources.agents import AsyncAgentsResource
Expand Down
43 changes: 40 additions & 3 deletions src/gradientai/_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

import httpx

from ._utils import extract_type_var_from_base
from ._utils import is_mapping, extract_type_var_from_base
from ._exceptions import APIError

if TYPE_CHECKING:
from ._client import GradientAI, AsyncGradientAI
Expand Down Expand Up @@ -55,7 +56,25 @@ def __stream__(self) -> Iterator[_T]:
iterator = self._iter_events()

for sse in iterator:
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
if sse.data.startswith("[DONE]"):
break

data = sse.json()
if is_mapping(data) and data.get("error"):
message = None
error = data.get("error")
if is_mapping(error):
message = error.get("message")
if not message or not isinstance(message, str):
message = "An error occurred during streaming"

raise APIError(
message=message,
request=self.response.request,
body=data["error"],
)

yield process_data(data=data, cast_to=cast_to, response=response)

# Ensure the entire stream is consumed
for _sse in iterator:
Expand Down Expand Up @@ -119,7 +138,25 @@ async def __stream__(self) -> AsyncIterator[_T]:
iterator = self._iter_events()

async for sse in iterator:
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
if sse.data.startswith("[DONE]"):
break

data = sse.json()
if is_mapping(data) and data.get("error"):
message = None
error = data.get("error")
if is_mapping(error):
message = error.get("message")
if not message or not isinstance(message, str):
message = "An error occurred during streaming"

raise APIError(
message=message,
request=self.response.request,
body=data["error"],
)

yield process_data(data=data, cast_to=cast_to, response=response)

# Ensure the entire stream is consumed
async for _sse in iterator:
Expand Down
2 changes: 1 addition & 1 deletion src/gradientai/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "gradientai"
__version__ = "0.1.0-alpha.7" # x-release-please-version
__version__ = "0.1.0-alpha.8" # x-release-please-version
Loading