Skip to main content

Runnable Examples Index

The fastest way to feel Dhenara’s “goodness” is to run the examples and inspect the artifacts.

All scripts live in:

  • packages/dhenara_ai/examples/

The GitHub links in this page point to the canonical dhenara-ai repo, where the same examples live at examples/.

How to run

From the repo root:

cd packages/dhenara_ai

# If you're using pip, create/activate a venv and install the package first.
# Example (macOS/Linux):
# python -m venv .venv
# source .venv/bin/activate
# pip install -e .

# run an example
python examples/19_streaming_multi_turn_structured_thinking.py

If you use uv, the simplest workflow is to sync the repo once and then run everything via uv run (no manual activation needed):

cd packages/dhenara_ai

uv sync
uv run python examples/19_streaming_multi_turn_structured_thinking.py

Most examples use the shared config helpers under packages/dhenara_ai/examples/include/.

If you only run a few scripts, run these first:

  1. Streaming + multi-turn + structured output + reasoning + validation
    • 19_streaming_multi_turn_structured_thinking.py
  2. Streaming + tools + structured output (end-to-end workflow)
    • 18_streaming_multi_turn_with_tools_and_structured_output.py
  3. Multi-turn tools with correct Messages API history
    • 16_multi_turn_with_tools_and_messages_api.py
  4. Structured output basics (Pydantic)
    • 21_structed_output.py

Capability map

You want to learnRun thisWhat to look for
Provider-agnostic text generation01_text_generation.pySame .generate() shape across providers
Streaming response handling02_text_streaming.pyToken deltas + final accumulated response
Input styles (prompt/context/messages)10_various_input_formats.pyMigration-friendly request shapes
Multi-turn via ResourceConfig12_multi_turn_with_resouce_config.pyEndpoint switching without changing app code
Streaming multi-turn via ResourceConfig13_streaming_multi_turn_with_resouce_config.pyStreaming loop + final response per turn
Async streaming multi-turn13_async_streaming_multi_turn_with_resouce_config.pyAsync generator semantics
Messages API multi-turn (recommended)14_multi_turn_with_messages_api.pymessages history + to_message_item()
Streaming + Messages API15_streaming_multi_turn_with_messages_api.pyStreaming with message history preserved
Tools + Messages API (correct tool loop)16_multi_turn_with_tools_and_messages_api.pyToolCallResult and call_id handling
Structured output + Messages API17_multi_turn_with_structured_output_and_messages_api.pyTyped schema per turn
Streaming + tools + structured output18_streaming_multi_turn_with_tools_and_structured_output.pyReal workflow pattern: stream + tool calls + typed output
“The goodness” recipe (stream + multi-turn + typed + reasoning + validation)19_streaming_multi_turn_structured_thinking.pyValidation-driven loop + artifacts per call
Function calling API surface20_fn_calling.pyToolDefinition.from_callable + ToolChoice
Structured output quickstart21_structed_output.pystructured_output=<Pydantic model> + chat.structured()
Images30_image_openai.py, 31_image_with_resource_config.py, 32_image_with_messages_and_text.pyUnified image response handling
Cross-provider structured output sanity check91_all_providers_structured_simple_test.pyProvider normalization differences
OpenAI reasoning knobs98_openai_reasoing.pyreasoning_effort + reasoning mode behavior
OpenAI tool calling specifics99_openai_toolcall.pyProvider-specific edge cases

Docs that match these examples