diff --git a/py/packages/genkit/tests/genkit/blocks/prompt_test.py b/py/packages/genkit/tests/genkit/blocks/prompt_test.py index 2d73f48353..6fb58abcda 100644 --- a/py/packages/genkit/tests/genkit/blocks/prompt_test.py +++ b/py/packages/genkit/tests/genkit/blocks/prompt_test.py @@ -274,7 +274,7 @@ async def test_load_nested_prompt() -> None: with tempfile.TemporaryDirectory() as tmpdir: prompt_dir = Path(tmpdir) / 'prompts' prompt_dir.mkdir() - + # Create subdirectory sub_dir = prompt_dir / 'admin' sub_dir.mkdir() @@ -289,12 +289,11 @@ async def test_load_nested_prompt() -> None: # Based on logic: name = "admin/dashboard" admin_exec = await prompt(ai.registry, 'admin/dashboard') response = await admin_exec({'name': 'SuperUser'}) - + assert 'Welcome Admin' in response.text assert 'SuperUser' in response.text - @pytest.mark.asyncio async def test_load_and_use_partial() -> None: """Test loading and using partials in prompts.""" diff --git a/py/samples/google-genai-hello/README.md b/py/samples/google-genai-hello/README.md index 3f1e8b1f77..67bcd37b4c 100644 --- a/py/samples/google-genai-hello/README.md +++ b/py/samples/google-genai-hello/README.md @@ -18,3 +18,27 @@ export GEMINI_API_KEY='' ```bash genkit start -- uv run src/google_genai_hello.py ``` + +### Testing GCP telemetry + +To test Google Cloud Platform telemetry (tracing and metrics), you need a GCP project and valid credentials. + +1. **Enable APIs**: Go to the [Google Cloud Console](https://console.cloud.google.com/) and enable the following APIs for your project: + - [Cloud Monitoring API](https://console.cloud.google.com/marketplace/product/google/monitoring.googleapis.com) + - [Cloud Trace API](https://console.cloud.google.com/marketplace/product/google/cloudtrace.googleapis.com) + +2. **Authenticate**: Set up Application Default Credentials (ADC). + ```bash + gcloud config set project + gcloud auth application-default login + ``` + + Choose the "Select All" option to select all requested permissions before + proceeding so that the authentication process can complete successfully. + Otherwise, you may run into a lot of HTTP 503 service unavailable or + `invalid_grant` errors. + +3. **Run with Telemetry**: + ```bash + genkit start -- uv run src/google_genai_hello.py --enable-gcp-telemetry + ``` diff --git a/py/samples/google-genai-hello/src/google_genai_hello.py b/py/samples/google-genai-hello/src/google_genai_hello.py index 949e0e52dd..66d77bc31f 100644 --- a/py/samples/google-genai-hello/src/google_genai_hello.py +++ b/py/samples/google-genai-hello/src/google_genai_hello.py @@ -42,7 +42,7 @@ """ -import os +import argparse import structlog from pydantic import BaseModel, Field @@ -69,7 +69,7 @@ ) logger = structlog.get_logger(__name__) -add_gcp_telemetry() + ai = Genkit( plugins=[ @@ -340,4 +340,13 @@ async def main() -> None: if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Google GenAI Hello Sample') + parser.add_argument( + '--enable-gcp-telemetry', + action='store_true', + help='Enable Google Cloud Platform telemetry', + ) + args = parser.parse_args() + if args.enable_gcp_telemetry: + add_gcp_telemetry() ai.run_main(main())