diff --git a/examples/README.md b/examples/README.md
index 9bf51af08..8e224bb35 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -23,7 +23,7 @@ This is a collection of fun examples for the Gemini API.
* [Translate a public domain](./Translate_a_Public_Domain_Book.ipynb): In this notebook, you will explore Gemini model as a translation tool, demonstrating how to prepare data, create effective prompts, and save results into a `.txt` file.
* [Working with Charts, Graphs, and Slide Decks](./Working_with_Charts_Graphs_and_Slide_Decks.ipynb): Gemini models are powerful multimodal LLMs that can process both text and image inputs. This notebook shows how Gemini 1.5 Flash model is capable of extracting data from various images.
* [Entity extraction](./Entity_Extraction.ipynb): Use Gemini API to speed up some of your tasks, such as searching through text to extract needed information. Entity extraction with a Gemini model is a simple query, and you can ask it to retrieve its answer in the form that you prefer.
-* [Generate a company research report using search grounding](./search_grounding_for_research_report.ipynb): Use search grounding to write a company research report with Gemini 1.5 Flash.
+* [Generate a company research report using search grounding](./Search_grounding_for_research_report.ipynb): Use search grounding to write a company research report with Gemini 1.5 Flash.
### Integrations
diff --git a/examples/search_grounding_for_research_report.ipynb b/examples/Search_grounding_for_research_report.ipynb
similarity index 97%
rename from examples/search_grounding_for_research_report.ipynb
rename to examples/Search_grounding_for_research_report.ipynb
index 1854bda9b..80cfd4a5c 100644
--- a/examples/search_grounding_for_research_report.ipynb
+++ b/examples/Search_grounding_for_research_report.ipynb
@@ -48,7 +48,7 @@
"source": [
"
"
]
@@ -61,9 +61,9 @@
"source": [
"In this tutorial you are going to leverage the [grounding-with-Google-Search](https://ai.google.dev/gemini-api/docs/grounding) capability of the Gemini 1.5 model to write a company report. Note that search grounding is a paid ony feature and this tutorial does not work with a free tier API key.\n",
"\n",
- "You may be asking, why does one need to use the search tool for this purpose? Well, as you may be aware, today's business world evolves very fast and LLMs generally are not trained frequently enough to capture the latest updates. Luckily Google search comes to the rescue. Google search is built to provide accurate and nearly realtime information and can help us fulfill this task nicely.\n",
+ "You may be asking, why does one need to use search grounding for this purpose? Well, as you may be aware, today's business world evolves very fast and LLMs generally are not trained frequently enough to capture the latest updates. Luckily Google search comes to the rescue. Google search is built to provide accurate and nearly realtime information and can help us fulfill this task nicely.\n",
"\n",
- "Note that the latest [search tool](https://ai.google.dev/gemini-api/docs/models/gemini-v2#search-tool) that comes with Gemini 2.0 is much easier to use and should be prioritized over search grounding in Gemini 1.5 models."
+ "Note that the latest [search tool](https://ai.google.dev/gemini-api/docs/models/gemini-v2#search-tool) that comes with Gemini 2.0 is much easier to use and should be prioritized over search grounding in Gemini 1.5 models. You can learn more about search tool in the [Search tool quickstart](../main/gemini-2/search_tool.ipynb) notebook and the [search tool for research report](../gemini-2/search_tool_for_research_report.ipynb) notebook which creates the same functionality as in this tutorial but uses search tool in Gemini 2.0."
]
},
{
@@ -341,7 +341,7 @@
"\n",
"Next you define a couple of helper functions to better display the final report.\n",
"\n",
- "Note that You must enable Google Search Suggestions, which help users find search results corresponding to a grounded response, and [display the search queries](https://ai.google.dev/gemini-api/docs/grounding/search-suggestions#display-requirements) that are included in the grounded response's metadata. You can find [more details](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) about this requirement."
+ "Note that you must enable Google Search Suggestions, which help users find search results corresponding to a grounded response, and [display the search queries](https://ai.google.dev/gemini-api/docs/grounding/search-suggestions#display-requirements) that are included in the grounded response's metadata. You can find [more details](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) about this requirement."
]
},
{
@@ -1149,7 +1149,9 @@
"id": "leOZmicAwTSn"
},
"source": [
- "As you can see, the Gemini 1.5 model is able to write an accurate and well-structured research report for us. All the information in the report is factual and up-to-date."
+ "As you can see, the Gemini 1.5 model is able to write an accurate and well-structured research report for us. All the information in the report is factual and up-to-date.\n",
+ "\n",
+ "Note that while this works quite nicely, it still requires multiple steps for the job. With Gemini 2.0, it is much easier and you can accomplish the same with only a single step using the new [search tool](../gemini-2/search_tool_for_research_report.ipynb). "
]
},
{
@@ -1160,15 +1162,16 @@
"source": [
"## Next Steps\n",
"\n",
- "* To learn more about search grounding, check out the [Grounding with Google Search](https://ai.google.dev/gemini-api/docs/grounding?lang=python) documentation\n",
- "* To get started with search grounding, check out the [Search grounding quickstart](../quickstarts/Search_Grounding.ipynb).",
- "* Also check the [Gemini 2.0 search tool](../gemini-2/search_tool.ipynb) notebook for a more recent example."
+ "* To learn more about search grounding, check out the [Grounding with Google Search](https://ai.google.dev/gemini-api/docs/grounding?lang=python) documentation.\n",
+ "* To get started with search grounding, check out the [Search grounding quickstart](../quickstarts/Search_Grounding.ipynb).\n",
+ "* To get started with the search tool in Gemini 2.0, check out the [Search tool quick start](../gemini-2/search_tool.ipynb).\n",
+ "* Also check the [search tool for research report](../gemini-2/search_tool_for_research_report.ipynb) notebook for a more recent example using Gemini 2.0."
]
}
],
"metadata": {
"colab": {
- "name": "search_grounding_for_research_report.ipynb",
+ "name": "Search_grounding_for_research_report.ipynb",
"toc_visible": true
},
"kernelspec": {
diff --git a/gemini-2/README.md b/gemini-2/README.md
index f68accf3e..c1dd85054 100644
--- a/gemini-2/README.md
+++ b/gemini-2/README.md
@@ -13,6 +13,7 @@ Explore Gemini 2.0’s capabilities through the following notebooks using Google
* [Live API tool use](./live_api_tool_use.ipynb) \- Overview of tool use in the Live API with the GenAI SDK
* [Plotting and mapping](./plotting_and_mapping.ipynb) \- Demo showing search, code and function calling with the Live API
* [Search tool](./search_tool.ipynb) \- Quick start using the Search tool with the unary and Live APIs in the GenAI SDK
+* [Search tool for research report](./search_tool_for_research_report.ipynb) \- Demo showing generation of a research report using the search tool with the unary API in the GenAI SDK
* [Spatial understanding](./spatial_understanding.ipynb) \- Comprehensive overview of 2D spatial understanding capabilities with the GenAI SDK
* [Spatial understanding (3D)](./spatial_understanding_3d.ipynb) \- Comprehensive overview of 3D spatial understanding capabilities with the GenAI SDK
* [Video understanding](./video_understanding.ipynb) \- Comprehensive overview Gemini 2.0 video understanding capabilities with the GenAI SDK
diff --git a/gemini-2/search_tool_for_research_report.ipynb b/gemini-2/search_tool_for_research_report.ipynb
new file mode 100644
index 000000000..70fc48bd9
--- /dev/null
+++ b/gemini-2/search_tool_for_research_report.ipynb
@@ -0,0 +1,1170 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "lb5yiH5h8x3h"
+ },
+ "source": [
+ "##### Copyright 2024 Google LLC."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "cellView": "form",
+ "id": "906e07f6e562"
+ },
+ "outputs": [],
+ "source": [
+ "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
+ "# you may not use this file except in compliance with the License.\n",
+ "# You may obtain a copy of the License at\n",
+ "#\n",
+ "# https://www.apache.org/licenses/LICENSE-2.0\n",
+ "#\n",
+ "# Unless required by applicable law or agreed to in writing, software\n",
+ "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
+ "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
+ "# See the License for the specific language governing permissions and\n",
+ "# limitations under the License."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "1YXR7Yn480fU"
+ },
+ "source": [
+ "# Search tool with Gemini 2.0"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "CeJyB7rG82ph"
+ },
+ "source": [
+ "
"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "___eV40o8399"
+ },
+ "source": [
+ "In this tutorial you are going to leverage the latest [search tool](https://ai.google.dev/gemini-api/docs/models/gemini-v2#search-tool) of the Gemini 2.0 model to write a company report. Note that the search tool is a paid ony feature and this tutorial does not work with a free tier API key.\n",
+ "\n",
+ "You may be asking, why does one need to use the search tool for this purpose? Well, as you may be aware, today's business world evolves very fast and LLMs generally are not trained frequently enough to capture the latest updates. Luckily Google search comes to the rescue. Google search is built to provide accurate and nearly realtime information and can help us fulfill this task perfectly.\n",
+ "\n",
+ "Note that while Gemini 1.5 models offer the [search grounding](https://ai.google.dev/gemini-api/docs/grounding) feature which may also help you achieve similar results (see [a previous notebook](../examples/Search_grounding_for_research_report.ipynb) using search grounding), the new search tool in Gemini 2.0 models is much more powerful and easier to use, and should be prioritized over search grounding."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "Mfk6YY3G5kqp"
+ },
+ "source": [
+ "## Setup"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "d5027929de8f"
+ },
+ "source": [
+ "### Install SDK\n",
+ "\n",
+ "The new **[Google Gen AI SDK](https://ai.google.dev/gemini-api/docs/sdks)** provides programmatic access to Gemini 2.0 (and previous models) using both the [Google AI for Developers](https://ai.google.dev/gemini-api/docs) and [Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/overview) APIs. With a few exceptions, code that runs on one platform will run on both. This means that you can prototype an application using the Developer API and then migrate the application to Vertex AI without rewriting your code.\n",
+ "\n",
+ "More details about this new SDK on the [documentation](https://ai.google.dev/gemini-api/docs/sdks) or in the [Getting started](../gemini-2/get_started.ipynb) notebook."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "46zEFO2a9FFd"
+ },
+ "outputs": [],
+ "source": [
+ "!pip install -U -q google-genai"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "CTIfnvCn9HvH"
+ },
+ "source": [
+ "### Setup your API key\n",
+ "\n",
+ "To run the following cell, your API key must be stored it in a Colab Secret named `GOOGLE_API_KEY`. If you don't already have an API key, or you're not sure how to create a Colab Secret, see [Authentication](../quickstarts/Authentication.ipynb) for an example."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "A1pkoyZb9Jm3"
+ },
+ "outputs": [],
+ "source": [
+ "from google.colab import userdata\n",
+ "\n",
+ "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "QclzsisW0nTK"
+ },
+ "source": [
+ "### Import the libraries"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "cXNAAIqOuXlO"
+ },
+ "outputs": [],
+ "source": [
+ "from google import genai\n",
+ "from google.genai.types import GenerateContentConfig, Tool\n",
+ "from IPython.display import display, HTML, Markdown\n",
+ "import io\n",
+ "import json\n",
+ "import re"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "3Hx_Gw9i0Yuv"
+ },
+ "source": [
+ "### Initialize SDK client\n",
+ "\n",
+ "With the new SDK you now only need to initialize a client with you API key (or OAuth if using [Vertex AI](https://link_to_vertex_AI)). The model is now set in each call."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "HghvVpbU0Uap"
+ },
+ "outputs": [],
+ "source": [
+ "client = genai.Client(api_key=GOOGLE_API_KEY)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "QOov6dpG99rY"
+ },
+ "source": [
+ "### Select a model\n",
+ "\n",
+ "Search tool is a new feature in the Gemini 2.0 model that automatically retrieves accurate and grounded artifacts from the web for developers to further process. Unlike the search grounding in the Gemini 1.5 models, you do not need to set the dynamic retrieval threshold.\n",
+ "\n",
+ "For more information about all Gemini models, check the [documentation](https://ai.google.dev/gemini-api/docs/models/gemini) for extended information on each of them.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "27Fikag0xSaB"
+ },
+ "outputs": [],
+ "source": [
+ "MODEL = \"gemini-2.0-flash-exp\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "F9lFY3h6unY2"
+ },
+ "source": [
+ "## Write the report with Gemini 2.0"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "j562CvvWvASd"
+ },
+ "source": [
+ "### Select a target company to research\n",
+ "\n",
+ "Next you will use Alphabet as an example research target."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "7UQxJr7UvEhl"
+ },
+ "outputs": [],
+ "source": [
+ "COMPANY = 'Alphabet'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "HALOE8He78H1"
+ },
+ "source": [
+ "### Have Gemini 2.0 plan for the task and write the report\n",
+ "\n",
+ "Gemini 2.0 is a huge step up from previous models since it can reason, plan, search and write in one go. In this case, you will only give Gemini 2.0 a prompt to do all of these and the model will finish your task seamlessly. You will also using output streaming, which streams the response as it is being generated, and the model will return chunks of the response as soon as they are generated. If you would like the SDK to return a response after the model completes the entire generation process, you can use the non-streaming approach as well.\n",
+ "\n",
+ "Note that you must enable Google Search Suggestions, which help users find search results corresponding to a grounded response, and [display the search queries](https://ai.google.dev/gemini-api/docs/grounding/search-suggestions#display-requirements) that are included in the grounded response's metadata. You can find [more details](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) about this requirement."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "IAl2UGtw0LPG"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/markdown": [
+ "Okay"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ ", I will research Alphabet and create a company report. Here's my plan"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ ":\n",
+ "\n",
+ "1. **Company Overview:** I'll start by gathering basic"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " information about Alphabet, such as its founding date, headquarters, and what it does.\n",
+ "2. **Business Segments:** I'll identify the different"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " business segments that Alphabet operates in (e.g., Google Services, Google Cloud, Other Bets).\n",
+ "3. **Recent News and Developments:** I'"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ "ll look for recent news articles and press releases to understand any significant updates, product launches, or strategic shifts.\n",
+ "4. **Financial Performance:** I'll try to find information about Alphabet's recent financial performance, including revenue,"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " profit, and key metrics.\n",
+ "5. **Stock Information:** I'll check the current stock price and any recent stock-related news.\n",
+ "6. **Key People:** I'll identify key executives and board members."
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ "\n",
+ "7. **Competitive Landscape:** I'll briefly touch on the competitive landscape and Alphabet's main competitors.\n",
+ "\n",
+ "Now, let's start with the searches.\n",
+ "\n"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ "Okay"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ ", I've gathered a lot of information about Alphabet. Here's a"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " company report:\n",
+ "\n",
+ "---\n",
+ "**Company Report: Alphabet Inc.**\n",
+ "\n",
+ "**Overview"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ ":**\n",
+ "\n",
+ "Alphabet Inc. is a multinational technology conglomerate holding company headquartered in Mountain View, California. It was created through a restructuring of Google on October 2,"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " 2015, becoming the parent company of Google and several former Google subsidiaries. Alphabet is the world's second-largest technology company by revenue,"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " after Apple, and one of the world's most valuable companies. It is considered one of the Big Five American information technology companies, alongside Amazon, Apple, Meta, and Microsoft.\n",
+ "\n",
+ "**Founding and Restructuring:**\n",
+ "\n",
+ "While Google"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " was founded in 1998 by Larry Page and Sergey Brin, Alphabet Inc. was formed on October 2, 2015, as a restructuring to make the core Google business \"cleaner and more accountable\""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " while allowing greater autonomy to other ventures. In December 2019, Larry Page and Sergey Brin stepped down from their executive roles, and Sundar Pichai, who was already CEO of Google, became CEO of both Google and Alphabet. Page and Brin remain employees, board members, and controlling shareholders."
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ "\n",
+ "\n",
+ "**Business Segments:**\n",
+ "\n",
+ "Alphabet operates through three main reportable segments:\n",
+ "\n",
+ "* **Google Services:** This segment includes Google's core internet products such as ads, Android, Chrome, hardware, Google Cloud, Google Maps, Google Play, Search, and YouTube. This is the most profitable segment, with"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " revenue primarily generated from advertising on Google Search and YouTube, as well as subscriptions and smartphone sales.\n",
+ "* **Google Cloud:** This segment provides cloud services for businesses, including office software and computing platforms. Google Cloud's quarterly revenues have recently surpassed $10 billion, and it is showing strong growth.\n",
+ "*"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " **Other Bets:** This segment includes various cutting-edge technology innovation ventures at different stages of development, such as Access, Calico, CapitalG, GV, Verily, Waymo, and X. This segment often posts operating losses.\n",
+ "\n",
+ "**Recent News and Developments:**\n",
+ "\n",
+ "* Alphabet's stock recently"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " reached an all-time high after unveiling its latest AI model, Gemini 2.0, and showcasing a new quantum computing chip called Willow.\n",
+ "* Google has launched Gemini, formerly known as Bard, an AI chatbot that supports over 40 languages.\n",
+ "* Alphabet's Q3 20"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ "24 results showed a 15% increase in consolidated revenue year-over-year, reaching $88.3 billion. Google Services revenue increased by 13% to $76.5 billion.\n",
+ "* Google Cloud's revenue exceeded $10 billion in a recent quarter, with over"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " $1 billion in operating profit.\n",
+ "* Alphabet announced a cash dividend of $0.20 per share in July 2024.\n",
+ "\n",
+ "**Financial Performance:**\n",
+ "\n",
+ "* In Q3 2024, Alphabet's consolidated revenue was $88.3 billion, a 1"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ "5% increase year-over-year.\n",
+ "* Net income for Q3 2024 was $26.3 billion, compared to $19.7 billion a year ago.\n",
+ "* For the nine months ended September 30, 2024, sales were $"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ "253.5 billion, compared to $221.1 billion a year ago.\n",
+ "* Google Cloud's revenue has surpassed $10 billion in a recent quarter.\n",
+ "* Alphabet's revenue is primarily driven by Google Services, particularly advertising.\n",
+ "\n",
+ "**Stock Information:**\n",
+ "\n",
+ "* "
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ "Alphabet has two classes of stock: GOOG (Class C shares without voting rights) and GOOGL (Class A common stock).\n",
+ "* As of today, December 17, 2024, the price of GOOG is around $198.16, and it has increased"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " by 4.31% in the past 24 hours.\n",
+ "* The stock reached an all-time high on December 10, 2024.\n",
+ "* Analysts' price targets for GOOG range from $185 to $240.\n",
+ "\n",
+ "**Key People"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ ":**\n",
+ "\n",
+ "* **CEO:** Sundar Pichai\n",
+ "* **Co-Founders:** Larry Page and Sergey Brin (remain board members and controlling shareholders)\n",
+ "* **Chief Financial Officer:** Anat Ashkenazi\n",
+ "* **Other Key Executives:** Philipp Schindler (Chief Business Officer, Google), Prabhakar"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ " Raghavan (Chief Technologist, Google), Ruth M. Porat (President and Chief Investment Officer; CFO)\n",
+ "\n",
+ "**Competitive Landscape:**\n",
+ "\n",
+ "Alphabet's main competitors include:\n",
+ "\n",
+ "* **Other Big Tech Companies:** Apple, Microsoft, Meta, Amazon, IBM\n",
+ "* **Software Companies:** SAP, Pal"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ "antir Technologies, Shopify, AppLovin, Infosys, CrowdStrike, Atlassian, Trade Desk, NetEase, Snowflake\n",
+ "* **Other Competitors:** ByteDance, Zoom, Salesforce, Tencent, Adobe\n",
+ "\n",
+ "**Additional Information:**\n",
+ "\n",
+ "* Alphabet's headquarters is located at 160"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ "0 Amphitheatre Parkway in Mountain View, California, also known as the Googleplex.\n",
+ "* Alphabet has a global presence with employees across six continents.\n",
+ "* Alphabet is involved in investing in infrastructure, data management, analytics, and artificial intelligence (AI).\n",
+ "\n",
+ "This report provides a comprehensive overview of Alphabet Inc"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/markdown": [
+ ". as of December 17, 2024.\n",
+ "---\n"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "
\n"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "sys_instruction = \"\"\"You are an analyst that conducts company research.\n",
+ "You are given a company name, and you will work on a company report. You have access\n",
+ "to Google Search to look up company news, updates and metrics to write research reports.\n",
+ "\n",
+ "When given a company name, identify key aspects to research, look up that information\n",
+ "and then write a concise company report.\n",
+ "\n",
+ "Feel free to plan your work and talk about it, but when you start writing the report,\n",
+ "put a line of dashes (---) to demarcate the report itself, and say nothing else after\n",
+ "the report has finished.\n",
+ "\"\"\"\n",
+ "\n",
+ "config = GenerateContentConfig(system_instruction=sys_instruction, tools=[Tool(google_search={})], temperature=0)\n",
+ "response_stream = client.models.generate_content_stream(\n",
+ " model=MODEL, config=config, contents=[COMPANY])\n",
+ "\n",
+ "report = io.StringIO()\n",
+ "for chunk in response_stream:\n",
+ " candidate = chunk.candidates[0]\n",
+ "\n",
+ " for part in candidate.content.parts:\n",
+ " if part.text:\n",
+ " display(Markdown(part.text))\n",
+ "\n",
+ " # Find and save the report itself.\n",
+ " if m := re.search('(^|\\n)-+\\n(.*)$', part.text, re.M):\n",
+ " # Find the starting '---' line and start saving.\n",
+ " report.write(m.group(2))\n",
+ " elif report.tell():\n",
+ " # If there's already something in the buffer, keep recording.\n",
+ " report.write(part.text)\n",
+ "\n",
+ " else:\n",
+ " print(json.dumps(part.model_dump(exclude_none=True), indent=2))\n",
+ "\n",
+ " # You must enable Google Search Suggestions\n",
+ " if gm := candidate.grounding_metadata:\n",
+ " if sep := gm.search_entry_point:\n",
+ " display(HTML(sep.rendered_content))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "e2gBbhEU-jCo"
+ },
+ "source": [
+ "Very impressive! Gemini 2.0 starts by planning for the task, performing relevant searches and streams out a report for you."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "P_JoMFa18Rss"
+ },
+ "source": [
+ "### Final output\n",
+ "\n",
+ "Render the final output."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "1yddCUCL4yKA"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/markdown": [
+ "**Company Report: Alphabet Inc.**:**\n",
+ "\n",
+ "Alphabet Inc. is a multinational technology conglomerate holding company headquartered in Mountain View, California. It was created through a restructuring of Google on October 2, 2015, becoming the parent company of Google and several former Google subsidiaries. Alphabet is the world's second-largest technology company by revenue, after Apple, and one of the world's most valuable companies. It is considered one of the Big Five American information technology companies, alongside Amazon, Apple, Meta, and Microsoft.\n",
+ "\n",
+ "**Founding and Restructuring:**\n",
+ "\n",
+ "While Google was founded in 1998 by Larry Page and Sergey Brin, Alphabet Inc. was formed on October 2, 2015, as a restructuring to make the core Google business \"cleaner and more accountable\" while allowing greater autonomy to other ventures. In December 2019, Larry Page and Sergey Brin stepped down from their executive roles, and Sundar Pichai, who was already CEO of Google, became CEO of both Google and Alphabet. Page and Brin remain employees, board members, and controlling shareholders.\n",
+ "\n",
+ "**Business Segments:**\n",
+ "\n",
+ "Alphabet operates through three main reportable segments:\n",
+ "\n",
+ "* **Google Services:** This segment includes Google's core internet products such as ads, Android, Chrome, hardware, Google Cloud, Google Maps, Google Play, Search, and YouTube. This is the most profitable segment, with revenue primarily generated from advertising on Google Search and YouTube, as well as subscriptions and smartphone sales.\n",
+ "* **Google Cloud:** This segment provides cloud services for businesses, including office software and computing platforms. Google Cloud's quarterly revenues have recently surpassed \\$10 billion, and it is showing strong growth.\n",
+ "* **Other Bets:** This segment includes various cutting-edge technology innovation ventures at different stages of development, such as Access, Calico, CapitalG, GV, Verily, Waymo, and X. This segment often posts operating losses.\n",
+ "\n",
+ "**Recent News and Developments:**\n",
+ "\n",
+ "* Alphabet's stock recently reached an all-time high after unveiling its latest AI model, Gemini 2.0, and showcasing a new quantum computing chip called Willow.\n",
+ "* Google has launched Gemini, formerly known as Bard, an AI chatbot that supports over 40 languages.\n",
+ "* Alphabet's Q3 2024 results showed a 15% increase in consolidated revenue year-over-year, reaching \\$88.3 billion. Google Services revenue increased by 13% to \\$76.5 billion.\n",
+ "* Google Cloud's revenue exceeded \\$10 billion in a recent quarter, with over \\$1 billion in operating profit.\n",
+ "* Alphabet announced a cash dividend of \\$0.20 per share in July 2024.\n",
+ "\n",
+ "**Financial Performance:**\n",
+ "\n",
+ "* In Q3 2024, Alphabet's consolidated revenue was \\$88.3 billion, a 15% increase year-over-year.\n",
+ "* Net income for Q3 2024 was \\$26.3 billion, compared to \\$19.7 billion a year ago.\n",
+ "* For the nine months ended September 30, 2024, sales were \\$253.5 billion, compared to \\$221.1 billion a year ago.\n",
+ "* Google Cloud's revenue has surpassed \\$10 billion in a recent quarter.\n",
+ "* Alphabet's revenue is primarily driven by Google Services, particularly advertising.\n",
+ "\n",
+ "**Stock Information:**\n",
+ "\n",
+ "* Alphabet has two classes of stock: GOOG (Class C shares without voting rights) and GOOGL (Class A common stock).\n",
+ "* As of today, December 17, 2024, the price of GOOG is around \\$198.16, and it has increased by 4.31% in the past 24 hours.\n",
+ "* The stock reached an all-time high on December 10, 2024.\n",
+ "* Analysts' price targets for GOOG range from \\$185 to \\$240.\n",
+ "\n",
+ "**Key People:**\n",
+ "\n",
+ "* **CEO:** Sundar Pichai\n",
+ "* **Co-Founders:** Larry Page and Sergey Brin (remain board members and controlling shareholders)\n",
+ "* **Chief Financial Officer:** Anat Ashkenazi\n",
+ "* **Other Key Executives:** Philipp Schindler (Chief Business Officer, Google), Prabhakar Raghavan (Chief Technologist, Google), Ruth M. Porat (President and Chief Investment Officer; CFO)\n",
+ "\n",
+ "**Competitive Landscape:**\n",
+ "\n",
+ "Alphabet's main competitors include:\n",
+ "\n",
+ "* **Other Big Tech Companies:** Apple, Microsoft, Meta, Amazon, IBM\n",
+ "* **Software Companies:** SAP, Palantir Technologies, Shopify, AppLovin, Infosys, CrowdStrike, Atlassian, Trade Desk, NetEase, Snowflake\n",
+ "* **Other Competitors:** ByteDance, Zoom, Salesforce, Tencent, Adobe\n",
+ "\n",
+ "**Additional Information:**\n",
+ "\n",
+ "* Alphabet's headquarters is located at 1600 Amphitheatre Parkway in Mountain View, California, also known as the Googleplex.\n",
+ "* Alphabet has a global presence with employees across six continents.\n",
+ "* Alphabet is involved in investing in infrastructure, data management, analytics, and artificial intelligence (AI).\n",
+ "\n",
+ "This report provides a comprehensive overview of Alphabet Inc"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "
\n"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "display(Markdown(report.getvalue().replace('$', r'\\$'))) # Escape $ signs for better MD rendering\n",
+ "display(HTML(sep.rendered_content))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "leOZmicAwTSn"
+ },
+ "source": [
+ "As you can see, the Gemini 2.0 model is able to write a concise, accurate and well-structured research report for us. All the information in the report is factual and up-to-date.\n",
+ "\n",
+ "Note that this tutorial is meant to showcase the capability of the new search tool and inspire interesting use cases, not to build a production research report generator. If you are looking to use a tool, please check out Google [Deep Research](https://blog.google/products/gemini/google-gemini-deep-research/) in the Gemini app."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "4677dd58e9b5"
+ },
+ "source": [
+ "## Next Steps\n",
+ "\n",
+ "* To learn more about the search tool, check out the [Search tool documentation](https://ai.google.dev/gemini-api/docs/models/gemini-v2#search-tool).\n",
+ "* To get started with streaming, check out the [Streaming Quickstart](../quickstarts/Streaming.ipynb).\n",
+ "* To get started with the search tool, check out the [Search tool quick start](https://github.com/google-gemini/cookbook/blob/main/gemini-2/search_tool.ipynb).\n",
+ "* To see how much easier and more powerful the search tool in Gemini 2.0 is than the previous search grounding feature, compare this tutorial with the [previous example](../examples/Search_grounding_for_research_report.ipynb).\n",
+ "* To learn more about all the new Gemini 2.0 features, check out the [Gemini 2.0 quickstart notebooks](../gemini-2/)."
+ ]
+ }
+ ],
+ "metadata": {
+ "colab": {
+ "name": "search_tool_for_research_report.ipynb",
+ "toc_visible": true
+ },
+ "kernelspec": {
+ "display_name": "Python 3",
+ "name": "python3"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}