Code Snippets Collection

Browse Snippets by Tags

Click on any tag to see all related snippets.

agents

OpenAI Agents SDK — basic agent and runner

Using the OpenAI Agents SDK to create agents with tools and run them with the basic Runner class.

Libraries: agents

ToyAIKit with OpenAI Agents SDK

Using ToyAIKit with the OpenAI Agents SDK to create persistent agents with tools and async chat interfaces.

Libraries: toyaikit, agents

ai

OpenAI Agents SDK — basic agent and runner

Using the OpenAI Agents SDK to create agents with tools and run them with the basic Runner class.

Libraries: agents

OpenAI Responses API — accessing function calls, messages, and usage

Examples showing how to call the Responses API, read function call outputs, inspect returned messages, and examine usage metadata.

Libraries: openai

Pydantic AI — streaming display with Rich

Display streaming agent execution using a Rich console while iterating over agent events.

Libraries: pydantic_ai, rich

ToyAIKit with Pydantic AI

Using ToyAIKit with Pydantic AI to create type-safe agents with structured tools and async chat interfaces.

Libraries: toyaikit, pydantic_ai

ToyAIKit with OpenAI Agents SDK

Using ToyAIKit with the OpenAI Agents SDK to create persistent agents with tools and async chat interfaces.

Libraries: toyaikit, agents

ToyAIKit custom callbacks

Creating custom callback classes by extending RunnerCallback to handle function calls, messages, and responses in ToyAIKit runners.

Libraries: toyaikit

ToyAIKit loops with callbacks and cost tracking

Using ToyAIKit callbacks to display intermediate results and track API costs in OpenAI Responses runner.

Libraries: toyaikit

ToyAIKit — building AI assistants with tools

Using ToyAIKit to create AI assistants with custom tools and interactive chat interfaces.

Libraries: toyaikit, openai

anthropic

LLM API Cost Tracker

Track and calculate LLM API costs per model with JSONL logging and usage summaries.

Libraries:

api

OpenAI Responses API — accessing function calls, messages, and usage

Examples showing how to call the Responses API, read function call outputs, inspect returned messages, and examine usage metadata.

Libraries: openai

assistant

ToyAIKit — building AI assistants with tools

Using ToyAIKit to create AI assistants with custom tools and interactive chat interfaces.

Libraries: toyaikit, openai

async

OpenAI Agents SDK — basic agent and runner

Using the OpenAI Agents SDK to create agents with tools and run them with the basic Runner class.

Libraries: agents

ToyAIKit with Pydantic AI

Using ToyAIKit with Pydantic AI to create type-safe agents with structured tools and async chat interfaces.

Libraries: toyaikit, pydantic_ai

ToyAIKit with OpenAI Agents SDK

Using ToyAIKit with the OpenAI Agents SDK to create persistent agents with tools and async chat interfaces.

Libraries: toyaikit, agents

asyncio

Async Message Batch Queue

Queue messages and send them in batches at regular intervals to avoid rate limits.

Async map with progress (tqdm) for asyncio

Run an async function over a sequence with concurrency limiting via asyncio.Semaphore while displaying a tqdm progress bar.

Libraries: tqdm

callbacks

ToyAIKit custom callbacks

Creating custom callback classes by extending RunnerCallback to handle function calls, messages, and responses in ToyAIKit runners.

Libraries: toyaikit

ToyAIKit loops with callbacks and cost tracking

Using ToyAIKit callbacks to display intermediate results and track API costs in OpenAI Responses runner.

Libraries: toyaikit

chat

ToyAIKit — building AI assistants with tools

Using ToyAIKit to create AI assistants with custom tools and interactive chat interfaces.

Libraries: toyaikit, openai

ci

Deploy Jekyll site to GitHub Pages (subfolder-aware)

A GitHub Actions workflow that builds a Jekyll site and deploys it to GitHub Pages, handling base paths for subfolder deployments.

Libraries:

concurrency

Async Message Batch Queue

Queue messages and send them in batches at regular intervals to avoid rate limits.

Async map with progress (tqdm) for asyncio

Run an async function over a sequence with concurrency limiting via asyncio.Semaphore while displaying a tqdm progress bar.

Libraries: tqdm

Map with progress (tqdm) for concurrent.futures

Run a function over a sequence using ThreadPoolExecutor while displaying a tqdm progress bar.

Libraries: tqdm

cost-tracking

LLM API Cost Tracker

Track and calculate LLM API costs per model with JSONL logging and usage summaries.

Libraries:

ToyAIKit loops with callbacks and cost tracking

Using ToyAIKit callbacks to display intermediate results and track API costs in OpenAI Responses runner.

Libraries: toyaikit

dependencies

Adding editable file system dependencies with uv

How to add ediable local path dependencies and editable installations using uv package manager.

Libraries: uv

devops

Dockerfile for Python Service with UV

Production Dockerfile using UV for fast dependency installation and slim base image.

Python Project Makefile

Makefile with targets for testing, linting, formatting, Docker build, and integration tests.

docker

Dockerfile for Python Service with UV

Production Dockerfile using UV for fast dependency installation and slim base image.

function-calls

OpenAI Responses API — accessing function calls, messages, and usage

