-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathgemini_instrumentation.py
More file actions
46 lines (34 loc) · 1.27 KB
/
gemini_instrumentation.py
File metadata and controls
46 lines (34 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Gemini auto-instrumentation example with Value SDK."""
import os
from dotenv import load_dotenv
load_dotenv()
from value import initialize_sync
from value.instrumentation import auto_instrument
from google import genai
# Get agent secret from environment variable
AGENT_SECRET = os.getenv("VALUE_AGENT_SECRET", "your-agent-secret")
client = initialize_sync(agent_secret=AGENT_SECRET)
auto_instrument(["gemini"])
api_key = os.getenv("GOOGLE_API_KEY")
if not api_key:
print("Error: GOOGLE_API_KEY not set in environment")
exit(1)
gemini_client = genai.Client(api_key=api_key)
model = "gemini-2.5-flash"
prompt = "Write a short, fun poem about tracing."
print(f"Making call to {model}...")
try:
with client.action_context(user_id="user123", anonymous_id="anon456") as ctx:
response = gemini_client.models.generate_content(model=model, contents=[prompt])
ctx.send(
action_name="process_gemini_response",
**{
"value.action.description": f"Received response from {model}",
"model": model,
"response_length": len(response.text),
"prompt_type": "creative_writing",
},
)
print(f"\n{response.text}")
except Exception as e:
print(f"Error: {e}")