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
5 changes: 2 additions & 3 deletions py/packages/genkit/tests/genkit/blocks/prompt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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."""
Expand Down
24 changes: 24 additions & 0 deletions py/samples/google-genai-hello/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,27 @@ export GEMINI_API_KEY='<Your 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 <your-gcp-project-id>
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
```
13 changes: 11 additions & 2 deletions py/samples/google-genai-hello/src/google_genai_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

"""

import os
import argparse

import structlog
from pydantic import BaseModel, Field
Expand All @@ -69,7 +69,7 @@
)

logger = structlog.get_logger(__name__)
add_gcp_telemetry()


ai = Genkit(
plugins=[
Expand Down Expand Up @@ -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())
Loading