Examples showing how to call the Responses API, read function call outputs, inspect returned messages, and examine usage metadata.

Libraries: openai

github-actions

Deploy Jekyll site to GitHub Pages (subfolder-aware)

A GitHub Actions workflow that builds a Jekyll site and deploys it to GitHub Pages, handling base paths for subfolder deployments.

Libraries:

jekyll

Deploy Jekyll site to GitHub Pages (subfolder-aware)

A GitHub Actions workflow that builds a Jekyll site and deploys it to GitHub Pages, handling base paths for subfolder deployments.

Libraries:

llm

LLM API Cost Tracker

Track and calculate LLM API costs per model with JSONL logging and usage summaries.

Libraries:

makefile

Python Project Makefile

Makefile with targets for testing, linting, formatting, Docker build, and integration tests.

openai

LLM API Cost Tracker

Track and calculate LLM API costs per model with JSONL logging and usage summaries.

Libraries:

OpenAI Agents SDK — basic agent and runner

Using the OpenAI Agents SDK to create agents with tools and run them with the basic Runner class.

Libraries: agents

OpenAI Responses API — accessing function calls, messages, and usage

Examples showing how to call the Responses API, read function call outputs, inspect returned messages, and examine usage metadata.

Libraries: openai

packaging

Adding editable file system dependencies with uv

How to add ediable local path dependencies and editable installations using uv package manager.

Libraries: uv

pages

Deploy Jekyll site to GitHub Pages (subfolder-aware)

A GitHub Actions workflow that builds a Jekyll site and deploys it to GitHub Pages, handling base paths for subfolder deployments.

Libraries:

progress

Async map with progress (tqdm) for asyncio

Run an async function over a sequence with concurrency limiting via asyncio.Semaphore while displaying a tqdm progress bar.

Libraries: tqdm

Map with progress (tqdm) for concurrent.futures

Run a function over a sequence using ThreadPoolExecutor while displaying a tqdm progress bar.

Libraries: tqdm

pydantic

Pydantic AI — streaming display with Rich

Display streaming agent execution using a Rich console while iterating over agent events.

Libraries: pydantic_ai, rich

ToyAIKit with Pydantic AI

Using ToyAIKit with Pydantic AI to create type-safe agents with structured tools and async chat interfaces.

Libraries: toyaikit, pydantic_ai

Pydantic Discriminated Unions

Use Literal type discriminators to model polymorphic block types with Pydantic.

Libraries: pydantic

python

Async Message Batch Queue

Queue messages and send them in batches at regular intervals to avoid rate limits.

Async map with progress (tqdm) for asyncio

Run an async function over a sequence with concurrency limiting via asyncio.Semaphore while displaying a tqdm progress bar.

Libraries: tqdm

Dockerfile for Python Service with UV

Production Dockerfile using UV for fast dependency installation and slim base image.

LLM API Cost Tracker

Track and calculate LLM API costs per model with JSONL logging and usage summaries.

Libraries:

Pydantic Discriminated Unions

Use Literal type discriminators to model polymorphic block types with Pydantic.

Libraries: pydantic

Python Project Makefile

Makefile with targets for testing, linting, formatting, Docker build, and integration tests.

Map with progress (tqdm) for concurrent.futures

Run a function over a sequence using ThreadPoolExecutor while displaying a tqdm progress bar.

Libraries: tqdm

Adding editable file system dependencies with uv

How to add ediable local path dependencies and editable installations using uv package manager.

Libraries: uv

rate-limiting

Async Message Batch Queue

Queue messages and send them in batches at regular intervals to avoid rate limits.

streaming

Pydantic AI — streaming display with Rich

Display streaming agent execution using a Rich console while iterating over agent events.

Libraries: pydantic_ai, rich

structured-output

Pydantic Discriminated Unions

Use Literal type discriminators to model polymorphic block types with Pydantic.

Libraries: pydantic

testing

Python Project Makefile

Makefile with targets for testing, linting, formatting, Docker build, and integration tests.

threading

Map with progress (tqdm) for concurrent.futures

Run a function over a sequence using ThreadPoolExecutor while displaying a tqdm progress bar.

Libraries: tqdm

tools

ToyAIKit with Pydantic AI

Using ToyAIKit with Pydantic AI to create type-safe agents with structured tools and async chat interfaces.

Libraries: toyaikit, pydantic_ai

ToyAIKit with OpenAI Agents SDK

Using ToyAIKit with the OpenAI Agents SDK to create persistent agents with tools and async chat interfaces.

Libraries: toyaikit, agents

ToyAIKit — building AI assistants with tools

Using ToyAIKit to create AI assistants with custom tools and interactive chat interfaces.

Libraries: toyaikit, openai

toyaikit

ToyAIKit custom callbacks

Creating custom callback classes by extending RunnerCallback to handle function calls, messages, and responses in ToyAIKit runners.

Libraries: toyaikit

ToyAIKit loops with callbacks and cost tracking

Using ToyAIKit callbacks to display intermediate results and track API costs in OpenAI Responses runner.

Libraries: toyaikit

uv

Dockerfile for Python Service with UV

Production Dockerfile using UV for fast dependency installation and slim base image.

Adding editable file system dependencies with uv

How to add ediable local path dependencies and editable installations using uv package manager.

Libraries: uv