From 708298b4fc84127006e77951e0164fe56b2bf4dd Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Thu, 23 Jan 2025 15:46:23 -0600 Subject: [PATCH] fix: Add Google Search example to MM Live API Notebook --- .../intro_multimodal_live_api_genai_sdk.ipynb | 54 +++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/gemini/multimodal-live-api/intro_multimodal_live_api_genai_sdk.ipynb b/gemini/multimodal-live-api/intro_multimodal_live_api_genai_sdk.ipynb index 08fb0f2d409..6b8c958c40d 100644 --- a/gemini/multimodal-live-api/intro_multimodal_live_api_genai_sdk.ipynb +++ b/gemini/multimodal-live-api/intro_multimodal_live_api_genai_sdk.ipynb @@ -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" + ] + }, + { + "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", + " )\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": {