Skip to content

Commit 6e5b7d9

Browse files
release: 3.0.2 (#44)
1 parent eaafa66 commit 6e5b7d9

File tree

97 files changed

+2530
-2170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2530
-2170
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/sh
2+
3+
export DIGITALOCEAN_ACCESS_TOKEN=replace_me
4+
export GRADIENT_MODEL_ACCESS_KEY=replace_me
5+
export GRADIENT_AGENT_ACCESS_KEY=replace_me
6+
export GRADIENT_AGENT_ENDPOINT=https://your-agent-subdomain.agents.do-ai.run

.github/workflows/ci.yml

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: CI
22
on:
33
push:
44
branches-ignore:
5-
- 'generated'
6-
- 'codegen/**'
7-
- 'integrated/**'
8-
- 'stl-preview-head/**'
9-
- 'stl-preview-base/**'
5+
- "generated"
6+
- "codegen/**"
7+
- "integrated/**"
8+
- "stl-preview-head/**"
9+
- "stl-preview-base/**"
1010
pull_request:
1111
branches-ignore:
12-
- 'stl-preview-head/**'
13-
- 'stl-preview-base/**'
12+
- "stl-preview-head/**"
13+
- "stl-preview-base/**"
1414

1515
jobs:
1616
lint:
@@ -26,8 +26,8 @@ jobs:
2626
curl -sSf https://rye.astral.sh/get | bash
2727
echo "$HOME/.rye/shims" >> $GITHUB_PATH
2828
env:
29-
RYE_VERSION: '0.44.0'
30-
RYE_INSTALL_OPTION: '--yes'
29+
RYE_VERSION: "0.44.0"
30+
RYE_INSTALL_OPTION: "--yes"
3131

3232
- name: Install dependencies
3333
run: rye sync --all-features
@@ -51,8 +51,8 @@ jobs:
5151
curl -sSf https://rye.astral.sh/get | bash
5252
echo "$HOME/.rye/shims" >> $GITHUB_PATH
5353
env:
54-
RYE_VERSION: '0.44.0'
55-
RYE_INSTALL_OPTION: '--yes'
54+
RYE_VERSION: "0.44.0"
55+
RYE_INSTALL_OPTION: "--yes"
5656

5757
- name: Install dependencies
5858
run: rye sync --all-features
@@ -88,11 +88,39 @@ jobs:
8888
curl -sSf https://rye.astral.sh/get | bash
8989
echo "$HOME/.rye/shims" >> $GITHUB_PATH
9090
env:
91-
RYE_VERSION: '0.44.0'
92-
RYE_INSTALL_OPTION: '--yes'
91+
RYE_VERSION: "0.44.0"
92+
RYE_INSTALL_OPTION: "--yes"
9393

9494
- name: Bootstrap
9595
run: ./scripts/bootstrap
9696

9797
- name: Run tests
9898
run: ./scripts/test
99+
100+
smoke:
101+
name: smoke
102+
# Only run smoke tests on pushes to main repo (not forks) so that secrets can be accessed
103+
if: github.repository == 'stainless-sdks/gradient-python' && github.event_name == 'push'
104+
runs-on: ${{ github.repository == 'stainless-sdks/gradient-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
105+
timeout-minutes: 10
106+
steps:
107+
- uses: actions/checkout@v4
108+
109+
- name: Install Rye
110+
run: |
111+
curl -sSf https://rye.astral.sh/get | bash
112+
echo "$HOME/.rye/shims" >> $GITHUB_PATH
113+
env:
114+
RYE_VERSION: "0.44.0"
115+
RYE_INSTALL_OPTION: "--yes"
116+
117+
- name: Bootstrap
118+
run: ./scripts/bootstrap
119+
120+
- name: Run smoke tests
121+
env:
122+
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
123+
GRADIENT_MODEL_ACCESS_KEY: ${{ secrets.GRADIENT_MODEL_ACCESS_KEY }}
124+
GRADIENT_AGENT_ACCESS_KEY: ${{ secrets.GRADIENT_AGENT_ACCESS_KEY }}
125+
GRADIENT_AGENT_ENDPOINT: ${{ secrets.GRADIENT_AGENT_ENDPOINT }}
126+
run: ./scripts/smoke

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "3.0.1"
2+
".": "3.0.2"
33
}

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 3.0.2 (2025-09-24)
4+
5+
Full Changelog: [v3.0.1...v3.0.2](https://github.com/digitalocean/gradient-python/compare/v3.0.1...v3.0.2)
6+
7+
### Chores
8+
9+
* do not install brew dependencies in ./scripts/bootstrap by default ([d83b77a](https://github.com/digitalocean/gradient-python/commit/d83b77a943d7beb3373eebc543cdc787371753a5))
10+
* improve example values ([8f3a107](https://github.com/digitalocean/gradient-python/commit/8f3a107935a7ef0aa7e0e93161a24c7ecf24a272))
11+
* **types:** change optional parameter type from NotGiven to Omit ([78eb019](https://github.com/digitalocean/gradient-python/commit/78eb019c87cc55186abffd92f1d710d0c6ef0895))
12+
313
## 3.0.1 (2025-09-24)
414

515
Full Changelog: [v3.0.0...v3.0.1](https://github.com/digitalocean/gradient-python/compare/v3.0.0...v3.0.1)

CONTRIBUTING.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,41 @@ $ npx prism mock path/to/your/openapi.yml
9696
$ ./scripts/test
9797
```
9898

99+
## Smoke tests & environment variables
100+
101+
The repository includes a small set of live "smoke" tests (see the `smoke` pytest marker) that exercise real Gradient API endpoints. These are excluded from the default test run and only executed when you explicitly target them (`pytest -m smoke`) or in CI via the dedicated `smoke` job.
102+
103+
Required environment variables for smoke tests (all must be set):
104+
105+
| Variable | Purpose |
106+
|----------|---------|
107+
| `DIGITALOCEAN_ACCESS_TOKEN` | Access token for core DigitalOcean Gradient API operations (e.g. listing agents). |
108+
| `GRADIENT_MODEL_ACCESS_KEY` | Key used for serverless inference (chat completions, etc.). |
109+
| `GRADIENT_AGENT_ACCESS_KEY` | Key used for agent-scoped inference requests. |
110+
| `GRADIENT_AGENT_ENDPOINT` | Fully-qualified HTTPS endpoint for your deployed agent (e.g. `https://my-agent.agents.do-ai.run`). |
111+
112+
Optional override:
113+
114+
| Variable | Purpose |
115+
|----------|---------|
116+
| `GRADIENT_INFERENCE_ENDPOINT` | Override default inference endpoint (`https://inference.do-ai.run`). |
117+
118+
Create a local `.env` file (never commit real secrets). A template is provided at `.env.example`.
119+
120+
Key design notes:
121+
* Sync & async suites each have a single central test that asserts environment presence and client auto-loaded properties.
122+
* Other smoke tests intentionally avoid repeating environment / property assertions to keep noise low.
123+
* Add new credentials by updating the `REQUIRED_ENV_VARS` tuple in both smoke test files and documenting them here and in the README.
124+
125+
Run smoke tests locally:
126+
127+
```bash
128+
./scripts/smoke # convenience wrapper
129+
pytest -m smoke -q # direct invocation
130+
```
131+
132+
Do NOT run smoke tests against production credentials unless you understand the API calls performed—they make real network requests.
133+
99134
## Linting and formatting
100135

101136
This repository uses [ruff](https://github.com/astral-sh/ruff) and

README.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ print(agent_response.choices[0].message.content)
9696

9797
While you can provide an `access_token`, `model_access_key` keyword argument,
9898
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
99-
to add `DIGITALOCEAN_ACCESS_TOKEN="My API Key"`, `GRADIENT_MODEL_ACCESS_KEY="My INFERENCE Key"` to your `.env` file
99+
to add `DIGITALOCEAN_ACCESS_TOKEN="My Access Token"`, `GRADIENT_MODEL_ACCESS_KEY="My Model Access Key"` to your `.env` file
100100
so that your keys are not stored in source control.
101101

102102
## Async usage
@@ -542,7 +542,64 @@ Python 3.8 or higher.
542542

543543
See [the contributing documentation](./CONTRIBUTING.md).
544544

545+
## Smoke tests
546+
547+
The repository includes a small set of "smoke" tests that exercise live Gradient API / Inference / Agent endpoints to catch integration regressions early. These tests are intentionally excluded from the standard test run (they are marked with the `smoke` pytest marker) and only run in CI via the dedicated `smoke` job, or when you explicitly target them locally.
548+
549+
### Required environment variables
550+
551+
All of the following environment variables must be set for the smoke tests (both sync & async) to run. If any are missing the smoke tests will fail fast:
552+
553+
| Variable | Purpose |
554+
|----------|---------|
555+
| `DIGITALOCEAN_ACCESS_TOKEN` | Access token for core DigitalOcean Gradient API operations (e.g. listing agents). |
556+
| `GRADIENT_MODEL_ACCESS_KEY` | Key used for serverless inference (chat completions, etc.). |
557+
| `GRADIENT_AGENT_ACCESS_KEY` | Key used for agent-scoped inference requests. |
558+
| `GRADIENT_AGENT_ENDPOINT` | Fully-qualified HTTPS endpoint for your deployed agent (e.g. `https://my-agent.agents.do-ai.run`). |
559+
560+
> Optional override: `GRADIENT_INFERENCE_ENDPOINT` can be provided to point inference to a non-default endpoint (defaults to `https://inference.do-ai.run`).
561+
562+
### Running smoke tests locally
563+
564+
1. Export the required environment variables (or place them in a `.env` file and use a tool like `direnv` or `python-dotenv`).
565+
2. Run only the smoke tests:
566+
567+
```bash
568+
rye run pytest -m smoke -q
569+
```
570+
571+
To include them alongside the regular suite:
572+
573+
```bash
574+
./scripts/test -m smoke
575+
```
576+
577+
Convenience wrapper (auto-loads a local `.env` if present):
578+
579+
```bash
580+
./scripts/smoke
581+
```
582+
583+
See `.env.example` for a template of required variables you can copy into a `.env` file (do not commit secrets).
584+
585+
### Async variants
586+
587+
Each smoke test has an async counterpart in `tests/test_smoke_sdk_async.py`. Both sets are covered automatically by the `-m smoke` selection.
588+
589+
### CI behavior
590+
591+
The default `test` job excludes smoke tests (`-m 'not smoke'`). A separate `smoke` job runs on pushes to the main repository with the required secrets injected. This keeps contributors from inadvertently hitting live services while still providing integration coverage in controlled environments.
592+
593+
### Adding new smoke tests
594+
595+
1. Add a new test function to `tests/test_smoke_sdk.py` and/or `tests/test_smoke_sdk_async.py`.
596+
2. Mark it with `@pytest.mark.smoke`.
597+
3. Avoid duplicating environment or client property assertions—those live in the central environment/client state test (sync & async).
598+
4. Keep assertions minimal—verify only surface contract / structure; deeper behavior belongs in unit tests with mocks.
599+
600+
If a new credential is required, update this README section, the `REQUIRED_ENV_VARS` list in both smoke test files, and the CI workflow's `smoke` job environment.
601+
545602

546603
## License
547604

548-
Licensed under the Apache License 2.0. See [LICENSE](./LICENSE)
605+
Licensed under the Apache License 2.0. See [LICENSE](./LICENSE)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "gradient"
3-
version = "3.0.1"
3+
version = "3.0.2"
44
description = "The official Python library for the Gradient API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pytest]
2+
markers =
3+
smoke: lightweight external integration smoke tests hitting live Gradient services
4+
addopts = -m "not smoke"
5+
asyncio_mode = auto

scripts/bootstrap

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ set -e
44

55
cd "$(dirname "$0")/.."
66

7-
if ! command -v rye >/dev/null 2>&1 && [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then
7+
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] && [ -t 0 ]; then
88
brew bundle check >/dev/null 2>&1 || {
9-
echo "==> Installing Homebrew dependencies…"
10-
brew bundle
9+
echo -n "==> Install Homebrew dependencies? (y/N): "
10+
read -r response
11+
case "$response" in
12+
[yY][eE][sS]|[yY])
13+
brew bundle
14+
;;
15+
*)
16+
;;
17+
esac
18+
echo
1119
}
1220
fi
1321

scripts/smoke

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
# Purpose: Run live smoke tests (sync + async) against real Gradient services.
4+
# These tests require valid credentials and are excluded from the normal test run.
5+
# Usage:
6+
# ./scripts/smoke # run all smoke tests
7+
# ./scripts/smoke -k agents # pass through extra pytest args
8+
#
9+
# If a .env file exists in the repo root it will be sourced automatically.
10+
11+
set -euo pipefail
12+
13+
cd "$(dirname "$0")/.."
14+
15+
if [ -f .env ]; then
16+
echo "==> Loading .env"
17+
# export variables declared in .env
18+
set -a
19+
# shellcheck disable=SC1091
20+
source .env
21+
set +a
22+
fi
23+
24+
required=(
25+
DIGITALOCEAN_ACCESS_TOKEN
26+
GRADIENT_MODEL_ACCESS_KEY
27+
GRADIENT_AGENT_ACCESS_KEY
28+
GRADIENT_AGENT_ENDPOINT
29+
)
30+
31+
missing=()
32+
for var in "${required[@]}"; do
33+
if [ -z "${!var:-}" ]; then
34+
missing+=("$var")
35+
fi
36+
done
37+
38+
if [ ${#missing[@]} -ne 0 ]; then
39+
echo "ERROR: Missing required environment variables for smoke tests:" >&2
40+
printf ' %s\n' "${missing[@]}" >&2
41+
echo >&2
42+
echo "Provide them via your shell environment or a .env file (see .env.example)." >&2
43+
exit 1
44+
fi
45+
46+
echo "==> Running smoke tests (marker: smoke)"
47+
rye run pytest -m smoke "$@"

0 commit comments

Comments
 (0)