-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Add Google Search example to MM Live API Notebook #1652
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -106,6 +106,7 @@ | |||||||||||||
"- Text-to-audio conversation\n", | ||||||||||||||
"- Function calling\n", | ||||||||||||||
"- Code execution\n", | ||||||||||||||
"- Google Search\n", | ||||||||||||||
"\n", | ||||||||||||||
"See the [Multimodal Live API](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/multimodal-live) page for more details." | ||||||||||||||
] | ||||||||||||||
|
@@ -177,7 +178,7 @@ | |||||||||||||
}, | ||||||||||||||
{ | ||||||||||||||
"cell_type": "code", | ||||||||||||||
"execution_count": null, | ||||||||||||||
"execution_count": 2, | ||||||||||||||
"metadata": { | ||||||||||||||
"id": "xBCH3hnAX9Bh" | ||||||||||||||
}, | ||||||||||||||
|
@@ -189,6 +190,7 @@ | |||||||||||||
"from google import genai\n", | ||||||||||||||
"from google.genai.types import (\n", | ||||||||||||||
" FunctionDeclaration,\n", | ||||||||||||||
" GoogleSearch,\n", | ||||||||||||||
" LiveConnectConfig,\n", | ||||||||||||||
" PrebuiltVoiceConfig,\n", | ||||||||||||||
" SpeechConfig,\n", | ||||||||||||||
|
@@ -214,7 +216,7 @@ | |||||||||||||
}, | ||||||||||||||
{ | ||||||||||||||
"cell_type": "code", | ||||||||||||||
"execution_count": null, | ||||||||||||||
"execution_count": 3, | ||||||||||||||
"metadata": { | ||||||||||||||
"id": "Nqwi-5ufWp_B" | ||||||||||||||
}, | ||||||||||||||
|
@@ -229,7 +231,7 @@ | |||||||||||||
}, | ||||||||||||||
{ | ||||||||||||||
"cell_type": "code", | ||||||||||||||
"execution_count": null, | ||||||||||||||
"execution_count": 4, | ||||||||||||||
"metadata": { | ||||||||||||||
"id": "T-tiytzQE0uM" | ||||||||||||||
}, | ||||||||||||||
|
@@ -251,7 +253,7 @@ | |||||||||||||
}, | ||||||||||||||
{ | ||||||||||||||
"cell_type": "code", | ||||||||||||||
"execution_count": null, | ||||||||||||||
"execution_count": 5, | ||||||||||||||
"metadata": { | ||||||||||||||
"id": "-coEslfWPrxo" | ||||||||||||||
}, | ||||||||||||||
|
@@ -577,6 +579,50 @@ | |||||||||||||
" display(Markdown(f\"**Response >** {''.join(response)}\"))" | ||||||||||||||
] | ||||||||||||||
}, | ||||||||||||||
{ | ||||||||||||||
"cell_type": "markdown", | ||||||||||||||
"metadata": { | ||||||||||||||
"id": "73660342318d" | ||||||||||||||
}, | ||||||||||||||
"source": [ | ||||||||||||||
"### **Example 6**: Google Search\n", | ||||||||||||||
"\n", | ||||||||||||||
"The `google_search` tool lets the model conduct Google searches. For example, try asking it about events that are too recent to be in the training data.\n" | ||||||||||||||
Comment on lines
+588
to
+590
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example query in this section could be more specific. Instead of asking about a general earthquake, consider asking about a specific event or aspect related to a recent earthquake. This would better demonstrate the tool's ability to retrieve real-time information. For example, you could ask "What were the initial reported damages from the earthquake?" or "Were there any aftershocks reported following the main earthquake?"
Suggested change
|
||||||||||||||
] | ||||||||||||||
}, | ||||||||||||||
{ | ||||||||||||||
"cell_type": "code", | ||||||||||||||
"execution_count": null, | ||||||||||||||
"metadata": { | ||||||||||||||
"id": "e64fc3a94d49" | ||||||||||||||
}, | ||||||||||||||
"outputs": [], | ||||||||||||||
"source": [ | ||||||||||||||
"config = LiveConnectConfig(\n", | ||||||||||||||
" response_modalities=[\"TEXT\"],\n", | ||||||||||||||
" tools=[Tool(google_search=GoogleSearch())],\n", | ||||||||||||||
")\n", | ||||||||||||||
"\n", | ||||||||||||||
"async with client.aio.live.connect(\n", | ||||||||||||||
" model=MODEL_ID,\n", | ||||||||||||||
" config=config,\n", | ||||||||||||||
") as session:\n", | ||||||||||||||
" text_input = (\n", | ||||||||||||||
" \"Tell me about the largest earthquake in California the week of Dec 5 2024?\"\n", | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in the previous comment, consider making the example query more specific. For instance, instead of asking about the largest earthquake in general, try asking about a specific detail, such as the magnitude or the epicenter of the earthquake. This would better illustrate the tool's ability to retrieve precise information. For example, you could ask "What was the magnitude and epicenter of the largest earthquake in California during the week of December 5, 2024?"
Suggested change
|
||||||||||||||
" )\n", | ||||||||||||||
" display(Markdown(f\"**Input:** {text_input}\"))\n", | ||||||||||||||
"\n", | ||||||||||||||
" await session.send(input=text_input, end_of_turn=True)\n", | ||||||||||||||
"\n", | ||||||||||||||
" response = []\n", | ||||||||||||||
"\n", | ||||||||||||||
" async for message in session.receive():\n", | ||||||||||||||
" if message.text:\n", | ||||||||||||||
" response.append(message.text)\n", | ||||||||||||||
"\n", | ||||||||||||||
" display(Markdown(f\"**Response >** {''.join(response)}\"))" | ||||||||||||||
] | ||||||||||||||
}, | ||||||||||||||
{ | ||||||||||||||
"cell_type": "markdown", | ||||||||||||||
"metadata": { | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a brief explanation of what the Google Search tool does in this overview. For example, you could add a sentence like "The Google Search tool allows the model to access and process real-time information from the web."