Skip to content

Commit 346fbed

Browse files
feat: Update Google Gemini tracing example and enhance model name handling
1 parent 86e65d2 commit 346fbed

2 files changed

Lines changed: 213 additions & 107 deletions

File tree

examples/tracing/google-gemini/gemini_tracing.ipynb

Lines changed: 94 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,95 @@
1515
},
1616
{
1717
"cell_type": "code",
18-
"execution_count": null,
18+
"execution_count": 1,
1919
"id": "020c8f6a",
2020
"metadata": {},
21-
"outputs": [],
21+
"outputs": [
22+
{
23+
"name": "stdout",
24+
"output_type": "stream",
25+
"text": [
26+
"Collecting google-generativeai\n",
27+
" Using cached google_generativeai-0.8.5-py3-none-any.whl.metadata (3.9 kB)\n",
28+
"Requirement already satisfied: openlayer in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (0.8.1)\n",
29+
"Collecting google-ai-generativelanguage==0.6.15 (from google-generativeai)\n",
30+
" Using cached google_ai_generativelanguage-0.6.15-py3-none-any.whl.metadata (5.7 kB)\n",
31+
"Requirement already satisfied: google-api-core in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-generativeai) (2.28.1)\n",
32+
"Requirement already satisfied: google-api-python-client in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-generativeai) (2.187.0)\n",
33+
"Requirement already satisfied: google-auth>=2.15.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-generativeai) (2.43.0)\n",
34+
"Requirement already satisfied: protobuf in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-generativeai) (6.33.1)\n",
35+
"Requirement already satisfied: pydantic in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-generativeai) (2.12.4)\n",
36+
"Requirement already satisfied: tqdm in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-generativeai) (4.67.1)\n",
37+
"Requirement already satisfied: typing-extensions in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-generativeai) (4.15.0)\n",
38+
"Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-ai-generativelanguage==0.6.15->google-generativeai) (1.26.1)\n",
39+
"Collecting protobuf (from google-generativeai)\n",
40+
" Using cached protobuf-5.29.5-cp38-abi3-macosx_10_9_universal2.whl.metadata (592 bytes)\n",
41+
"Requirement already satisfied: anyio<5,>=3.5.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from openlayer) (4.11.0)\n",
42+
"Requirement already satisfied: distro<2,>=1.7.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from openlayer) (1.9.0)\n",
43+
"Requirement already satisfied: httpx<1,>=0.23.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from openlayer) (0.28.1)\n",
44+
"Requirement already satisfied: pandas in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from openlayer) (2.3.3)\n",
45+
"Requirement already satisfied: pyarrow>=18.0.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from openlayer) (22.0.0)\n",
46+
"Requirement already satisfied: pyyaml>=6.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from openlayer) (6.0.3)\n",
47+
"Requirement already satisfied: requests-toolbelt>=1.0.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from openlayer) (1.0.0)\n",
48+
"Requirement already satisfied: sniffio in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from openlayer) (1.3.1)\n",
49+
"Requirement already satisfied: wrapt>=1.14.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from openlayer) (2.0.1)\n",
50+
"Requirement already satisfied: idna>=2.8 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from anyio<5,>=3.5.0->openlayer) (3.11)\n",
51+
"Requirement already satisfied: googleapis-common-protos<2.0.0,>=1.56.2 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-api-core->google-generativeai) (1.72.0)\n",
52+
"Requirement already satisfied: requests<3.0.0,>=2.18.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-api-core->google-generativeai) (2.32.5)\n",
53+
"Requirement already satisfied: cachetools<7.0,>=2.0.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-auth>=2.15.0->google-generativeai) (6.2.2)\n",
54+
"Requirement already satisfied: pyasn1-modules>=0.2.1 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-auth>=2.15.0->google-generativeai) (0.4.2)\n",
55+
"Requirement already satisfied: rsa<5,>=3.1.4 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-auth>=2.15.0->google-generativeai) (4.9.1)\n",
56+
"Requirement already satisfied: certifi in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openlayer) (2025.11.12)\n",
57+
"Requirement already satisfied: httpcore==1.* in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openlayer) (1.0.9)\n",
58+
"Requirement already satisfied: h11>=0.16 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openlayer) (0.16.0)\n",
59+
"Requirement already satisfied: annotated-types>=0.6.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from pydantic->google-generativeai) (0.7.0)\n",
60+
"Requirement already satisfied: pydantic-core==2.41.5 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from pydantic->google-generativeai) (2.41.5)\n",
61+
"Requirement already satisfied: typing-inspection>=0.4.2 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from pydantic->google-generativeai) (0.4.2)\n",
62+
"Requirement already satisfied: httplib2<1.0.0,>=0.19.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-api-python-client->google-generativeai) (0.31.0)\n",
63+
"Requirement already satisfied: google-auth-httplib2<1.0.0,>=0.2.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-api-python-client->google-generativeai) (0.2.1)\n",
64+
"Requirement already satisfied: uritemplate<5,>=3.0.1 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-api-python-client->google-generativeai) (4.2.0)\n",
65+
"Requirement already satisfied: numpy>=1.26.0 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from pandas->openlayer) (2.3.5)\n",
66+
"Requirement already satisfied: python-dateutil>=2.8.2 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from pandas->openlayer) (2.9.0.post0)\n",
67+
"Requirement already satisfied: pytz>=2020.1 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from pandas->openlayer) (2025.2)\n",
68+
"Requirement already satisfied: tzdata>=2022.7 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from pandas->openlayer) (2025.2)\n",
69+
"Requirement already satisfied: grpcio<2.0.0,>=1.33.2 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.10.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,<3.0.0dev,>=1.34.1->google-ai-generativelanguage==0.6.15->google-generativeai) (1.76.0)\n",
70+
"Requirement already satisfied: grpcio-status<2.0.0,>=1.33.2 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.10.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,<3.0.0dev,>=1.34.1->google-ai-generativelanguage==0.6.15->google-generativeai) (1.76.0)\n",
71+
"Requirement already satisfied: pyparsing<4,>=3.0.4 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from httplib2<1.0.0,>=0.19.0->google-api-python-client->google-generativeai) (3.2.5)\n",
72+
"Requirement already satisfied: pyasn1<0.7.0,>=0.6.1 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from pyasn1-modules>=0.2.1->google-auth>=2.15.0->google-generativeai) (0.6.1)\n",
73+
"Requirement already satisfied: six>=1.5 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from python-dateutil>=2.8.2->pandas->openlayer) (1.17.0)\n",
74+
"Requirement already satisfied: charset_normalizer<4,>=2 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from requests<3.0.0,>=2.18.0->google-api-core->google-generativeai) (3.4.4)\n",
75+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/vini/Workspace/Openlayer/integrations-sdks/openlayer-python/.venv/lib/python3.12/site-packages (from requests<3.0.0,>=2.18.0->google-api-core->google-generativeai) (2.5.0)\n",
76+
"INFO: pip is looking at multiple versions of grpcio-status to determine which version is compatible with other requirements. This could take a while.\n",
77+
"Collecting grpcio-status<2.0.0,>=1.33.2 (from google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.10.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,<3.0.0dev,>=1.34.1->google-ai-generativelanguage==0.6.15->google-generativeai)\n",
78+
" Using cached grpcio_status-1.75.1-py3-none-any.whl.metadata (1.1 kB)\n",
79+
" Using cached grpcio_status-1.75.0-py3-none-any.whl.metadata (1.1 kB)\n",
80+
" Using cached grpcio_status-1.74.0-py3-none-any.whl.metadata (1.1 kB)\n",
81+
" Using cached grpcio_status-1.73.1-py3-none-any.whl.metadata (1.1 kB)\n",
82+
" Using cached grpcio_status-1.73.0-py3-none-any.whl.metadata (1.1 kB)\n",
83+
" Using cached grpcio_status-1.72.2-py3-none-any.whl.metadata (1.1 kB)\n",
84+
" Using cached grpcio_status-1.72.1-py3-none-any.whl.metadata (1.1 kB)\n",
85+
"INFO: pip is still looking at multiple versions of grpcio-status to determine which version is compatible with other requirements. This could take a while.\n",
86+
" Using cached grpcio_status-1.71.2-py3-none-any.whl.metadata (1.1 kB)\n",
87+
"Using cached google_generativeai-0.8.5-py3-none-any.whl (155 kB)\n",
88+
"Using cached google_ai_generativelanguage-0.6.15-py3-none-any.whl (1.3 MB)\n",
89+
"Using cached protobuf-5.29.5-cp38-abi3-macosx_10_9_universal2.whl (418 kB)\n",
90+
"Using cached grpcio_status-1.71.2-py3-none-any.whl (14 kB)\n",
91+
"Installing collected packages: protobuf, grpcio-status, google-ai-generativelanguage, google-generativeai\n",
92+
" Attempting uninstall: protobuf\n",
93+
" Found existing installation: protobuf 6.33.1\n",
94+
" Uninstalling protobuf-6.33.1:\n",
95+
" Successfully uninstalled protobuf-6.33.1\n",
96+
" Attempting uninstall: grpcio-status\n",
97+
" Found existing installation: grpcio-status 1.76.0\n",
98+
" Uninstalling grpcio-status-1.76.0:\n",
99+
" Successfully uninstalled grpcio-status-1.76.0\n",
100+
"Successfully installed google-ai-generativelanguage-0.6.15 google-generativeai-0.8.5 grpcio-status-1.71.2 protobuf-5.29.5\n",
101+
"\n",
102+
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.3\u001b[0m\n",
103+
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
104+
]
105+
}
106+
],
22107
"source": [
23108
"!pip install google-generativeai openlayer"
24109
]
@@ -43,11 +128,11 @@
43128
"import google.generativeai as genai\n",
44129
"\n",
45130
"# Gemini API key\n",
46-
"os.environ[\"GOOGLE_API_KEY\"] = \"YOUR_GOOGLE_API_KEY_HERE\"\n",
131+
"os.environ[\"GOOGLE_AI_API_KEY\"] = \"AIzaSyA8wPnrtcHw7840GqhVgvKFAqBiQ0hgd9g\"\n",
47132
"\n",
48133
"# Openlayer env variables\n",
49-
"os.environ[\"OPENLAYER_API_KEY\"] = \"YOUR_OPENLAYER_API_KEY_HERE\"\n",
50-
"os.environ[\"OPENLAYER_INFERENCE_PIPELINE_ID\"] = \"YOUR_OPENLAYER_INFERENCE_PIPELINE_ID_HERE\""
134+
"os.environ[\"OPENLAYER_API_KEY\"] = \"sk-ol-WTyjVITCUUQ_LhOQmwmG6f_va9WjNuz7\"\n",
135+
"os.environ[\"OPENLAYER_INFERENCE_PIPELINE_ID\"] = \"c2c6a731-6fc4-49cb-b0c9-51cd3956088c\""
51136
]
52137
},
53138
{
@@ -67,7 +152,7 @@
67152
"source": [
68153
"from openlayer.lib import trace_gemini\n",
69154
"\n",
70-
"genai.configure(api_key=os.environ[\"GOOGLE_API_KEY\"])\n",
155+
"genai.configure(api_key=os.environ[\"GOOGLE_AI_API_KEY\"])\n",
71156
"\n",
72157
"model = genai.GenerativeModel(\"gemini-pro\")\n",
73158
"traced_model = trace_gemini(model)"
@@ -135,7 +220,7 @@
135220
"response = traced_model.generate_content(\"Tell me a short story.\", stream=True)\n",
136221
"\n",
137222
"for chunk in response:\n",
138-
" if hasattr(chunk, 'text'):\n",
223+
" if hasattr(chunk, \"text\"):\n",
139224
" continue # Process chunks as needed"
140225
]
141226
},
@@ -209,7 +294,7 @@
209294
],
210295
"metadata": {
211296
"kernelspec": {
212-
"display_name": "Python 3 (ipykernel)",
297+
"display_name": ".venv",
213298
"language": "python",
214299
"name": "python3"
215300
},
@@ -223,7 +308,7 @@
223308
"name": "python",
224309
"nbconvert_exporter": "python",
225310
"pygments_lexer": "ipython3",
226-
"version": "3.9.18"
311+
"version": "3.12.8"
227312
}
228313
},
229314
"nbformat": 4,

0 commit comments

Comments
 (0)