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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ ai.resolve_hook("approve_send_email", {"granted": True, "reason": "approved"})

## Examples

Focused samples live in `examples/samples/`.
Focused samples live in `examples/`.

End-to-end demos:

Expand Down
21 changes: 14 additions & 7 deletions examples/.test_scripts/check-examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,35 @@
REPO = Path(__file__).resolve().parent.parent.parent
MYPY_VERSION = "mypy>=1.11"

# Each entry: (display name, directory to check, extra --with deps)
EXAMPLES: list[tuple[str, Path, list[str]]] = [
("samples", REPO / "examples" / "samples", []),
_SAMPLE_FILES = sorted(p.name for p in (REPO / "examples").glob("*.py"))

# Each entry: (display name, directory to check, extra --with deps, targets)
EXAMPLES: list[tuple[str, Path, list[str], list[str]]] = [
("samples", REPO / "examples", [], _SAMPLE_FILES),
(
"fastapi-vite/backend",
REPO / "examples" / "fastapi-vite" / "backend",
["fastapi"],
["."],
),
(
"multiagent-textual",
REPO / "examples" / "multiagent-textual",
["fastapi", "textual", "websockets"],
["."],
),
(
"temporal-direct",
REPO / "examples" / "temporal-direct",
["temporalio"],
["."],
),
]


def run_mypy(name: str, directory: Path, extra_deps: list[str]) -> bool:
def run_mypy(
name: str, directory: Path, extra_deps: list[str], targets: list[str]
) -> bool:
header = f"{'=' * 20} {name} {'=' * 20}"
print(header)

Expand All @@ -56,7 +63,7 @@ def run_mypy(name: str, directory: Path, extra_deps: list[str]) -> bool:
"mypy",
"--config-file",
str(REPO / "pyproject.toml"),
".",
*targets,
]

env = {k: v for k, v in os.environ.items() if k != "VIRTUAL_ENV"}
Expand All @@ -69,8 +76,8 @@ def run_mypy(name: str, directory: Path, extra_deps: list[str]) -> bool:

def main() -> None:
results: list[tuple[str, bool]] = []
for name, directory, extra_deps in EXAMPLES:
ok = run_mypy(name, directory, extra_deps)
for name, directory, extra_deps, targets in EXAMPLES:
ok = run_mypy(name, directory, extra_deps, targets)
results.append((name, ok))

print("=" * 60)
Expand Down
20 changes: 6 additions & 14 deletions examples/.test_scripts/run-examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from pathlib import Path

REPO = Path(__file__).resolve().parent.parent.parent
SAMPLES = REPO / "examples" / "samples"
PATCH_SCRIPT = REPO / "examples" / ".test_scripts" / "run-with-patched-model.py"
EXAMPLES_DIR = REPO / "examples"
PATCH_SCRIPT = EXAMPLES_DIR / ".test_scripts" / "run-with-patched-model.py"


@dataclasses.dataclass
Expand Down Expand Up @@ -140,13 +140,8 @@ def _known_sample_map() -> dict[str, Sample]:
samples: dict[str, Sample] = {}
for sample in KNOWN_SAMPLES:
samples[sample.name] = sample
if sample.cmd is None:
samples[f"samples/{sample.name}"] = sample
samples[f"examples/samples/{sample.name}"] = sample
samples[_path_key(SAMPLES / sample.name)] = sample
else:
samples[f"examples/{sample.name}"] = sample
samples[_path_key(REPO / "examples" / sample.name)] = sample
samples[f"examples/{sample.name}"] = sample
samples[_path_key(EXAMPLES_DIR / sample.name)] = sample
return samples


Expand All @@ -156,9 +151,7 @@ def _sample_path(name: str) -> Path:
return path
if path.parts[:1] == ("examples",):
return REPO / path
if path.parts[:1] == ("samples",):
return REPO / "examples" / path
return SAMPLES / path
return EXAMPLES_DIR / path


def _select_sample(
Expand Down Expand Up @@ -302,8 +295,7 @@ def main() -> None:
nargs="*",
metavar="example",
help=(
"example file(s) to run, e.g. stream.py or "
"examples/samples/stream.py"
"example file(s) to run, e.g. stream.py or " "examples/stream.py"
),
)
args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion examples/.test_scripts/run-with-patched-model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Example:
uv run examples/.test_scripts/run-with-patched-model.py \\
gateway:openai/gpt-5.4-mini \\
examples/samples/stream.py
examples/stream.py

"""

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading