From a3b8890f81bf55c2da97a6e59b9356a95e09d599 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Thu, 30 May 2024 13:12:11 -0700 Subject: [PATCH 1/9] Reformat notebook --- .../prompting/Basic_Code_Generation.ipynb | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/examples/prompting/Basic_Code_Generation.ipynb b/examples/prompting/Basic_Code_Generation.ipynb index 3f1021977..7205a1694 100644 --- a/examples/prompting/Basic_Code_Generation.ipynb +++ b/examples/prompting/Basic_Code_Generation.ipynb @@ -11,7 +11,11 @@ }, { "cell_type": "code", +<<<<<<< HEAD "execution_count": null, +======= + "execution_count": 1, +>>>>>>> 757cc02 (Update basic code generation) "metadata": { "cellView": "form", "id": "vQoUR__bUlfj" @@ -66,7 +70,11 @@ }, { "cell_type": "code", +<<<<<<< HEAD "execution_count": 1, +======= + "execution_count": 2, +>>>>>>> 757cc02 (Update basic code generation) "metadata": { "id": "Ne-3gnXqR0hI" }, @@ -77,7 +85,11 @@ }, { "cell_type": "code", +<<<<<<< HEAD "execution_count": 2, +======= + "execution_count": 3, +>>>>>>> 757cc02 (Update basic code generation) "metadata": { "id": "EconMHePQHGw" }, @@ -101,7 +113,11 @@ }, { "cell_type": "code", +<<<<<<< HEAD "execution_count": 3, +======= + "execution_count": 4, +>>>>>>> 757cc02 (Update basic code generation) "metadata": { "id": "v-JZzORUpVR2" }, @@ -133,11 +149,16 @@ }, { "cell_type": "code", +<<<<<<< HEAD "execution_count": 4, +======= + "execution_count": 5, +>>>>>>> 757cc02 (Update basic code generation) "metadata": { "id": "kVF8ZQ38Vs1P" }, "outputs": [], +<<<<<<< HEAD "source": [ "error_handling_system_prompt =f\"\"\"\n", "Your task is to explain exactly why this error occurred and how to fix it.\n", @@ -177,6 +198,58 @@ "You've encountered the following error message:\n", "Error Message: {error_message}\"\"\"\n", "\n", +======= + "source": [ + "error_handling_system_prompt =f\"\"\"\n", + "You are a coding assistant tasked with error handling. Your task is to provide:\n", + "\n", + "Explanation:\n", + "Explain why this error occurred. Provide insights into common causes of the error.\n", + "For each common cause, provide a code example of how this error arose.\n", + "\n", + "Possible Solutions:\n", + "Offer a potential solution to resolve the error.\n", + "\n", + "Example Code:\n", + "Optionally, include example code snippets demonstrating correct usage or\n", + "implementation.\n", + "\"\"\"\n", + "error_handling_model = genai.GenerativeModel(model_name='gemini-1.5-flash-latest', generation_config={\"temperature\": 0},\n", + " system_instruction=error_handling_system_prompt)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "CHTdAVE0pIFf" + }, + "outputs": [ + { + "data": { + "text/markdown": "## Explanation:\n\nThe error \"IndexError: list index out of range\" occurs when you try to access an element in a list using an index that is outside the valid range of indices for that list.\n\n**Common Causes:**\n\n1. **Incorrect Index:** You are trying to access an element at an index that doesn't exist in the list. \n * **Example:**\n ```python\n my_list = [1, 2, 3]\n print(my_list[3]) # Trying to access the 4th element (index 3), which doesn't exist.\n ```\n\n2. **Negative Index Out of Range:** You are using a negative index to access an element from the end of the list, but the index is too large (i.e., more negative than the length of the list).\n * **Example:**\n ```python\n my_list = [1, 2, 3]\n print(my_list[-4]) # Trying to access the 4th element from the end, which doesn't exist.\n ```\n\n3. **List Modification During Iteration:** You are modifying the list while iterating over it, which can lead to unexpected index errors.\n * **Example:**\n ```python\n my_list = [1, 2, 3]\n for i in range(len(my_list)):\n if my_list[i] == 2:\n my_list.pop(i) # Removing an element while iterating can cause index errors.\n print(my_list[i])\n ```\n\n## Possible Solutions:\n\n1. **Check the Index:** Ensure that the index you are using to access the element is within the valid range of the list. You can use `len(my_list)` to get the length of the list and make sure your index is less than that.\n * **Example:**\n ```python\n my_list = [1, 2, 3]\n if 3 < len(my_list):\n print(my_list[3])\n else:\n print(\"Index out of range\")\n ```\n\n2. **Use Negative Indices Carefully:** When using negative indices, remember that `-1` refers to the last element, `-2` to the second-to-last, and so on. Make sure your negative index is within the valid range.\n * **Example:**\n ```python\n my_list = [1, 2, 3]\n if -1 >= -len(my_list):\n print(my_list[-1])\n else:\n print(\"Index out of range\")\n ```\n\n3. **Avoid Modifying Lists During Iteration:** If you need to modify a list while iterating over it, consider using a copy of the list or iterating over a range of indices instead of directly modifying the list during iteration.\n * **Example:**\n ```python\n my_list = [1, 2, 3]\n for i in range(len(my_list)):\n if my_list[i] == 2:\n my_list.pop(i) # Removing an element while iterating can cause index errors.\n print(my_list[i])\n ```\n\n **Solution:**\n ```python\n my_list = [1, 2, 3]\n for i in range(len(my_list)):\n if my_list[i] == 2:\n my_list.pop(i)\n break # Stop iterating after removing the element\n print(my_list[i])\n ```\n\nBy understanding the common causes of this error and implementing the appropriate solutions, you can avoid \"IndexError: list index out of range\" and ensure your code runs smoothly. \n", + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "error_message = \"\"\"\n", + " 1 my_list = [1,2,3]\n", + "----> 2 print(my_list[3])\n", + "\n", + "IndexError: list index out of range\n", + "\"\"\"\n", + "\n", + "error_prompt = f\"\"\"\n", + "You've encountered the following error message:\n", + "Error Message: {error_message}\"\"\"\n", + "\n", +>>>>>>> 757cc02 (Update basic code generation) "Markdown(error_handling_model.generate_content(error_prompt).text)" ] }, @@ -191,7 +264,11 @@ }, { "cell_type": "code", +<<<<<<< HEAD "execution_count": 6, +======= + "execution_count": 7, +>>>>>>> 757cc02 (Update basic code generation) "metadata": { "id": "1T1QSzjVVvE_" }, @@ -210,7 +287,11 @@ }, { "cell_type": "code", +<<<<<<< HEAD "execution_count": 7, +======= + "execution_count": 8, +>>>>>>> 757cc02 (Update basic code generation) "metadata": { "id": "8KVpzExDqRj2" }, @@ -222,7 +303,11 @@ "" ] }, +<<<<<<< HEAD "execution_count": 7, +======= + "execution_count": 8, +>>>>>>> 757cc02 (Update basic code generation) "metadata": {}, "output_type": "execute_result" } @@ -244,7 +329,11 @@ }, { "cell_type": "code", +<<<<<<< HEAD "execution_count": 8, +======= + "execution_count": 9, +>>>>>>> 757cc02 (Update basic code generation) "metadata": { "id": "lOU_abTPSmZu" }, @@ -286,7 +375,11 @@ ], "metadata": { "colab": { +<<<<<<< HEAD "name": "Basic_code_generation.ipynb", +======= + "name": "Basic_Code_Generation.ipynb", +>>>>>>> 757cc02 (Update basic code generation) "toc_visible": true }, "kernelspec": { From 2353307401e3dc4321db683fcb0425bbd05f9253 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Thu, 30 May 2024 12:39:13 -0700 Subject: [PATCH 2/9] Update notebook with shorter prompt --- .../prompting/Basic_Code_Generation.ipynb | 59 ++++++++++++++----- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/examples/prompting/Basic_Code_Generation.ipynb b/examples/prompting/Basic_Code_Generation.ipynb index 7205a1694..216a03b3a 100644 --- a/examples/prompting/Basic_Code_Generation.ipynb +++ b/examples/prompting/Basic_Code_Generation.ipynb @@ -11,11 +11,15 @@ }, { "cell_type": "code", +<<<<<<< HEAD <<<<<<< HEAD "execution_count": null, ======= "execution_count": 1, >>>>>>> 757cc02 (Update basic code generation) +======= + "execution_count": null, +>>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": { "cellView": "form", "id": "vQoUR__bUlfj" @@ -70,11 +74,15 @@ }, { "cell_type": "code", +<<<<<<< HEAD <<<<<<< HEAD "execution_count": 1, ======= "execution_count": 2, >>>>>>> 757cc02 (Update basic code generation) +======= + "execution_count": 1, +>>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": { "id": "Ne-3gnXqR0hI" }, @@ -85,11 +93,15 @@ }, { "cell_type": "code", +<<<<<<< HEAD <<<<<<< HEAD "execution_count": 2, ======= "execution_count": 3, >>>>>>> 757cc02 (Update basic code generation) +======= + "execution_count": 2, +>>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": { "id": "EconMHePQHGw" }, @@ -113,11 +125,15 @@ }, { "cell_type": "code", +<<<<<<< HEAD <<<<<<< HEAD "execution_count": 3, ======= "execution_count": 4, >>>>>>> 757cc02 (Update basic code generation) +======= + "execution_count": 3, +>>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": { "id": "v-JZzORUpVR2" }, @@ -149,11 +165,15 @@ }, { "cell_type": "code", +<<<<<<< HEAD <<<<<<< HEAD "execution_count": 4, ======= "execution_count": 5, >>>>>>> 757cc02 (Update basic code generation) +======= + "execution_count": 4, +>>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": { "id": "kVF8ZQ38Vs1P" }, @@ -201,18 +221,7 @@ ======= "source": [ "error_handling_system_prompt =f\"\"\"\n", - "You are a coding assistant tasked with error handling. Your task is to provide:\n", - "\n", - "Explanation:\n", - "Explain why this error occurred. Provide insights into common causes of the error.\n", - "For each common cause, provide a code example of how this error arose.\n", - "\n", - "Possible Solutions:\n", - "Offer a potential solution to resolve the error.\n", - "\n", - "Example Code:\n", - "Optionally, include example code snippets demonstrating correct usage or\n", - "implementation.\n", + "Your task is to explain exactly why this error occurred and how to fix it.\n", "\"\"\"\n", "error_handling_model = genai.GenerativeModel(model_name='gemini-1.5-flash-latest', generation_config={\"temperature\": 0},\n", " system_instruction=error_handling_system_prompt)" @@ -220,19 +229,19 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": { "id": "CHTdAVE0pIFf" }, "outputs": [ { "data": { - "text/markdown": "## Explanation:\n\nThe error \"IndexError: list index out of range\" occurs when you try to access an element in a list using an index that is outside the valid range of indices for that list.\n\n**Common Causes:**\n\n1. **Incorrect Index:** You are trying to access an element at an index that doesn't exist in the list. \n * **Example:**\n ```python\n my_list = [1, 2, 3]\n print(my_list[3]) # Trying to access the 4th element (index 3), which doesn't exist.\n ```\n\n2. **Negative Index Out of Range:** You are using a negative index to access an element from the end of the list, but the index is too large (i.e., more negative than the length of the list).\n * **Example:**\n ```python\n my_list = [1, 2, 3]\n print(my_list[-4]) # Trying to access the 4th element from the end, which doesn't exist.\n ```\n\n3. **List Modification During Iteration:** You are modifying the list while iterating over it, which can lead to unexpected index errors.\n * **Example:**\n ```python\n my_list = [1, 2, 3]\n for i in range(len(my_list)):\n if my_list[i] == 2:\n my_list.pop(i) # Removing an element while iterating can cause index errors.\n print(my_list[i])\n ```\n\n## Possible Solutions:\n\n1. **Check the Index:** Ensure that the index you are using to access the element is within the valid range of the list. You can use `len(my_list)` to get the length of the list and make sure your index is less than that.\n * **Example:**\n ```python\n my_list = [1, 2, 3]\n if 3 < len(my_list):\n print(my_list[3])\n else:\n print(\"Index out of range\")\n ```\n\n2. **Use Negative Indices Carefully:** When using negative indices, remember that `-1` refers to the last element, `-2` to the second-to-last, and so on. Make sure your negative index is within the valid range.\n * **Example:**\n ```python\n my_list = [1, 2, 3]\n if -1 >= -len(my_list):\n print(my_list[-1])\n else:\n print(\"Index out of range\")\n ```\n\n3. **Avoid Modifying Lists During Iteration:** If you need to modify a list while iterating over it, consider using a copy of the list or iterating over a range of indices instead of directly modifying the list during iteration.\n * **Example:**\n ```python\n my_list = [1, 2, 3]\n for i in range(len(my_list)):\n if my_list[i] == 2:\n my_list.pop(i) # Removing an element while iterating can cause index errors.\n print(my_list[i])\n ```\n\n **Solution:**\n ```python\n my_list = [1, 2, 3]\n for i in range(len(my_list)):\n if my_list[i] == 2:\n my_list.pop(i)\n break # Stop iterating after removing the element\n print(my_list[i])\n ```\n\nBy understanding the common causes of this error and implementing the appropriate solutions, you can avoid \"IndexError: list index out of range\" and ensure your code runs smoothly. \n", + "text/markdown": "The error message \"IndexError: list index out of range\" means you're trying to access an element in a list using an index that doesn't exist.\n\n**Explanation:**\n\n* **List Indexing:** In Python, lists are zero-indexed. This means the first element has an index of 0, the second element has an index of 1, and so on.\n* **Your Code:** In your code, `my_list = [1, 2, 3]` has three elements. The valid indices for this list are 0, 1, and 2.\n* **The Error:** You're trying to access `my_list[3]`. Since the list only has three elements, there is no element at index 3. This causes the \"IndexError: list index out of range\" error.\n\n**How to Fix It:**\n\n1. **Check the Index:** Ensure the index you're using is within the valid range of the list. In this case, you should use an index between 0 and 2.\n2. **Adjust the Code:** To access the last element of the list, use `my_list[2]`.\n\n**Corrected Code:**\n\n```python\nmy_list = [1, 2, 3]\nprint(my_list[2]) # This will print 3\n```\n\n**Important Note:** Always be mindful of the size of your lists and the indices you use to avoid this common error. \n", "text/plain": [ "" ] }, - "execution_count": 6, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -264,11 +273,15 @@ }, { "cell_type": "code", +<<<<<<< HEAD <<<<<<< HEAD "execution_count": 6, ======= "execution_count": 7, >>>>>>> 757cc02 (Update basic code generation) +======= + "execution_count": 6, +>>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": { "id": "1T1QSzjVVvE_" }, @@ -287,11 +300,15 @@ }, { "cell_type": "code", +<<<<<<< HEAD <<<<<<< HEAD "execution_count": 7, ======= "execution_count": 8, >>>>>>> 757cc02 (Update basic code generation) +======= + "execution_count": 7, +>>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": { "id": "8KVpzExDqRj2" }, @@ -303,11 +320,15 @@ "" ] }, +<<<<<<< HEAD <<<<<<< HEAD "execution_count": 7, ======= "execution_count": 8, >>>>>>> 757cc02 (Update basic code generation) +======= + "execution_count": 7, +>>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": {}, "output_type": "execute_result" } @@ -329,11 +350,15 @@ }, { "cell_type": "code", +<<<<<<< HEAD <<<<<<< HEAD "execution_count": 8, ======= "execution_count": 9, >>>>>>> 757cc02 (Update basic code generation) +======= + "execution_count": 8, +>>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": { "id": "lOU_abTPSmZu" }, @@ -375,11 +400,15 @@ ], "metadata": { "colab": { +<<<<<<< HEAD <<<<<<< HEAD "name": "Basic_code_generation.ipynb", ======= "name": "Basic_Code_Generation.ipynb", >>>>>>> 757cc02 (Update basic code generation) +======= + "name": "Basic_code_generation.ipynb", +>>>>>>> 7c65d32 (Update notebook with shorter prompt) "toc_visible": true }, "kernelspec": { From 6144ddccbc4cae416643e514fea5867009a1d084 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Tue, 11 Jun 2024 12:57:46 -0700 Subject: [PATCH 3/9] Migrating langchain integration examples with Gemini 1.5 Flash --- .../Gemini_LangChain_QA_Chroma_WebLoad.ipynb | 633 ++++++++++++++++++ ...mini_LangChain_Summarization_WebLoad.ipynb | 442 ++++++++++++ 2 files changed, 1075 insertions(+) create mode 100644 examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb create mode 100644 examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb diff --git a/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb new file mode 100644 index 000000000..4a6ce3a83 --- /dev/null +++ b/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb @@ -0,0 +1,633 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "Tce3stUlHN0L" + }, + "source": [ + "##### Copyright 2024 Google LLC." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "tuOe1ymfHZPu" + }, + "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": "0c5ea3f4a75c" + }, + "source": [ + "# Question Answering using Gemini, LangChain, and Chroma" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "awKO767lQIWh" + }, + "source": [ + "\n", + " \n", + "
\n", + " Run in Google Colab\n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "479790a71f3c" + }, + "source": [ + "## Overview\n", + "\n", + "[Gemini](https://ai.google.dev/models/gemini) is a family of generative AI models that lets developers generate content and solve problems. These models are designed and trained to handle both text and images as input.\n", + "\n", + "[LangChain](https://www.langchain.com/) is a data framework designed to make integration of Large Language Models (LLM) like Gemini easier for applications.\n", + "\n", + "[Chroma](https://docs.trychroma.com/) is an open-source embedding database focused on simplicity and developer productivity. Chroma allows users to store embeddings and their metadata, embed documents and queries, and search the embeddings quickly.\n", + "\n", + "In this notebook, you'll learn how to create an application that answers questions using data from a website with the help of Gemini, LangChain, and Chroma." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_qRjVe1tZhsx" + }, + "source": [ + "## Setup\n", + "\n", + "First, you must install the packages and set the necessary environment variables.\n", + "\n", + "### Installation\n", + "\n", + "Install LangChain's Python library, `langchain` and LangChain's integration package for Gemini, `langchain-google-genai`. Next, install Chroma's Python client SDK, `chromadb`." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "olK4Ejjzuj76", + "outputId": "363f1bfb-f493-4d97-b772-6aaf0ba9d942", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m1.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.2/49.2 kB\u001b[0m \u001b[31m1.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h" + ] + } + ], + "source": [ + "!pip install --quiet langchain\n", + "!pip install --quiet langchain-google-genai\n", + "!pip install --quiet chromadb\n", + "!pip install --quiet langchain-community" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "TcvGPVdXu05F", + "outputId": "ff08a3b2-1541-4d32-9279-2875dbcf33d4", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "WARNING:root:USER_AGENT environment variable not set, consider setting it to identify your requests.\n" + ] + } + ], + "source": [ + "from langchain import PromptTemplate\n", + "from langchain import hub\n", + "from langchain.docstore.document import Document\n", + "from langchain.document_loaders import WebBaseLoader\n", + "from langchain.schema import StrOutputParser\n", + "from langchain.schema.prompt_template import format_document\n", + "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain.vectorstores import Chroma" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "wiGHSFmZaniK" + }, + "source": [ + "## Set up your API key\n", + "\n", + "To use Gemini you need an API key. You can create an API key with one click in Google AI Studio. After creating the API key, you can either set an environment variable named GOOGLE_API_KEY to your API Key or pass the API key as an argument when using the ChatGoogleGenerativeAI class to access Google's gemini and gemini-vision models or the GoogleGenerativeAIEmbeddings class to access Google's Generative AI embedding model using LangChain.\n", + "\n", + "In this tutorial, you will set the environment variable `GOOGLE_API_KEY` to configure Gemini to use your API key." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "id": "xId4sR52utS0", + "outputId": "f6c160b6-5f74-4011-de39-1836cf0ee6a0", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gemini API Key:··········\n" + ] + } + ], + "source": [ + "# Run this cell and paste the API key in the prompt\n", + "import os\n", + "import getpass\n", + "\n", + "os.environ['GOOGLE_API_KEY'] = getpass.getpass('Gemini API Key:')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "aEKMUyVmckWI" + }, + "source": [ + "## Basic steps\n", + "LLMs are trained offline on a large corpus of public data. Hence they cannot answer questions based on custom or private data accurately without additional context.\n", + "\n", + "If you want to make use of LLMs to answer questions based on private data, you have to provide the relevant documents as context alongside your prompt. This approach is called Retrieval Augmented Generation (RAG).\n", + "\n", + "You will use this approach to create a question-answering assistant using the Gemini text model integrated through LangChain. The assistant is expected to answer questions about the Gemini model. To make this possible you will add more context to the assistant using data from a website.\n", + "\n", + "In this tutorial, you'll implement the two main components in an RAG-based architecture:\n", + "\n", + "1. Retriever\n", + "\n", + " Based on the user's query, the retriever retrieves relevant snippets that add context from the document. In this tutorial, the document is the website data.\n", + " The relevant snippets are passed as context to the next stage - \"Generator\".\n", + "\n", + "2. Generator\n", + "\n", + " The relevant snippets from the website data are passed to the LLM along with the user's query to generate accurate answers.\n", + "\n", + "You'll learn more about these stages in the upcoming sections while implementing the application." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4461Jihk_rWq" + }, + "source": [ + "## Retriever\n", + "\n", + "In this stage, you will perform the following steps:\n", + "\n", + "1. Read and parse the website data using LangChain.\n", + "\n", + "2. Create embeddings of the website data.\n", + "\n", + " Embeddings are numerical representations (vectors) of text. Hence, text with similar meaning will have similar embedding vectors. You'll make use of Gemini's embedding model to create the embedding vectors of the website data.\n", + "\n", + "3. Store the embeddings in Chroma's vector store.\n", + " \n", + " Chroma is a vector database. The Chroma vector store helps in the efficient retrieval of similar vectors. Thus, for adding context to the prompt for the LLM, relevant embeddings of the text matching the user's question can be retrieved easily using Chroma.\n", + "\n", + "4. Create a Retriever from the Chroma vector store.\n", + "\n", + " The retriever will be used to pass relevant website embeddings to the LLM along with user queries." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WomGvIAVjZeI" + }, + "source": [ + "### Read and parse the website data\n", + "\n", + "LangChain provides a wide variety of document loaders. To read the website data as a document, you will use the `WebBaseLoader` from LangChain.\n", + "\n", + "To know more about how to read and parse input data from different sources using the document loaders of LangChain, read LangChain's [document loaders guide](https://python.langchain.com/docs/integrations/document_loaders)." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "DeNX9QFM0V-C" + }, + "outputs": [], + "source": [ + "loader = WebBaseLoader(\"https://blog.google/technology/ai/google-gemini-ai/\")\n", + "docs = loader.load()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "olIlIOYrJTlF" + }, + "source": [ + "If you only want to select a specific portion of the website data to add context to the prompt, you can use regex, text slicing, or text splitting.\n", + "\n", + "In this example, you'll use Python's `split()` function to extract the required portion of the text. The extracted text should be converted back to LangChain's `Document` format." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "EDL9YLRb9Bw2" + }, + "outputs": [], + "source": [ + "# Extract the text from the website data document\n", + "text_content = docs[0].page_content\n", + "\n", + "# The text content between the substrings \"code, audio, image and video.\" to\n", + "# \"Cloud TPU v5p\" is relevant for this tutorial. You can use Python's `split()`\n", + "# to select the required content.\n", + "text_content_1 = text_content.split(\"code, audio, image and video.\",1)[1]\n", + "final_text = text_content_1.split(\"Cloud TPU v5p\",1)[0]\n", + "\n", + "# Convert the text to LangChain's `Document` format\n", + "docs = [Document(page_content=final_text, metadata={\"source\": \"local\"})]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "yDsdAg4Fjo5o" + }, + "source": [ + "### Initialize Gemini's embedding model\n", + "\n", + "To create the embeddings from the website data, you'll use Gemini's embedding model, **embedding-001** which supports creating text embeddings.\n", + "\n", + "To use this embedding model, you have to import `GoogleGenerativeAIEmbeddings` from LangChain. To know more about the embedding model, read Google AI's [language documentation](https://ai.google.dev/models/gemini)." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "8NXNTrjp0jdh" + }, + "outputs": [], + "source": [ + "from langchain_google_genai import GoogleGenerativeAIEmbeddings\n", + "\n", + "# If there is no environment variable set for the API key, you can pass the API\n", + "# key to the parameter `google_api_key` of the `GoogleGenerativeAIEmbeddings`\n", + "# function: `google_api_key = \"key\"`.\n", + "\n", + "gemini_embeddings = GoogleGenerativeAIEmbeddings(model=\"models/embedding-001\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "m9Vzw30wpebs" + }, + "source": [ + "### Store the data using Chroma\n", + "\n", + "To create a Chroma vector database from the website data, you will use the `from_documents` function of `Chroma`. Under the hood, this function creates embeddings from the documents created by the document loader of LangChain using any specified embedding model and stores them in a Chroma vector database. \n", + "\n", + "You have to specify the `docs` you created from the website data using LangChain's `WebBasedLoader` and the `gemini_embeddings` as the embedding model when invoking the `from_documents` function to create the vector database from the website data. You can also specify a directory in the `persist_directory` argument to store the vector store on the disk. If you don't specify a directory, the data will be ephemeral in-memory.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "n1VwhUQMvpcN" + }, + "outputs": [], + "source": [ + "# Save to disk\n", + "vectorstore = Chroma.from_documents(\n", + " documents=docs, # Data\n", + " embedding=gemini_embeddings, # Embedding model\n", + " persist_directory=\"./chroma_db\" # Directory to save data\n", + " )" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WFKyb3JXOeaQ" + }, + "source": [ + "### Create a retriever using Chroma\n", + "\n", + "You'll now create a retriever that can retrieve website data embeddings from the newly created Chroma vector store. This retriever can be later used to pass embeddings that provide more context to the LLM for answering user's queries.\n", + "\n", + "\n", + "To load the vector store that you previously stored in the disk, you can specify the name of the directory that contains the vector store in `persist_directory` and the embedding model in the `embedding_function` arguments of Chroma's initializer.\n", + "\n", + "You can then invoke the `as_retriever` function of `Chroma` on the vector store to create a retriever." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "s3t4kmzIOZQq", + "outputId": "c419b8ee-2603-4337-a6dd-8bb2f3d4b2da", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "/usr/local/lib/python3.10/dist-packages/langchain_core/_api/deprecation.py:119: LangChainDeprecationWarning: The method `BaseRetriever.get_relevant_documents` was deprecated in langchain-core 0.1.46 and will be removed in 0.3.0. Use invoke instead.\n", + " warn_deprecated(\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "1\n" + ] + } + ], + "source": [ + "# Load from disk\n", + "vectorstore_disk = Chroma(\n", + " persist_directory=\"./chroma_db\", # Directory of db\n", + " embedding_function=gemini_embeddings # Embedding model\n", + " )\n", + "# Get the Retriever interface for the store to use later.\n", + "# When an unstructured query is given to a retriever it will return documents.\n", + "# Read more about retrievers in the following link.\n", + "# https://python.langchain.com/docs/modules/data_connection/retrievers/\n", + "#\n", + "# Since only 1 document is stored in the Chroma vector store, search_kwargs `k`\n", + "# is set to 1 to decrease the `k` value of chroma's similarity search from 4 to\n", + "# 1. If you don't pass this value, you will get a warning.\n", + "retriever = vectorstore_disk.as_retriever(search_kwargs={\"k\": 1})\n", + "\n", + "# Check if the retriever is working by trying to fetch the relevant docs related\n", + "# to the word 'MMLU' (Massive Multitask Language Understanding). If the length is greater than zero, it means that\n", + "# the retriever is functioning well.\n", + "print(len(retriever.get_relevant_documents(\"MMLU\")))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LZwcZyRxSO0q" + }, + "source": [ + "## Generator\n", + "\n", + "The Generator prompts the LLM for an answer when the user asks a question. The retriever you created in the previous stage from the Chroma vector store will be used to pass relevant embeddings from the website data to the LLM to provide more context to the user's query.\n", + "\n", + "You'll perform the following steps in this stage:\n", + "\n", + "1. Chain together the following:\n", + " * A prompt for extracting the relevant embeddings using the retriever.\n", + " * A prompt for answering any question using LangChain.\n", + " * An LLM model from Gemini for prompting.\n", + " \n", + "2. Run the created chain with a question as input to prompt the model for an answer.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FtUi5FBIJMDy" + }, + "source": [ + "### Initialize Gemini\n", + "\n", + "You must import `ChatGoogleGenerativeAI` from LangChain to initialize your model.\n", + " In this example, you will use **gemini-pro**, as it supports text summarization. To know more about the text model, read Google AI's [language documentation](https://ai.google.dev/models/gemini).\n", + "\n", + "You can configure the model parameters such as ***temperature*** or ***top_p***, by passing the appropriate values when initializing the `ChatGoogleGenerativeAI` LLM. To learn more about the parameters and their uses, read Google AI's [concepts guide](https://ai.google.dev/docs/concepts#model_parameters)." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "id": "CaA1vRCh7s36" + }, + "outputs": [], + "source": [ + "from langchain_google_genai import ChatGoogleGenerativeAI\n", + "\n", + "# If there is no environment variable set for the API key, you can pass the API\n", + "# key to the parameter `google_api_key` of the `ChatGoogleGenerativeAI` function:\n", + "# `google_api_key=\"key\"`.\n", + "llm = ChatGoogleGenerativeAI(model=\"gemini-1.5-flash-latest\",\n", + " temperature=0.7, top_p=0.85)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jC4QDhiPpDJa" + }, + "source": [ + "### Create prompt templates\n", + "\n", + "You'll use LangChain's [PromptTemplate](https://python.langchain.com/docs/modules/model_io/prompts/prompt_templates/) to generate prompts to the LLM for answering questions.\n", + "\n", + "In the `llm_prompt`, the variable `question` will be replaced later by the input question, and the variable `context` will be replaced by the relevant text from the website retrieved from the Chroma vector store." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "id": "90Czqh074dEC", + "outputId": "626affcd-002b-447c-bd6b-b06c316cf67e", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "input_variables=['context', 'question'] template=\"You are an assistant for question-answering tasks.\\nUse the following context to answer the question.\\nIf you don't know the answer, just say that you don't know.\\nUse five sentences maximum and keep the answer concise.\\n\\nQuestion: {question} \\nContext: {context} \\nAnswer:\"\n" + ] + } + ], + "source": [ + "# Prompt template to query Gemini\n", + "llm_prompt_template = \"\"\"You are an assistant for question-answering tasks.\n", + "Use the following context to answer the question.\n", + "If you don't know the answer, just say that you don't know.\n", + "Use five sentences maximum and keep the answer concise.\\n\n", + "Question: {question} \\nContext: {context} \\nAnswer:\"\"\"\n", + "\n", + "llm_prompt = PromptTemplate.from_template(llm_prompt_template)\n", + "\n", + "print(llm_prompt)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "KXDh2jsdp4sr" + }, + "source": [ + "### Create a stuff documents chain\n", + "\n", + "LangChain provides [Chains](https://python.langchain.com/docs/modules/chains/) for chaining together LLMs with each other or other components for complex applications. You will create a **stuff documents chain** for this application. A stuff documents chain lets you combine all the relevant documents, insert them into the prompt, and pass that prompt to the LLM.\n", + "\n", + "You can create a stuff documents chain using the [LangChain Expression Language (LCEL)](https://python.langchain.com/docs/expression_language).\n", + "\n", + "To learn more about different types of document chains, read LangChain's [chains guide](https://python.langchain.com/docs/modules/chains/document/).\n", + "\n", + "The stuff documents chain for this application retrieves the relevant website data and passes it as the context to an LLM prompt along with the input question." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "id": "gj5sWzpwp7vc" + }, + "outputs": [], + "source": [ + "# Combine data from documents to readable string format.\n", + "def format_docs(docs):\n", + " return \"\\n\\n\".join(doc.page_content for doc in docs)\n", + "\n", + "# Create stuff documents chain using LCEL.\n", + "#\n", + "# This is called a chain because you are chaining together different elements\n", + "# with the LLM. In the following example, to create the stuff chain, you will\n", + "# combine the relevant context from the website data matching the question, the\n", + "# LLM model, and the output parser together like a chain using LCEL.\n", + "#\n", + "# The chain implements the following pipeline:\n", + "# 1. Extract the website data relevant to the question from the Chroma\n", + "# vector store and save it to the variable `context`.\n", + "# 2. `RunnablePassthrough` option to provide `question` when invoking\n", + "# the chain.\n", + "# 3. The `context` and `question` are then passed to the prompt where they\n", + "# are populated in the respective variables.\n", + "# 4. This prompt is then passed to the LLM (`gemini-pro`).\n", + "# 5. Output from the LLM is passed through an output parser\n", + "# to structure the model's response.\n", + "rag_chain = (\n", + " {\"context\": retriever | format_docs, \"question\": RunnablePassthrough()}\n", + " | llm_prompt\n", + " | llm\n", + " | StrOutputParser()\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cPPqsGCLIrs1" + }, + "source": [ + "### Prompt the model\n", + "\n", + "You can now query the LLM by passing any question to the `invoke()` function of the stuff documents chain you created previously." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "id": "4vIaopCsIq0B", + "outputId": "b40c9bcb-3add-49d7-b024-a4020c8a17e2", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 70 + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "\"Gemini is Google's largest and most capable AI model, designed to be flexible and efficient across various platforms. It excels in a wide range of tasks, including natural language understanding, image and video comprehension, mathematical reasoning, and coding. Gemini comes in three sizes: Ultra, Pro, and Nano, each optimized for different use cases. Gemini Ultra has achieved state-of-the-art performance on multiple benchmarks, surpassing human experts in some areas. \\n\"" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 16 + } + ], + "source": [ + "rag_chain.invoke(\"What is Gemini?\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "lV7T9rqDdjZK" + }, + "source": [ + "# Conclusion\n", + "\n", + "That's it. You have successfully created an LLM application that answers questions using data from a website with the help of Gemini, LangChain, and Chroma." + ] + } + ], + "metadata": { + "colab": { + "name": "Gemini_LangChain_QA_Chroma_WebLoad.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb new file mode 100644 index 000000000..27955b765 --- /dev/null +++ b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb @@ -0,0 +1,442 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "Tce3stUlHN0L" + }, + "source": [ + "##### Copyright 2024 Google LLC." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "tuOe1ymfHZPu" + }, + "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": "f22a409c18ef" + }, + "source": [ + "# Summarize large documents using LangChain and Gemini" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "awKO767lQIWh" + }, + "source": [ + "\n", + " \n", + "
\n", + " Run in Google Colab\n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "f892e8b2c8ef" + }, + "source": [ + "## Overview\n", + "\n", + "[Gemini](https://ai.google.dev/models/gemini) is a family of generative AI models that lets developers generate content and solve problems. These models are designed and trained to handle both text and images as input.\n", + "\n", + "[LangChain](https://www.langchain.com/) is a framework designed to make integration of Large Language Models (LLM) like Gemini easier for applications.\n", + "\n", + "In this notebook, you'll learn how to create an application to summarize large documents using Gemini and LangChain.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "iHj4T7hsx1EB" + }, + "source": [ + "## Setup\n", + "\n", + "First, you must install the packages and set the necessary environment variables.\n", + "\n", + "### Installation\n", + "\n", + "Install LangChain's Python library, `langchain` and LangChain's integration package for Gemini, `langchain-google-genai`." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "yERdO0eFJpb-", + "outputId": "b9b9c5b4-6053-45a0-97ec-1e12deea86e4" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Installing collected packages: mypy-extensions, marshmallow, typing-inspect, dataclasses-json, langchain-community\n", + "Successfully installed dataclasses-json-0.6.7 langchain-community-0.2.4 marshmallow-3.21.3 mypy-extensions-1.0.0 typing-inspect-0.9.0\n" + ] + } + ], + "source": [ + "!pip install --quiet langchain\n", + "!pip install --quiet langchain-google-genai\n", + "!pip install -U langchain-community" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "rAv0UicpKARZ", + "outputId": "5e7c1c21-5f9b-4d2e-d656-eec1e630c8ed" + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:root:USER_AGENT environment variable not set, consider setting it to identify your requests.\n" + ] + } + ], + "source": [ + "from langchain import PromptTemplate\n", + "from langchain.document_loaders import WebBaseLoader\n", + "from langchain.schema import StrOutputParser\n", + "from langchain.schema.prompt_template import format_document" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ycFMUTxn0VoI" + }, + "source": [ + "### Grab an API Key\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "e1dZNWvUzksX" + }, + "source": [ + "To use Gemini you need an *API key*. You can create an API key with one click in [Google AI Studio](https://makersuite.google.com/).\n", + "After creating the API key, you can either set an environment variable named `GOOGLE_API_KEY` to your API Key or pass the API key as an argument when creating the `ChatGoogleGenerativeAI` LLM using `LangChain`.\n", + "\n", + "In this tutorial, you will set the environment variable `GOOGLE_API_KEY` to configure Gemini to use your API key." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "1RO5jvTTddtc", + "outputId": "5d907186-56c4-4399-968d-bc9c83e0d1c5" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Gemini API Key:··········\n" + ] + } + ], + "source": [ + "# Run this cell and paste the API key in the prompt\n", + "import os\n", + "import getpass\n", + "\n", + "os.environ['GOOGLE_API_KEY'] = getpass.getpass('Gemini API Key:')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "i7wgsoiz418u" + }, + "source": [ + "## Summarize text\n", + "\n", + "In this tutorial, you are going to summarize the text from a website using the Gemini model integrated through LangChain.\n", + "\n", + "You'll perform the following steps to achieve the same:\n", + "1. Read and parse the website data using LangChain.\n", + "2. Chain together the following:\n", + " * A prompt for extracting the required input data from the parsed website data.\n", + " * A prompt for summarizing the text using LangChain.\n", + " * An LLM model (Gemini) for prompting.\n", + "\n", + "3. Run the created chain to prompt the model for the summary of the website data." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4tKpRvmMRX23" + }, + "source": [ + "### Read and parse the website data\n", + "\n", + "LangChain provides a wide variety of document loaders. To read the website data as a document, you will use the `WebBaseLoader` from LangChain.\n", + "\n", + "To know more about how to read and parse input data from different sources using the document loaders of LangChain, read LangChain's [document loaders guide](https://python.langchain.com/docs/integrations/document_loaders)." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "TTgmyxXzKCSq", + "outputId": "1bcf9e38-afe7-43a6-8093-434bb91fc212" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Document(page_content=\"\\n\\n\\n\\n\\n\\nIntroducing Gemini: Google’s most capable AI model yet\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nSkip to main content\\n\\n\\n\\n\\n\\n The Keyword\\n \\n\\n\\n\\n\\n Introducing Gemini: our largest and most capable AI model\\n \\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Latest stories\\n \\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Android\\n \\n \\n\\n\\n\\n Chrome\\n \\n \\n\\n\\n\\n Chromebooks\\n \\n \\n\\n\\n\\n Google Play\\n \\n \\n\\n\\n\\n Wear OS by Google\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Chromecast\\n \\n \\n\\n\\n\\n Fitbit\\n \\n \\n\\n\\n\\n Google Nest\\n \\n \\n\\n\\n\\n Pixel\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Gemini\\n \\n \\n\\n\\n\\n Google Assistant\\n \\n \\n\\n\\n\\n Maps\\n \\n \\n\\n\\n\\n News\\n \\n \\n\\n\\n\\n Search\\n \\n \\n\\n\\n\\n Shopping\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Photos\\n \\n \\n\\n\\n\\n Translate\\n \\n \\n\\n\\n\\n Registry\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Docs, Sheets and Slides\\n \\n \\n\\n\\n\\n Gmail\\n \\n \\n\\n\\n\\n Google Cloud\\n \\n \\n\\n\\n\\n Meet\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n Android\\n\\n \\n \\n\\n\\n\\n Chrome\\n\\n \\n \\n\\n\\n\\n Chromebooks\\n\\n \\n \\n\\n\\n\\n Google Play\\n\\n \\n \\n\\n\\n\\n Wear OS by Google\\n\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n Chromecast\\n\\n \\n \\n\\n\\n\\n Fitbit\\n\\n \\n \\n\\n\\n\\n Google Nest\\n\\n \\n \\n\\n\\n\\n Pixel\\n\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n Gemini\\n\\n \\n \\n\\n\\n\\n Google Assistant\\n\\n \\n \\n\\n\\n\\n Maps\\n\\n \\n \\n\\n\\n\\n News\\n\\n \\n \\n\\n\\n\\n Search\\n\\n \\n \\n\\n\\n\\n Shopping\\n\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n Photos\\n\\n \\n \\n\\n\\n\\n Translate\\n\\n \\n \\n\\n\\n\\n Registry\\n\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n Docs, Sheets and Slides\\n\\n \\n \\n\\n\\n\\n Gmail\\n\\n \\n \\n\\n\\n\\n Google Cloud\\n\\n \\n \\n\\n\\n\\n Meet\\n\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Diversity and inclusion\\n \\n \\n\\n\\n\\n Education\\n \\n \\n\\n\\n\\n Google.org\\n \\n \\n\\n\\n\\n Grow with Google\\n \\n \\n\\n\\n\\n Sustainability\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n AI\\n \\n \\n\\n\\n\\n Developers\\n \\n \\n\\n\\n\\n Families\\n \\n \\n\\n\\n\\n Next billion users\\n \\n \\n\\n\\n\\n Safety and security\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Data centers and infrastructure\\n \\n \\n\\n\\n\\n Doodles\\n \\n \\n\\n\\n\\n Googlers\\n \\n \\n\\n\\n\\n Life at Google\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Google in Asia\\n \\n \\n\\n\\n\\n Google in Europe\\n \\n \\n\\n\\n\\n Google in Latin America\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Sundar Pichai, CEO\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n Diversity and inclusion\\n\\n \\n \\n\\n\\n\\n Education\\n\\n \\n \\n\\n\\n\\n Google.org\\n\\n \\n \\n\\n\\n\\n Grow with Google\\n\\n \\n \\n\\n\\n\\n Sustainability\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n AI\\n\\n \\n \\n\\n\\n\\n Developers\\n\\n \\n \\n\\n\\n\\n Families\\n\\n \\n \\n\\n\\n\\n Next billion users\\n\\n \\n \\n\\n\\n\\n Safety and security\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n Data centers and infrastructure\\n\\n \\n \\n\\n\\n\\n Doodles\\n\\n \\n \\n\\n\\n\\n Googlers\\n\\n \\n \\n\\n\\n\\n Life at Google\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n Google in Asia\\n\\n \\n \\n\\n\\n\\n Google in Europe\\n\\n \\n \\n\\n\\n\\n Google in Latin America\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n Sundar Pichai, CEO\\n\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n The Keyword\\n \\n\\n\\n\\n\\n\\n\\n\\n Latest stories\\n \\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Android\\n \\n \\n\\n\\n\\n Chrome\\n \\n \\n\\n\\n\\n Chromebooks\\n \\n \\n\\n\\n\\n Google Play\\n \\n \\n\\n\\n\\n Wear OS by Google\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Chromecast\\n \\n \\n\\n\\n\\n Fitbit\\n \\n \\n\\n\\n\\n Google Nest\\n \\n \\n\\n\\n\\n Pixel\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Gemini\\n \\n \\n\\n\\n\\n Google Assistant\\n \\n \\n\\n\\n\\n Maps\\n \\n \\n\\n\\n\\n News\\n \\n \\n\\n\\n\\n Search\\n \\n \\n\\n\\n\\n Shopping\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Photos\\n \\n \\n\\n\\n\\n Translate\\n \\n \\n\\n\\n\\n Registry\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Docs, Sheets and Slides\\n \\n \\n\\n\\n\\n Gmail\\n \\n \\n\\n\\n\\n Google Cloud\\n \\n \\n\\n\\n\\n Meet\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Diversity and inclusion\\n \\n \\n\\n\\n\\n Education\\n \\n \\n\\n\\n\\n Google.org\\n \\n \\n\\n\\n\\n Grow with Google\\n \\n \\n\\n\\n\\n Sustainability\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n AI\\n \\n \\n\\n\\n\\n Developers\\n \\n \\n\\n\\n\\n Families\\n \\n \\n\\n\\n\\n Next billion users\\n \\n \\n\\n\\n\\n Safety and security\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Data centers and infrastructure\\n \\n \\n\\n\\n\\n Doodles\\n \\n \\n\\n\\n\\n Googlers\\n \\n \\n\\n\\n\\n Life at Google\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Google in Asia\\n \\n \\n\\n\\n\\n Google in Europe\\n \\n \\n\\n\\n\\n Google in Latin America\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Sundar Pichai, CEO\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPress corner\\n\\n\\n\\n\\n RSS feed\\n \\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nAI\\n\\n\\nIntroducing Gemini: our largest and most capable AI model\\n\\n\\n\\n\\n\\n\\n\\nDec 06, 2023\\n[[read-time]] min read\\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Making AI more helpful for everyone\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nSundar Pichai\\n\\n CEO of Google and Alphabet\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nDemis Hassabis\\n\\n CEO and Co-Founder, Google DeepMind\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nIn this story\\n\\n\\nIn this story\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nNote from Sundar\\n\\n\\nIntroducing Gemini\\n\\n\\nState-of-the-art performance\\n\\n\\nNext-generation capabilities\\n\\n\\nScalable and efficient\\n\\n\\nResponsibility and safety\\n\\n\\nAvailability\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nA note from Google and Alphabet CEO Sundar Pichai:Every technology shift is an opportunity to advance scientific discovery, accelerate human progress, and improve lives. I believe the transition we are seeing right now with AI will be the most profound in our lifetimes, far bigger than the shift to mobile or to the web before it. AI has the potential to create opportunities — from the everyday to the extraordinary — for people everywhere. It will bring new waves of innovation and economic progress and drive knowledge, learning, creativity and productivity on a scale we haven’t seen before.That’s what excites me: the chance to make AI helpful for everyone, everywhere in the world.Nearly eight years into our journey as an AI-first company, the pace of progress is only accelerating: Millions of people are now using generative AI across our products to do things they couldn’t even a year ago, from finding answers to more complex questions to using new tools to collaborate and create. At the same time, developers are using our models and infrastructure to build new generative AI applications, and startups and enterprises around the world are growing with our AI tools.This is incredible momentum, and yet, we’re only beginning to scratch the surface of what’s possible.We’re approaching this work boldly and responsibly. That means being ambitious in our research and pursuing the capabilities that will bring enormous benefits to people and society, while building in safeguards and working collaboratively with governments and experts to address risks as AI becomes more capable. And we continue to invest in the very best tools, foundation models and infrastructure and bring them to our products and to others, guided by our AI Principles.Now, we’re taking the next step on our journey with Gemini, our most capable and general model yet, with state-of-the-art performance across many leading benchmarks. Our first version, Gemini 1.0, is optimized for different sizes: Ultra, Pro and Nano. These are the first models of the Gemini era and the first realization of the vision we had when we formed Google DeepMind earlier this year. This new era of models represents one of the biggest science and engineering efforts we’ve undertaken as a company. I’m genuinely excited for what’s ahead, and for the opportunities Gemini will unlock for people everywhere.– Sundar\\n\\n\\n\\n\\n\\nIntroducing GeminiBy Demis Hassabis, CEO and Co-Founder of Google DeepMind, on behalf of the Gemini teamAI has been the focus of my life's work, as for many of my research colleagues. Ever since programming AI for computer games as a teenager, and throughout my years as a neuroscience researcher trying to understand the workings of the brain, I’ve always believed that if we could build smarter machines, we could harness them to benefit humanity in incredible ways.This promise of a world responsibly empowered by AI continues to drive our work at Google DeepMind. For a long time, we’ve wanted to build a new generation of AI models, inspired by the way people understand and interact with the world. AI that feels less like a smart piece of software and more like something useful and intuitive — an expert helper or assistant.Today, we’re a step closer to this vision as we introduce Gemini, the most capable and general model we’ve ever built.Gemini is the result of large-scale collaborative efforts by teams across Google, including our colleagues at Google Research. It was built from the ground up to be multimodal, which means it can generalize and seamlessly understand, operate across and combine different types of information including text, code, audio, image and video.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nIntroducing Gemini: our largest and most capable AI model\\n\\n\\n\\n\\n\\n\\nGemini is also our most flexible model yet — able to efficiently run on everything from data centers to mobile devices. Its state-of-the-art capabilities will significantly enhance the way developers and enterprise customers build and scale with AI.We’ve optimized Gemini 1.0, our first version, for three different sizes:Gemini Ultra — our largest and most capable model for highly complex tasks.Gemini Pro — our best model for scaling across a wide range of tasks.Gemini Nano — our most efficient model for on-device tasks.\\n\\n\\n\\n\\n\\nState-of-the-art performanceWe've been rigorously testing our Gemini models and evaluating their performance on a wide variety of tasks. From natural image, audio and video understanding to mathematical reasoning, Gemini Ultra’s performance exceeds current state-of-the-art results on 30 of the 32 widely-used academic benchmarks used in large language model (LLM) research and development.With a score of 90.0%, Gemini Ultra is the first model to outperform human experts on MMLU (massive multitask language understanding), which uses a combination of 57 subjects such as math, physics, history, law, medicine and ethics for testing both world knowledge and problem-solving abilities.Our new benchmark approach to MMLU enables Gemini to use its reasoning capabilities to think more carefully before answering difficult questions, leading to significant improvements over just using its first impression.\\n\\n\\n\\n\\n\\n\\nGemini surpasses state-of-the-art performance on a range of benchmarks including text and coding.\\n\\n\\n\\nGemini Ultra also achieves a state-of-the-art score of 59.4% on the new MMMU benchmark, which consists of multimodal tasks spanning different domains requiring deliberate reasoning.With the image benchmarks we tested, Gemini Ultra outperformed previous state-of-the-art models, without assistance from optical character recognition (OCR) systems that extract text from images for further processing. These benchmarks highlight Gemini’s native multimodality and indicate early signs of Gemini's more complex reasoning abilities.See more details in our Gemini technical report.\\n\\n\\n\\n\\n\\n\\nGemini surpasses state-of-the-art performance on a range of multimodal benchmarks.\\n\\n\\n\\n\\nNext-generation capabilitiesUntil now, the standard approach to creating multimodal models involved training separate components for different modalities and then stitching them together to roughly mimic some of this functionality. These models can sometimes be good at performing certain tasks, like describing images, but struggle with more conceptual and complex reasoning.We designed Gemini to be natively multimodal, pre-trained from the start on different modalities. Then we fine-tuned it with additional multimodal data to further refine its effectiveness. This helps Gemini seamlessly understand and reason about all kinds of inputs from the ground up, far better than existing multimodal models — and its capabilities are state of the art in nearly every domain.Learn more about Gemini’s capabilities and see how it works.Sophisticated reasoningGemini 1.0’s sophisticated multimodal reasoning capabilities can help make sense of complex written and visual information. This makes it uniquely skilled at uncovering knowledge that can be difficult to discern amid vast amounts of data.Its remarkable ability to extract insights from hundreds of thousands of documents through reading, filtering and understanding information will help deliver new breakthroughs at digital speeds in many fields from science to finance.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini unlocks new scientific insights\\n\\n\\n\\n\\n\\n\\nUnderstanding text, images, audio and moreGemini 1.0 was trained to recognize and understand text, images, audio and more at the same time, so it better understands nuanced information and can answer questions relating to complicated topics. This makes it especially good at explaining reasoning in complex subjects like math and physics.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini explains reasoning in math and physics\\n\\n\\n\\n\\n\\n\\nAdvanced codingOur first version of Gemini can understand, explain and generate high-quality code in the world’s most popular programming languages, like Python, Java, C++, and Go. Its ability to work across languages and reason about complex information makes it one of the leading foundation models for coding in the world.Gemini Ultra excels in several coding benchmarks, including HumanEval, an important industry-standard for evaluating performance on coding tasks, and Natural2Code, our internal held-out dataset, which uses author-generated sources instead of web-based information.Gemini can also be used as the engine for more advanced coding systems. Two years ago we presented AlphaCode, the first AI code generation system to reach a competitive level of performance in programming competitions.Using a specialized version of Gemini, we created a more advanced code generation system, AlphaCode 2, which excels at solving competitive programming problems that go beyond coding to involve complex math and theoretical computer science.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini excels at coding and competitive programming\\n\\n\\n\\n\\n\\n\\nWhen evaluated on the same platform as the original AlphaCode, AlphaCode 2 shows massive improvements, solving nearly twice as many problems, and we estimate that it performs better than 85% of competition participants — up from nearly 50% for AlphaCode. When programmers collaborate with AlphaCode 2 by defining certain properties for the code samples to follow, it performs even better.We’re excited for programmers to increasingly use highly capable AI models as collaborative tools that can help them reason about the problems, propose code designs and assist with implementation — so they can release apps and design better services, faster.See more details in our AlphaCode 2 technical report.\\n\\n\\n\\n\\n\\nMore reliable, scalable and efficientWe trained Gemini 1.0 at scale on our AI-optimized infrastructure using Google’s in-house designed Tensor Processing Units (TPUs) v4 and v5e. And we designed it to be our most reliable and scalable model to train, and our most efficient to serve.On TPUs, Gemini runs significantly faster than earlier, smaller and less-capable models. These custom-designed AI accelerators have been at the heart of Google's AI-powered products that serve billions of users like Search, YouTube, Gmail, Google Maps, Google Play and Android. They’ve also enabled companies around the world to train large-scale AI models cost-efficiently.Today, we’re announcing the most powerful, efficient and scalable TPU system to date, Cloud TPU v5p, designed for training cutting-edge AI models. This next generation TPU will accelerate Gemini’s development and help developers and enterprise customers train large-scale generative AI models faster, allowing new products and capabilities to reach customers sooner.\\n\\n\\n\\n\\n\\n\\nA row of Cloud TPU v5p AI accelerator supercomputers in a Google data center.\\n\\n\\n\\n\\nBuilt with responsibility and safety at the coreAt Google, we’re committed to advancing bold and responsible AI in everything we do. Building upon Google’s AI Principles and the robust safety policies across our products, we’re adding new protections to account for Gemini’s multimodal capabilities. At each stage of development, we’re considering potential risks and working to test and mitigate them.Gemini has the most comprehensive safety evaluations of any Google AI model to date, including for bias and toxicity. We’ve conducted novel research into potential risk areas like cyber-offense, persuasion and autonomy, and have applied Google Research’s best-in-class adversarial testing techniques to help identify critical safety issues in advance of Gemini’s deployment.To identify blindspots in our internal evaluation approach, we’re working with a diverse group of external experts and partners to stress-test our models across a range of issues.To diagnose content safety issues during Gemini’s training phases and ensure its output follows our policies, we’re using benchmarks such as Real Toxicity Prompts, a set of 100,000 prompts with varying degrees of toxicity pulled from the web, developed by experts at the Allen Institute for AI. Further details on this work are coming soon.To limit harm, we built dedicated safety classifiers to identify, label and sort out content involving violence or negative stereotypes, for example. Combined with robust filters, this layered approach is designed to make Gemini safer and more inclusive for everyone. Additionally, we’re continuing to address known challenges for models such as factuality, grounding, attribution and corroboration.Responsibility and safety will always be central to the development and deployment of our models. This is a long-term commitment that requires building collaboratively, so we’re partnering with the industry and broader ecosystem on defining best practices and setting safety and security benchmarks through organizations like MLCommons, the Frontier Model Forum and its AI Safety Fund, and our Secure AI Framework (SAIF), which was designed to help mitigate security risks specific to AI systems across the public and private sectors. We’ll continue partnering with researchers, governments and civil society groups around the world as we develop Gemini.\\n\\n\\n\\n\\n\\nMaking Gemini available to the worldGemini 1.0 is now rolling out across a range of products and platforms:Gemini Pro in Google productsWe’re bringing Gemini to billions of people through Google products.Starting today, Bard will use a fine-tuned version of Gemini Pro for more advanced reasoning, planning, understanding and more. This is the biggest upgrade to Bard since it launched. It will be available in English in more than 170 countries and territories, and we plan to expand to different modalities and support new languages and locations in the near future.We’re also bringing Gemini to Pixel. Pixel 8 Pro is the first smartphone engineered to run Gemini Nano, which is powering new features like Summarize in the Recorder app and rolling out in Smart Reply in Gboard, starting with WhatsApp, Line and KakaoTalk1 — with more messaging apps coming next year.In the coming months, Gemini will be available in more of our products and services like Search, Ads, Chrome and Duet AI.We’re already starting to experiment with Gemini in Search, where it's making our Search Generative Experience (SGE) faster for users, with a 40% reduction in latency in English in the U.S., alongside improvements in quality.Building with GeminiStarting on December 13, developers and enterprise customers can access Gemini Pro via the Gemini API in Google AI Studio or Google Cloud Vertex AI.Google AI Studio is a free, web-based developer tool to prototype and launch apps quickly with an API key. When it's time for a fully-managed AI platform, Vertex AI allows customization of Gemini with full data control and benefits from additional Google Cloud features for enterprise security, safety, privacy and data governance and compliance.Android developers will also be able to build with Gemini Nano, our most efficient model for on-device tasks, via AICore, a new system capability available in Android 14, starting on Pixel 8 Pro devices. Sign up for an early preview of AICore.Gemini Ultra coming soonFor Gemini Ultra, we’re currently completing extensive trust and safety checks, including red-teaming by trusted external parties, and further refining the model using fine-tuning and reinforcement learning from human feedback (RLHF) before making it broadly available.As part of this process, we’ll make Gemini Ultra available to select customers, developers, partners and safety and responsibility experts for early experimentation and feedback before rolling it out to developers and enterprise customers early next year.Early next year, we’ll also launch Bard Advanced, a new, cutting-edge AI experience that gives you access to our best models and capabilities, starting with Gemini Ultra.\\n\\n\\n\\n\\nThe Gemini era: enabling a future of innovationThis is a significant milestone in the development of AI, and the start of a new era for us at Google as we continue to rapidly innovate and responsibly advance the capabilities of our models.We’ve made great progress on Gemini so far and we’re working hard to further extend its capabilities for future versions, including advances in planning and memory, and increasing the context window for processing even more information to give better responses.We’re excited by the amazing possibilities of a world responsibly empowered by AI — a future of innovation that will enhance creativity, extend knowledge, advance science and transform the way billions of people live and work around the world.\\n\\n\\n\\n\\n\\n\\n\\n\\nCollection\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nCollection\\n\\nMore about Gemini\\nExplore our collection to find out more about Gemini, the most capable and general model we’ve ever built.\\n\\nSee more\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Get more stories from Google in your inbox.\\n \\n\\n\\n\\n\\n\\n Email address\\n \\n\\n\\n\\n\\n\\n Your information will be used in accordance with\\n \\nGoogle's privacy policy.\\n\\n\\n Subscribe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nDone. Just one step more.\\n\\nCheck your inbox to confirm your subscription.\\n\\nYou are already subscribed to our newsletter.\\n\\n\\n\\n You can also subscribe with a\\n \\ndifferent email address\\n\\n .\\n \\n\\n\\n\\n\\n\\n\\nPOSTED IN:\\n\\n\\n\\n\\n\\n\\nAI\\n\\n\\n \\n\\n\\n\\n\\n\\nGemini\\n\\n\\n \\n\\n\\n\\n\\n\\nDevelopers\\n\\n\\n \\n\\n\\n\\n\\n\\nGoogle Cloud\\n\\n\\n \\n\\n\\n\\n\\n\\nResearch\\n\\n\\n \\n\\n\\n\\n\\n\\nGoogle DeepMind\\n\\n\\n \\n\\n\\n\\n\\n\\nPixel\\n\\n\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nRead Article\\n\\n\\n\\n\\n\\n\\n\\nMore Information\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n1\\n\\nUpdated on Dec 13 to include additional messaging apps\\n\\n\\n\\nCollapse\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Related stories\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPixel\\nJune Feature Drop: New features and upgrades for the Pixel portfolio\\n\\n\\n\\n By\\n \\n \\n Mikaela Kraft\\n \\n\\n Jun 11, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nEntrepreneurs\\nSupport for European and Israeli startups working on AI and climate solutions\\n\\n\\n\\n By\\n \\n \\n Matt Brittin\\n \\n\\n Jun 11, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nAI\\nNotebookLM goes global with Slides support and better ways to fact-check\\n\\n\\n\\n By\\n \\n \\n Steven Johnson\\n \\n\\n Raiza Martin\\n \\n\\n Jun 06, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nArts & Culture\\nA new AI tool to help monitor coral reef health\\n\\n\\n\\n By\\n \\n \\n Steve Simpson\\n \\n\\n Ben Williams\\n \\n\\n Jun 06, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nAI\\nI tried 8 of our newest AI products and updates\\n\\n\\n\\n By\\n \\n \\n Chaim Gartenberg\\n \\n\\n Jun 05, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nEntrepreneurs\\nApply to our new program for startups using AI to improve U.S. infrastructure\\n\\n\\n\\n By\\n \\n \\n Lisa Gevelber\\n \\n\\n Jun 05, 2024\\n\\n\\n\\n\\n\\n\\n.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nLet’s stay in touch. Get the latest news from Google in your inbox.\\n\\n\\nSubscribe\\nNo thanks\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Follow Us\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPrivacy\\n \\n\\n\\nTerms\\n \\n\\n\\nAbout Google\\n \\n\\n\\nGoogle Products\\n \\n\\n\\nAbout the Keyword\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Help\\n \\n\\n\\n\\n\\n\\n Deutsch\\n \\n\\n English\\n \\n\\n English (Africa)\\n \\n\\n English (Australia)\\n \\n\\n English (Canada)\\n \\n\\n English (India)\\n \\n\\n English (MENA)\\n \\n\\n Español (España)\\n \\n\\n Español (Latinoamérica)\\n \\n\\n Français (Canada)\\n \\n\\n Français (France)\\n \\n\\n Italiano\\n \\n\\n Nederlands (Nederland)\\n \\n\\n Polski\\n \\n\\n Português (Brasil)\\n \\n\\n اللغة العربية (MENA)\\n \\n\\n 日本語 (日本)\\n \\n\\n 한국어\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\", metadata={'source': 'https://blog.google/technology/ai/google-gemini-ai/#sundar-note', 'title': 'Introducing Gemini: Google’s most capable AI model yet', 'description': 'Gemini is our most capable and general model, built to be multimodal and optimized for three different sizes: Ultra, Pro and Nano.', 'language': 'en-us'})]\n" + ] + } + ], + "source": [ + "loader = WebBaseLoader(\"https://blog.google/technology/ai/google-gemini-ai/#sundar-note\")\n", + "docs = loader.load()\n", + "\n", + "print(docs)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4xlf_F_4B6lB" + }, + "source": [ + "### Initialize Gemini\n", + "\n", + "You must import the `ChatGoogleGenerativeAI` LLM from LangChain to initialize your model.\n", + " In this example you will use **gemini-pro**, as it supports text summarization. To know more about the text model, read Google AI's [language documentation](https://ai.google.dev/models/gemini).\n", + "\n", + "You can configure the model parameters such as ***temperature*** or ***top_p***, by passing the appropriate values when creating the `ChatGoogleGenerativeAI` LLM. To learn more about the parameters and their uses, read Google AI's [concepts guide](https://ai.google.dev/docs/concepts#model_parameters)." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "WWA9F0ZqB-8k" + }, + "outputs": [], + "source": [ + "from langchain_google_genai import ChatGoogleGenerativeAI\n", + "\n", + "# If there is no env variable set for API key, you can pass the API key\n", + "# to the parameter `google_api_key` of the `ChatGoogleGenerativeAI` function:\n", + "# `google_api_key=\"key\"`.\n", + "\n", + "llm = ChatGoogleGenerativeAI(model=\"gemini-1.5-flash-latest\",\n", + " temperature=0.7, top_p=0.85)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "6TECDzaUSTvS" + }, + "source": [ + "### Create prompt templates\n", + "\n", + "You'll use LangChain's [PromptTemplate](https://python.langchain.com/docs/modules/model_io/prompts/prompt_templates/) to generate prompts for summarizing the text.\n", + "\n", + "To summarize the text from the website, you will need the following prompts.\n", + "1. Prompt to extract the data from the output of `WebBaseLoader`, named `doc_prompt`\n", + "2. Prompt for the LLM model (Gemini) to summarize the extracted text, named `llm_prompt`.\n", + "\n", + "In the `llm_prompt`, the variable `text` will be replaced later by the text from the website." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "rixvvvaNKLe_", + "outputId": "9c433a7b-056f-4f61-ea02-bfadd35b521b" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "input_variables=['text'] template='Write a concise summary of the following:\\n\"{text}\"\\nCONCISE SUMMARY:'\n" + ] + } + ], + "source": [ + "# To extract data from WebBaseLoader\n", + "doc_prompt = PromptTemplate.from_template(\"{page_content}\")\n", + "\n", + "# To query Gemini\n", + "llm_prompt_template = \"\"\"Write a concise summary of the following:\n", + "\"{text}\"\n", + "CONCISE SUMMARY:\"\"\"\n", + "llm_prompt = PromptTemplate.from_template(llm_prompt_template)\n", + "\n", + "print(llm_prompt)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-wPBMFyISh13" + }, + "source": [ + "### Create a Stuff documents chain\n", + "\n", + "LangChain provides [Chains](https://python.langchain.com/docs/modules/chains/) for chaining together LLMs with each other or other components for complex applications. You will create a **Stuff documents chain** for this application. A **Stuff documents chain** lets you combine all the documents, insert them into the prompt and pass that prompt to the LLM.\n", + "\n", + "You can create a Stuff documents chain using the [LangChain Expression Language (LCEL)](https://python.langchain.com/docs/expression_language).\n", + "\n", + "To learn more about different types of document chains, read LangChain's [chains guide](https://python.langchain.com/docs/modules/chains/document/)." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "EMZomQdyKMr5" + }, + "outputs": [], + "source": [ + "# Create Stuff documents chain using LCEL.\n", + "# This is called a chain because you are chaining\n", + "# together different elements with the LLM.\n", + "# In the following example, to create stuff chain,\n", + "# you will combine content, prompt, LLM model and\n", + "# output parser together like a chain using LCEL.\n", + "#\n", + "# The chain implements the following pipeline:\n", + "# 1. Extract data from documents and save to variable `text`.\n", + "# 2. This `text` is then passed to the prompt and input variable\n", + "# in prompt is populated.\n", + "# 3. The prompt is then passed to the LLM (Gemini).\n", + "# 4. Output from the LLM is passed through an output parser\n", + "# to structure the model response.\n", + "\n", + "stuff_chain = (\n", + " # Extract data from the documents and add to the key `text`.\n", + " {\n", + " \"text\": lambda docs: \"\\n\\n\".join(\n", + " format_document(doc, doc_prompt) for doc in docs\n", + " )\n", + " }\n", + " | llm_prompt # Prompt for Gemini\n", + " | llm # Gemini function\n", + " | StrOutputParser() # output parser\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5L0Tvk_5eQzC" + }, + "source": [ + "### Prompt the model\n", + "\n", + "To generate the summary of the the website data, pass the documents extracted using the `WebBaseLoader` (`docs`) to `invoke()`." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 105 + }, + "id": "k9_GxkA5ePRR", + "outputId": "c1557d48-0d79-4a37-a970-0d8c83776025" + }, + "outputs": [ + { + "data": { + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + }, + "text/plain": [ + "'Google has announced Gemini, its most advanced AI model yet. Gemini is multimodal, meaning it can understand and process various types of information, including text, code, audio, images, and video. It surpasses existing models in performance across various benchmarks, particularly in reasoning and multimodal tasks. \\n\\nGemini is available in three sizes: Ultra, Pro, and Nano. Gemini Pro is being integrated into Google products like Bard, Pixel, and Search, while Gemini Nano is available for on-device tasks. Developers can access Gemini Pro through APIs, and Gemini Ultra will be available for early access soon. \\n\\nGoogle emphasizes its commitment to responsible AI development, including comprehensive safety evaluations and collaborations with external experts to mitigate potential risks. The company sees Gemini as a major step towards a future where AI empowers innovation, creativity, and knowledge advancement for everyone. \\n'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "stuff_chain.invoke(docs)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nfrBsxUFgZzc" + }, + "source": [ + "# Conclusion\n", + "\n", + "That's it. You have successfully created an LLM application to summarize text using LangChain and Gemini." + ] + } + ], + "metadata": { + "colab": { + "name": "Gemini_LangChain_Summarization_WebLoad.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From 1022d71ae79d9e19427af5d1d4dd74217269598e Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Tue, 11 Jun 2024 12:59:16 -0700 Subject: [PATCH 4/9] Reformat notebooks --- .../Gemini_LangChain_QA_Chroma_WebLoad.ipynb | 64 ++++++------------- ...mini_LangChain_Summarization_WebLoad.ipynb | 39 ++--------- 2 files changed, 27 insertions(+), 76 deletions(-) diff --git a/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb index 4a6ce3a83..ac0cbedc4 100644 --- a/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb +++ b/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb @@ -13,6 +13,7 @@ "cell_type": "code", "execution_count": 1, "metadata": { + "cellView": "form", "id": "tuOe1ymfHZPu" }, "outputs": [], @@ -88,16 +89,12 @@ "cell_type": "code", "execution_count": 5, "metadata": { - "id": "olK4Ejjzuj76", - "outputId": "363f1bfb-f493-4d97-b772-6aaf0ba9d942", - "colab": { - "base_uri": "https://localhost:8080/" - } + "id": "olK4Ejjzuj76" }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m1.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.2/49.2 kB\u001b[0m \u001b[31m1.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", @@ -116,16 +113,12 @@ "cell_type": "code", "execution_count": 6, "metadata": { - "id": "TcvGPVdXu05F", - "outputId": "ff08a3b2-1541-4d32-9279-2875dbcf33d4", - "colab": { - "base_uri": "https://localhost:8080/" - } + "id": "TcvGPVdXu05F" }, "outputs": [ { - "output_type": "stream", "name": "stderr", + "output_type": "stream", "text": [ "WARNING:root:USER_AGENT environment variable not set, consider setting it to identify your requests.\n" ] @@ -159,11 +152,7 @@ "cell_type": "code", "execution_count": 7, "metadata": { - "id": "xId4sR52utS0", - "outputId": "f6c160b6-5f74-4011-de39-1836cf0ee6a0", - "colab": { - "base_uri": "https://localhost:8080/" - } + "id": "xId4sR52utS0" }, "outputs": [ { @@ -370,24 +359,20 @@ "cell_type": "code", "execution_count": 12, "metadata": { - "id": "s3t4kmzIOZQq", - "outputId": "c419b8ee-2603-4337-a6dd-8bb2f3d4b2da", - "colab": { - "base_uri": "https://localhost:8080/" - } + "id": "s3t4kmzIOZQq" }, "outputs": [ { - "output_type": "stream", "name": "stderr", + "output_type": "stream", "text": [ "/usr/local/lib/python3.10/dist-packages/langchain_core/_api/deprecation.py:119: LangChainDeprecationWarning: The method `BaseRetriever.get_relevant_documents` was deprecated in langchain-core 0.1.46 and will be removed in 0.3.0. Use invoke instead.\n", " warn_deprecated(\n" ] }, { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "1\n" ] @@ -483,16 +468,12 @@ "cell_type": "code", "execution_count": 14, "metadata": { - "id": "90Czqh074dEC", - "outputId": "626affcd-002b-447c-bd6b-b06c316cf67e", - "colab": { - "base_uri": "https://localhost:8080/" - } + "id": "90Czqh074dEC" }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "input_variables=['context', 'question'] template=\"You are an assistant for question-answering tasks.\\nUse the following context to answer the question.\\nIf you don't know the answer, just say that you don't know.\\nUse five sentences maximum and keep the answer concise.\\n\\nQuestion: {question} \\nContext: {context} \\nAnswer:\"\n" ] @@ -580,26 +561,21 @@ "cell_type": "code", "execution_count": 16, "metadata": { - "id": "4vIaopCsIq0B", - "outputId": "b40c9bcb-3add-49d7-b024-a4020c8a17e2", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 70 - } + "id": "4vIaopCsIq0B" }, "outputs": [ { - "output_type": "execute_result", "data": { - "text/plain": [ - "\"Gemini is Google's largest and most capable AI model, designed to be flexible and efficient across various platforms. It excels in a wide range of tasks, including natural language understanding, image and video comprehension, mathematical reasoning, and coding. Gemini comes in three sizes: Ultra, Pro, and Nano, each optimized for different use cases. Gemini Ultra has achieved state-of-the-art performance on multiple benchmarks, surpassing human experts in some areas. \\n\"" - ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" - } + }, + "text/plain": [ + "\"Gemini is Google's largest and most capable AI model, designed to be flexible and efficient across various platforms. It excels in a wide range of tasks, including natural language understanding, image and video comprehension, mathematical reasoning, and coding. Gemini comes in three sizes: Ultra, Pro, and Nano, each optimized for different use cases. Gemini Ultra has achieved state-of-the-art performance on multiple benchmarks, surpassing human experts in some areas. \\n\"" + ] }, + "execution_count": 16, "metadata": {}, - "execution_count": 16 + "output_type": "execute_result" } ], "source": [ @@ -621,7 +597,7 @@ "metadata": { "colab": { "name": "Gemini_LangChain_QA_Chroma_WebLoad.ipynb", - "provenance": [] + "toc_visible": true }, "kernelspec": { "display_name": "Python 3", @@ -630,4 +606,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb index 27955b765..e2c8347e0 100644 --- a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb +++ b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb @@ -87,11 +87,7 @@ "cell_type": "code", "execution_count": 5, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "yERdO0eFJpb-", - "outputId": "b9b9c5b4-6053-45a0-97ec-1e12deea86e4" + "id": "yERdO0eFJpb-" }, "outputs": [ { @@ -113,11 +109,7 @@ "cell_type": "code", "execution_count": 6, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "rAv0UicpKARZ", - "outputId": "5e7c1c21-5f9b-4d2e-d656-eec1e630c8ed" + "id": "rAv0UicpKARZ" }, "outputs": [ { @@ -160,11 +152,7 @@ "cell_type": "code", "execution_count": 2, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "1RO5jvTTddtc", - "outputId": "5d907186-56c4-4399-968d-bc9c83e0d1c5" + "id": "1RO5jvTTddtc" }, "outputs": [ { @@ -220,11 +208,7 @@ "cell_type": "code", "execution_count": 7, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "TTgmyxXzKCSq", - "outputId": "1bcf9e38-afe7-43a6-8093-434bb91fc212" + "id": "TTgmyxXzKCSq" }, "outputs": [ { @@ -295,11 +279,7 @@ "cell_type": "code", "execution_count": 9, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "rixvvvaNKLe_", - "outputId": "9c433a7b-056f-4f61-ea02-bfadd35b521b" + "id": "rixvvvaNKLe_" }, "outputs": [ { @@ -389,12 +369,7 @@ "cell_type": "code", "execution_count": 11, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 105 - }, - "id": "k9_GxkA5ePRR", - "outputId": "c1557d48-0d79-4a37-a970-0d8c83776025" + "id": "k9_GxkA5ePRR" }, "outputs": [ { @@ -430,7 +405,7 @@ "metadata": { "colab": { "name": "Gemini_LangChain_Summarization_WebLoad.ipynb", - "provenance": [] + "toc_visible": true }, "kernelspec": { "display_name": "Python 3", From 18b17847894989b6148e5f5e355122a1319c716b Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Tue, 11 Jun 2024 13:02:23 -0700 Subject: [PATCH 5/9] Update basic code generation --- .../prompting/Basic_Code_Generation.ipynb | 138 +----------------- 1 file changed, 8 insertions(+), 130 deletions(-) diff --git a/examples/prompting/Basic_Code_Generation.ipynb b/examples/prompting/Basic_Code_Generation.ipynb index 216a03b3a..0762008fc 100644 --- a/examples/prompting/Basic_Code_Generation.ipynb +++ b/examples/prompting/Basic_Code_Generation.ipynb @@ -11,15 +11,7 @@ }, { "cell_type": "code", -<<<<<<< HEAD -<<<<<<< HEAD "execution_count": null, -======= - "execution_count": 1, ->>>>>>> 757cc02 (Update basic code generation) -======= - "execution_count": null, ->>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": { "cellView": "form", "id": "vQoUR__bUlfj" @@ -74,15 +66,7 @@ }, { "cell_type": "code", -<<<<<<< HEAD -<<<<<<< HEAD - "execution_count": 1, -======= - "execution_count": 2, ->>>>>>> 757cc02 (Update basic code generation) -======= - "execution_count": 1, ->>>>>>> 7c65d32 (Update notebook with shorter prompt) + "execution_count": null, "metadata": { "id": "Ne-3gnXqR0hI" }, @@ -93,15 +77,7 @@ }, { "cell_type": "code", -<<<<<<< HEAD -<<<<<<< HEAD - "execution_count": 2, -======= - "execution_count": 3, ->>>>>>> 757cc02 (Update basic code generation) -======= - "execution_count": 2, ->>>>>>> 7c65d32 (Update notebook with shorter prompt) + "execution_count": null, "metadata": { "id": "EconMHePQHGw" }, @@ -125,15 +101,7 @@ }, { "cell_type": "code", -<<<<<<< HEAD -<<<<<<< HEAD - "execution_count": 3, -======= - "execution_count": 4, ->>>>>>> 757cc02 (Update basic code generation) -======= - "execution_count": 3, ->>>>>>> 7c65d32 (Update notebook with shorter prompt) + "execution_count": null, "metadata": { "id": "v-JZzORUpVR2" }, @@ -165,60 +133,11 @@ }, { "cell_type": "code", -<<<<<<< HEAD -<<<<<<< HEAD - "execution_count": 4, -======= - "execution_count": 5, ->>>>>>> 757cc02 (Update basic code generation) -======= - "execution_count": 4, ->>>>>>> 7c65d32 (Update notebook with shorter prompt) + "execution_count": null, "metadata": { "id": "kVF8ZQ38Vs1P" }, "outputs": [], -<<<<<<< HEAD - "source": [ - "error_handling_system_prompt =f\"\"\"\n", - "Your task is to explain exactly why this error occurred and how to fix it.\n", - "\"\"\"\n", - "error_handling_model = genai.GenerativeModel(model_name='gemini-1.5-flash-latest', generation_config={\"temperature\": 0},\n", - " system_instruction=error_handling_system_prompt)" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "id": "CHTdAVE0pIFf" - }, - "outputs": [ - { - "data": { - "text/markdown": "The error message \"IndexError: list index out of range\" means you're trying to access an element in a list using an index that doesn't exist.\n\n**Explanation:**\n\n* **List Indexing:** In Python, lists are zero-indexed. This means the first element has an index of 0, the second element has an index of 1, and so on.\n* **Your Code:** In your code, `my_list = [1, 2, 3]` has three elements. The valid indices for this list are 0, 1, and 2.\n* **The Error:** You're trying to access `my_list[3]`. Since the list only has three elements, there is no element at index 3. This causes the \"IndexError: list index out of range\" error.\n\n**How to Fix It:**\n\n1. **Check the Index:** Ensure the index you're using is within the valid range of the list. In this case, you should use an index between 0 and 2.\n2. **Adjust the Code:** To access the last element of the list, use `my_list[2]`.\n\n**Corrected Code:**\n\n```python\nmy_list = [1, 2, 3]\nprint(my_list[2]) # This will print 3\n```\n\n**Important Note:** Always be mindful of the size of your lists and the indices you use to avoid this common error. \n", - "text/plain": [ - "" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "error_message = \"\"\"\n", - " 1 my_list = [1,2,3]\n", - "----> 2 print(my_list[3])\n", - "\n", - "IndexError: list index out of range\n", - "\"\"\"\n", - "\n", - "error_prompt = f\"\"\"\n", - "You've encountered the following error message:\n", - "Error Message: {error_message}\"\"\"\n", - "\n", -======= "source": [ "error_handling_system_prompt =f\"\"\"\n", "Your task is to explain exactly why this error occurred and how to fix it.\n", @@ -229,7 +148,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { "id": "CHTdAVE0pIFf" }, @@ -258,7 +177,6 @@ "You've encountered the following error message:\n", "Error Message: {error_message}\"\"\"\n", "\n", ->>>>>>> 757cc02 (Update basic code generation) "Markdown(error_handling_model.generate_content(error_prompt).text)" ] }, @@ -273,15 +191,7 @@ }, { "cell_type": "code", -<<<<<<< HEAD -<<<<<<< HEAD - "execution_count": 6, -======= - "execution_count": 7, ->>>>>>> 757cc02 (Update basic code generation) -======= - "execution_count": 6, ->>>>>>> 7c65d32 (Update notebook with shorter prompt) + "execution_count": null, "metadata": { "id": "1T1QSzjVVvE_" }, @@ -300,15 +210,7 @@ }, { "cell_type": "code", -<<<<<<< HEAD -<<<<<<< HEAD - "execution_count": 7, -======= - "execution_count": 8, ->>>>>>> 757cc02 (Update basic code generation) -======= - "execution_count": 7, ->>>>>>> 7c65d32 (Update notebook with shorter prompt) + "execution_count": null, "metadata": { "id": "8KVpzExDqRj2" }, @@ -320,15 +222,7 @@ "" ] }, -<<<<<<< HEAD -<<<<<<< HEAD - "execution_count": 7, -======= - "execution_count": 8, ->>>>>>> 757cc02 (Update basic code generation) -======= "execution_count": 7, ->>>>>>> 7c65d32 (Update notebook with shorter prompt) "metadata": {}, "output_type": "execute_result" } @@ -350,15 +244,7 @@ }, { "cell_type": "code", -<<<<<<< HEAD -<<<<<<< HEAD - "execution_count": 8, -======= - "execution_count": 9, ->>>>>>> 757cc02 (Update basic code generation) -======= - "execution_count": 8, ->>>>>>> 7c65d32 (Update notebook with shorter prompt) + "execution_count": null, "metadata": { "id": "lOU_abTPSmZu" }, @@ -400,15 +286,7 @@ ], "metadata": { "colab": { -<<<<<<< HEAD -<<<<<<< HEAD - "name": "Basic_code_generation.ipynb", -======= "name": "Basic_Code_Generation.ipynb", ->>>>>>> 757cc02 (Update basic code generation) -======= - "name": "Basic_code_generation.ipynb", ->>>>>>> 7c65d32 (Update notebook with shorter prompt) "toc_visible": true }, "kernelspec": { From 1c5430ecf11614cf62166131a323c9f6e7e2a47e Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Thu, 13 Jun 2024 12:58:55 -0700 Subject: [PATCH 6/9] Revise summarize large documents notebook --- ...mini_LangChain_Summarization_WebLoad.ipynb | 97 ++++++++----------- 1 file changed, 43 insertions(+), 54 deletions(-) diff --git a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb index e2c8347e0..963966f4b 100644 --- a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb +++ b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "cellView": "form", "id": "tuOe1ymfHZPu" @@ -48,7 +48,7 @@ "source": [ "\n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", "
\n" ] @@ -61,11 +61,11 @@ "source": [ "## Overview\n", "\n", - "[Gemini](https://ai.google.dev/models/gemini) is a family of generative AI models that lets developers generate content and solve problems. These models are designed and trained to handle both text and images as input.\n", + "The [Gemini](https://ai.google.dev/models/gemini) models are a family of generative AI models that allow developers generate content and solve problems. These models are designed and trained to handle both text and images as input.\n", "\n", "[LangChain](https://www.langchain.com/) is a framework designed to make integration of Large Language Models (LLM) like Gemini easier for applications.\n", "\n", - "In this notebook, you'll learn how to create an application to summarize large documents using Gemini and LangChain.\n" + "In this notebook, you'll learn how to create an application to summarize large documents using the Gemini API and LangChain.\n" ] }, { @@ -80,12 +80,12 @@ "\n", "### Installation\n", "\n", - "Install LangChain's Python library, `langchain` and LangChain's integration package for Gemini, `langchain-google-genai`." + "Install LangChain's Python library, `langchain` and LangChain's integration package for the Gemini API, `langchain-google-genai`. Installing `langchain-community` allows you to use the `WebBaseLoader` tool shown later in this example." ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": { "id": "yERdO0eFJpb-" }, @@ -94,20 +94,26 @@ "name": "stdout", "output_type": "stream", "text": [ - "Installing collected packages: mypy-extensions, marshmallow, typing-inspect, dataclasses-json, langchain-community\n", - "Successfully installed dataclasses-json-0.6.7 langchain-community-0.2.4 marshmallow-3.21.3 mypy-extensions-1.0.0 typing-inspect-0.9.0\n" + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m974.0/974.0 kB\u001b[0m \u001b[31m7.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m314.7/314.7 kB\u001b[0m \u001b[31m10.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m125.2/125.2 kB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.7/142.7 kB\u001b[0m \u001b[31m8.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m11.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.2/49.2 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h" ] } ], "source": [ "!pip install --quiet langchain\n", "!pip install --quiet langchain-google-genai\n", - "!pip install -U langchain-community" + "!pip install --quiet -U langchain-community" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": { "id": "rAv0UicpKARZ" }, @@ -127,48 +133,28 @@ "from langchain.schema.prompt_template import format_document" ] }, - { - "cell_type": "markdown", - "metadata": { - "id": "ycFMUTxn0VoI" - }, - "source": [ - "### Grab an API Key\n" - ] - }, { "cell_type": "markdown", "metadata": { "id": "e1dZNWvUzksX" }, "source": [ - "To use Gemini you need an *API key*. You can create an API key with one click in [Google AI Studio](https://makersuite.google.com/).\n", - "After creating the API key, you can either set an environment variable named `GOOGLE_API_KEY` to your API Key or pass the API key as an argument when creating the `ChatGoogleGenerativeAI` LLM using `LangChain`.\n", + "## Configure your API key\n", "\n", - "In this tutorial, you will set the environment variable `GOOGLE_API_KEY` to configure Gemini to use your API key." + "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](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb) for an example." ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": { "id": "1RO5jvTTddtc" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Gemini API Key:··········\n" - ] - } - ], + "outputs": [], "source": [ "# Run this cell and paste the API key in the prompt\n", - "import os\n", - "import getpass\n", - "\n", - "os.environ['GOOGLE_API_KEY'] = getpass.getpass('Gemini API Key:')" + "from google.colab import userdata\n", + "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')" ] }, { @@ -186,7 +172,7 @@ "2. Chain together the following:\n", " * A prompt for extracting the required input data from the parsed website data.\n", " * A prompt for summarizing the text using LangChain.\n", - " * An LLM model (Gemini) for prompting.\n", + " * An LLM model (such as the Gemini model) for prompting.\n", "\n", "3. Run the created chain to prompt the model for the summary of the website data." ] @@ -206,7 +192,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": { "id": "TTgmyxXzKCSq" }, @@ -215,7 +201,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[Document(page_content=\"\\n\\n\\n\\n\\n\\nIntroducing Gemini: Google’s most capable AI model yet\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nSkip to main content\\n\\n\\n\\n\\n\\n The Keyword\\n \\n\\n\\n\\n\\n Introducing Gemini: our largest and most capable AI model\\n \\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Latest stories\\n \\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Android\\n \\n \\n\\n\\n\\n Chrome\\n \\n \\n\\n\\n\\n Chromebooks\\n \\n \\n\\n\\n\\n Google Play\\n \\n \\n\\n\\n\\n Wear OS by Google\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Chromecast\\n \\n \\n\\n\\n\\n Fitbit\\n \\n \\n\\n\\n\\n Google Nest\\n \\n \\n\\n\\n\\n Pixel\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Gemini\\n \\n \\n\\n\\n\\n Google Assistant\\n \\n \\n\\n\\n\\n Maps\\n \\n \\n\\n\\n\\n News\\n \\n \\n\\n\\n\\n Search\\n \\n \\n\\n\\n\\n Shopping\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Photos\\n \\n \\n\\n\\n\\n Translate\\n \\n \\n\\n\\n\\n Registry\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Docs, Sheets and Slides\\n \\n \\n\\n\\n\\n Gmail\\n \\n \\n\\n\\n\\n Google Cloud\\n \\n \\n\\n\\n\\n Meet\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n Android\\n\\n \\n \\n\\n\\n\\n Chrome\\n\\n \\n \\n\\n\\n\\n Chromebooks\\n\\n \\n \\n\\n\\n\\n Google Play\\n\\n \\n \\n\\n\\n\\n Wear OS by Google\\n\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n Chromecast\\n\\n \\n \\n\\n\\n\\n Fitbit\\n\\n \\n \\n\\n\\n\\n Google Nest\\n\\n \\n \\n\\n\\n\\n Pixel\\n\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n Gemini\\n\\n \\n \\n\\n\\n\\n Google Assistant\\n\\n \\n \\n\\n\\n\\n Maps\\n\\n \\n \\n\\n\\n\\n News\\n\\n \\n \\n\\n\\n\\n Search\\n\\n \\n \\n\\n\\n\\n Shopping\\n\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n Photos\\n\\n \\n \\n\\n\\n\\n Translate\\n\\n \\n \\n\\n\\n\\n Registry\\n\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n Docs, Sheets and Slides\\n\\n \\n \\n\\n\\n\\n Gmail\\n\\n \\n \\n\\n\\n\\n Google Cloud\\n\\n \\n \\n\\n\\n\\n Meet\\n\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Diversity and inclusion\\n \\n \\n\\n\\n\\n Education\\n \\n \\n\\n\\n\\n Google.org\\n \\n \\n\\n\\n\\n Grow with Google\\n \\n \\n\\n\\n\\n Sustainability\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n AI\\n \\n \\n\\n\\n\\n Developers\\n \\n \\n\\n\\n\\n Families\\n \\n \\n\\n\\n\\n Next billion users\\n \\n \\n\\n\\n\\n Safety and security\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Data centers and infrastructure\\n \\n \\n\\n\\n\\n Doodles\\n \\n \\n\\n\\n\\n Googlers\\n \\n \\n\\n\\n\\n Life at Google\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Google in Asia\\n \\n \\n\\n\\n\\n Google in Europe\\n \\n \\n\\n\\n\\n Google in Latin America\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Sundar Pichai, CEO\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n Diversity and inclusion\\n\\n \\n \\n\\n\\n\\n Education\\n\\n \\n \\n\\n\\n\\n Google.org\\n\\n \\n \\n\\n\\n\\n Grow with Google\\n\\n \\n \\n\\n\\n\\n Sustainability\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n AI\\n\\n \\n \\n\\n\\n\\n Developers\\n\\n \\n \\n\\n\\n\\n Families\\n\\n \\n \\n\\n\\n\\n Next billion users\\n\\n \\n \\n\\n\\n\\n Safety and security\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n Data centers and infrastructure\\n\\n \\n \\n\\n\\n\\n Doodles\\n\\n \\n \\n\\n\\n\\n Googlers\\n\\n \\n \\n\\n\\n\\n Life at Google\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n Google in Asia\\n\\n \\n \\n\\n\\n\\n Google in Europe\\n\\n \\n \\n\\n\\n\\n Google in Latin America\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n Sundar Pichai, CEO\\n\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n The Keyword\\n \\n\\n\\n\\n\\n\\n\\n\\n Latest stories\\n \\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Android\\n \\n \\n\\n\\n\\n Chrome\\n \\n \\n\\n\\n\\n Chromebooks\\n \\n \\n\\n\\n\\n Google Play\\n \\n \\n\\n\\n\\n Wear OS by Google\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Chromecast\\n \\n \\n\\n\\n\\n Fitbit\\n \\n \\n\\n\\n\\n Google Nest\\n \\n \\n\\n\\n\\n Pixel\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Gemini\\n \\n \\n\\n\\n\\n Google Assistant\\n \\n \\n\\n\\n\\n Maps\\n \\n \\n\\n\\n\\n News\\n \\n \\n\\n\\n\\n Search\\n \\n \\n\\n\\n\\n Shopping\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Photos\\n \\n \\n\\n\\n\\n Translate\\n \\n \\n\\n\\n\\n Registry\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Docs, Sheets and Slides\\n \\n \\n\\n\\n\\n Gmail\\n \\n \\n\\n\\n\\n Google Cloud\\n \\n \\n\\n\\n\\n Meet\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Diversity and inclusion\\n \\n \\n\\n\\n\\n Education\\n \\n \\n\\n\\n\\n Google.org\\n \\n \\n\\n\\n\\n Grow with Google\\n \\n \\n\\n\\n\\n Sustainability\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n AI\\n \\n \\n\\n\\n\\n Developers\\n \\n \\n\\n\\n\\n Families\\n \\n \\n\\n\\n\\n Next billion users\\n \\n \\n\\n\\n\\n Safety and security\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Data centers and infrastructure\\n \\n \\n\\n\\n\\n Doodles\\n \\n \\n\\n\\n\\n Googlers\\n \\n \\n\\n\\n\\n Life at Google\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Google in Asia\\n \\n \\n\\n\\n\\n Google in Europe\\n \\n \\n\\n\\n\\n Google in Latin America\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Sundar Pichai, CEO\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPress corner\\n\\n\\n\\n\\n RSS feed\\n \\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nAI\\n\\n\\nIntroducing Gemini: our largest and most capable AI model\\n\\n\\n\\n\\n\\n\\n\\nDec 06, 2023\\n[[read-time]] min read\\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Making AI more helpful for everyone\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nSundar Pichai\\n\\n CEO of Google and Alphabet\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nDemis Hassabis\\n\\n CEO and Co-Founder, Google DeepMind\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nIn this story\\n\\n\\nIn this story\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nNote from Sundar\\n\\n\\nIntroducing Gemini\\n\\n\\nState-of-the-art performance\\n\\n\\nNext-generation capabilities\\n\\n\\nScalable and efficient\\n\\n\\nResponsibility and safety\\n\\n\\nAvailability\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nA note from Google and Alphabet CEO Sundar Pichai:Every technology shift is an opportunity to advance scientific discovery, accelerate human progress, and improve lives. I believe the transition we are seeing right now with AI will be the most profound in our lifetimes, far bigger than the shift to mobile or to the web before it. AI has the potential to create opportunities — from the everyday to the extraordinary — for people everywhere. It will bring new waves of innovation and economic progress and drive knowledge, learning, creativity and productivity on a scale we haven’t seen before.That’s what excites me: the chance to make AI helpful for everyone, everywhere in the world.Nearly eight years into our journey as an AI-first company, the pace of progress is only accelerating: Millions of people are now using generative AI across our products to do things they couldn’t even a year ago, from finding answers to more complex questions to using new tools to collaborate and create. At the same time, developers are using our models and infrastructure to build new generative AI applications, and startups and enterprises around the world are growing with our AI tools.This is incredible momentum, and yet, we’re only beginning to scratch the surface of what’s possible.We’re approaching this work boldly and responsibly. That means being ambitious in our research and pursuing the capabilities that will bring enormous benefits to people and society, while building in safeguards and working collaboratively with governments and experts to address risks as AI becomes more capable. And we continue to invest in the very best tools, foundation models and infrastructure and bring them to our products and to others, guided by our AI Principles.Now, we’re taking the next step on our journey with Gemini, our most capable and general model yet, with state-of-the-art performance across many leading benchmarks. Our first version, Gemini 1.0, is optimized for different sizes: Ultra, Pro and Nano. These are the first models of the Gemini era and the first realization of the vision we had when we formed Google DeepMind earlier this year. This new era of models represents one of the biggest science and engineering efforts we’ve undertaken as a company. I’m genuinely excited for what’s ahead, and for the opportunities Gemini will unlock for people everywhere.– Sundar\\n\\n\\n\\n\\n\\nIntroducing GeminiBy Demis Hassabis, CEO and Co-Founder of Google DeepMind, on behalf of the Gemini teamAI has been the focus of my life's work, as for many of my research colleagues. Ever since programming AI for computer games as a teenager, and throughout my years as a neuroscience researcher trying to understand the workings of the brain, I’ve always believed that if we could build smarter machines, we could harness them to benefit humanity in incredible ways.This promise of a world responsibly empowered by AI continues to drive our work at Google DeepMind. For a long time, we’ve wanted to build a new generation of AI models, inspired by the way people understand and interact with the world. AI that feels less like a smart piece of software and more like something useful and intuitive — an expert helper or assistant.Today, we’re a step closer to this vision as we introduce Gemini, the most capable and general model we’ve ever built.Gemini is the result of large-scale collaborative efforts by teams across Google, including our colleagues at Google Research. It was built from the ground up to be multimodal, which means it can generalize and seamlessly understand, operate across and combine different types of information including text, code, audio, image and video.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nIntroducing Gemini: our largest and most capable AI model\\n\\n\\n\\n\\n\\n\\nGemini is also our most flexible model yet — able to efficiently run on everything from data centers to mobile devices. Its state-of-the-art capabilities will significantly enhance the way developers and enterprise customers build and scale with AI.We’ve optimized Gemini 1.0, our first version, for three different sizes:Gemini Ultra — our largest and most capable model for highly complex tasks.Gemini Pro — our best model for scaling across a wide range of tasks.Gemini Nano — our most efficient model for on-device tasks.\\n\\n\\n\\n\\n\\nState-of-the-art performanceWe've been rigorously testing our Gemini models and evaluating their performance on a wide variety of tasks. From natural image, audio and video understanding to mathematical reasoning, Gemini Ultra’s performance exceeds current state-of-the-art results on 30 of the 32 widely-used academic benchmarks used in large language model (LLM) research and development.With a score of 90.0%, Gemini Ultra is the first model to outperform human experts on MMLU (massive multitask language understanding), which uses a combination of 57 subjects such as math, physics, history, law, medicine and ethics for testing both world knowledge and problem-solving abilities.Our new benchmark approach to MMLU enables Gemini to use its reasoning capabilities to think more carefully before answering difficult questions, leading to significant improvements over just using its first impression.\\n\\n\\n\\n\\n\\n\\nGemini surpasses state-of-the-art performance on a range of benchmarks including text and coding.\\n\\n\\n\\nGemini Ultra also achieves a state-of-the-art score of 59.4% on the new MMMU benchmark, which consists of multimodal tasks spanning different domains requiring deliberate reasoning.With the image benchmarks we tested, Gemini Ultra outperformed previous state-of-the-art models, without assistance from optical character recognition (OCR) systems that extract text from images for further processing. These benchmarks highlight Gemini’s native multimodality and indicate early signs of Gemini's more complex reasoning abilities.See more details in our Gemini technical report.\\n\\n\\n\\n\\n\\n\\nGemini surpasses state-of-the-art performance on a range of multimodal benchmarks.\\n\\n\\n\\n\\nNext-generation capabilitiesUntil now, the standard approach to creating multimodal models involved training separate components for different modalities and then stitching them together to roughly mimic some of this functionality. These models can sometimes be good at performing certain tasks, like describing images, but struggle with more conceptual and complex reasoning.We designed Gemini to be natively multimodal, pre-trained from the start on different modalities. Then we fine-tuned it with additional multimodal data to further refine its effectiveness. This helps Gemini seamlessly understand and reason about all kinds of inputs from the ground up, far better than existing multimodal models — and its capabilities are state of the art in nearly every domain.Learn more about Gemini’s capabilities and see how it works.Sophisticated reasoningGemini 1.0’s sophisticated multimodal reasoning capabilities can help make sense of complex written and visual information. This makes it uniquely skilled at uncovering knowledge that can be difficult to discern amid vast amounts of data.Its remarkable ability to extract insights from hundreds of thousands of documents through reading, filtering and understanding information will help deliver new breakthroughs at digital speeds in many fields from science to finance.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini unlocks new scientific insights\\n\\n\\n\\n\\n\\n\\nUnderstanding text, images, audio and moreGemini 1.0 was trained to recognize and understand text, images, audio and more at the same time, so it better understands nuanced information and can answer questions relating to complicated topics. This makes it especially good at explaining reasoning in complex subjects like math and physics.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini explains reasoning in math and physics\\n\\n\\n\\n\\n\\n\\nAdvanced codingOur first version of Gemini can understand, explain and generate high-quality code in the world’s most popular programming languages, like Python, Java, C++, and Go. Its ability to work across languages and reason about complex information makes it one of the leading foundation models for coding in the world.Gemini Ultra excels in several coding benchmarks, including HumanEval, an important industry-standard for evaluating performance on coding tasks, and Natural2Code, our internal held-out dataset, which uses author-generated sources instead of web-based information.Gemini can also be used as the engine for more advanced coding systems. Two years ago we presented AlphaCode, the first AI code generation system to reach a competitive level of performance in programming competitions.Using a specialized version of Gemini, we created a more advanced code generation system, AlphaCode 2, which excels at solving competitive programming problems that go beyond coding to involve complex math and theoretical computer science.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini excels at coding and competitive programming\\n\\n\\n\\n\\n\\n\\nWhen evaluated on the same platform as the original AlphaCode, AlphaCode 2 shows massive improvements, solving nearly twice as many problems, and we estimate that it performs better than 85% of competition participants — up from nearly 50% for AlphaCode. When programmers collaborate with AlphaCode 2 by defining certain properties for the code samples to follow, it performs even better.We’re excited for programmers to increasingly use highly capable AI models as collaborative tools that can help them reason about the problems, propose code designs and assist with implementation — so they can release apps and design better services, faster.See more details in our AlphaCode 2 technical report.\\n\\n\\n\\n\\n\\nMore reliable, scalable and efficientWe trained Gemini 1.0 at scale on our AI-optimized infrastructure using Google’s in-house designed Tensor Processing Units (TPUs) v4 and v5e. And we designed it to be our most reliable and scalable model to train, and our most efficient to serve.On TPUs, Gemini runs significantly faster than earlier, smaller and less-capable models. These custom-designed AI accelerators have been at the heart of Google's AI-powered products that serve billions of users like Search, YouTube, Gmail, Google Maps, Google Play and Android. They’ve also enabled companies around the world to train large-scale AI models cost-efficiently.Today, we’re announcing the most powerful, efficient and scalable TPU system to date, Cloud TPU v5p, designed for training cutting-edge AI models. This next generation TPU will accelerate Gemini’s development and help developers and enterprise customers train large-scale generative AI models faster, allowing new products and capabilities to reach customers sooner.\\n\\n\\n\\n\\n\\n\\nA row of Cloud TPU v5p AI accelerator supercomputers in a Google data center.\\n\\n\\n\\n\\nBuilt with responsibility and safety at the coreAt Google, we’re committed to advancing bold and responsible AI in everything we do. Building upon Google’s AI Principles and the robust safety policies across our products, we’re adding new protections to account for Gemini’s multimodal capabilities. At each stage of development, we’re considering potential risks and working to test and mitigate them.Gemini has the most comprehensive safety evaluations of any Google AI model to date, including for bias and toxicity. We’ve conducted novel research into potential risk areas like cyber-offense, persuasion and autonomy, and have applied Google Research’s best-in-class adversarial testing techniques to help identify critical safety issues in advance of Gemini’s deployment.To identify blindspots in our internal evaluation approach, we’re working with a diverse group of external experts and partners to stress-test our models across a range of issues.To diagnose content safety issues during Gemini’s training phases and ensure its output follows our policies, we’re using benchmarks such as Real Toxicity Prompts, a set of 100,000 prompts with varying degrees of toxicity pulled from the web, developed by experts at the Allen Institute for AI. Further details on this work are coming soon.To limit harm, we built dedicated safety classifiers to identify, label and sort out content involving violence or negative stereotypes, for example. Combined with robust filters, this layered approach is designed to make Gemini safer and more inclusive for everyone. Additionally, we’re continuing to address known challenges for models such as factuality, grounding, attribution and corroboration.Responsibility and safety will always be central to the development and deployment of our models. This is a long-term commitment that requires building collaboratively, so we’re partnering with the industry and broader ecosystem on defining best practices and setting safety and security benchmarks through organizations like MLCommons, the Frontier Model Forum and its AI Safety Fund, and our Secure AI Framework (SAIF), which was designed to help mitigate security risks specific to AI systems across the public and private sectors. We’ll continue partnering with researchers, governments and civil society groups around the world as we develop Gemini.\\n\\n\\n\\n\\n\\nMaking Gemini available to the worldGemini 1.0 is now rolling out across a range of products and platforms:Gemini Pro in Google productsWe’re bringing Gemini to billions of people through Google products.Starting today, Bard will use a fine-tuned version of Gemini Pro for more advanced reasoning, planning, understanding and more. This is the biggest upgrade to Bard since it launched. It will be available in English in more than 170 countries and territories, and we plan to expand to different modalities and support new languages and locations in the near future.We’re also bringing Gemini to Pixel. Pixel 8 Pro is the first smartphone engineered to run Gemini Nano, which is powering new features like Summarize in the Recorder app and rolling out in Smart Reply in Gboard, starting with WhatsApp, Line and KakaoTalk1 — with more messaging apps coming next year.In the coming months, Gemini will be available in more of our products and services like Search, Ads, Chrome and Duet AI.We’re already starting to experiment with Gemini in Search, where it's making our Search Generative Experience (SGE) faster for users, with a 40% reduction in latency in English in the U.S., alongside improvements in quality.Building with GeminiStarting on December 13, developers and enterprise customers can access Gemini Pro via the Gemini API in Google AI Studio or Google Cloud Vertex AI.Google AI Studio is a free, web-based developer tool to prototype and launch apps quickly with an API key. When it's time for a fully-managed AI platform, Vertex AI allows customization of Gemini with full data control and benefits from additional Google Cloud features for enterprise security, safety, privacy and data governance and compliance.Android developers will also be able to build with Gemini Nano, our most efficient model for on-device tasks, via AICore, a new system capability available in Android 14, starting on Pixel 8 Pro devices. Sign up for an early preview of AICore.Gemini Ultra coming soonFor Gemini Ultra, we’re currently completing extensive trust and safety checks, including red-teaming by trusted external parties, and further refining the model using fine-tuning and reinforcement learning from human feedback (RLHF) before making it broadly available.As part of this process, we’ll make Gemini Ultra available to select customers, developers, partners and safety and responsibility experts for early experimentation and feedback before rolling it out to developers and enterprise customers early next year.Early next year, we’ll also launch Bard Advanced, a new, cutting-edge AI experience that gives you access to our best models and capabilities, starting with Gemini Ultra.\\n\\n\\n\\n\\nThe Gemini era: enabling a future of innovationThis is a significant milestone in the development of AI, and the start of a new era for us at Google as we continue to rapidly innovate and responsibly advance the capabilities of our models.We’ve made great progress on Gemini so far and we’re working hard to further extend its capabilities for future versions, including advances in planning and memory, and increasing the context window for processing even more information to give better responses.We’re excited by the amazing possibilities of a world responsibly empowered by AI — a future of innovation that will enhance creativity, extend knowledge, advance science and transform the way billions of people live and work around the world.\\n\\n\\n\\n\\n\\n\\n\\n\\nCollection\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nCollection\\n\\nMore about Gemini\\nExplore our collection to find out more about Gemini, the most capable and general model we’ve ever built.\\n\\nSee more\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Get more stories from Google in your inbox.\\n \\n\\n\\n\\n\\n\\n Email address\\n \\n\\n\\n\\n\\n\\n Your information will be used in accordance with\\n \\nGoogle's privacy policy.\\n\\n\\n Subscribe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nDone. Just one step more.\\n\\nCheck your inbox to confirm your subscription.\\n\\nYou are already subscribed to our newsletter.\\n\\n\\n\\n You can also subscribe with a\\n \\ndifferent email address\\n\\n .\\n \\n\\n\\n\\n\\n\\n\\nPOSTED IN:\\n\\n\\n\\n\\n\\n\\nAI\\n\\n\\n \\n\\n\\n\\n\\n\\nGemini\\n\\n\\n \\n\\n\\n\\n\\n\\nDevelopers\\n\\n\\n \\n\\n\\n\\n\\n\\nGoogle Cloud\\n\\n\\n \\n\\n\\n\\n\\n\\nResearch\\n\\n\\n \\n\\n\\n\\n\\n\\nGoogle DeepMind\\n\\n\\n \\n\\n\\n\\n\\n\\nPixel\\n\\n\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nRead Article\\n\\n\\n\\n\\n\\n\\n\\nMore Information\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n1\\n\\nUpdated on Dec 13 to include additional messaging apps\\n\\n\\n\\nCollapse\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Related stories\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPixel\\nJune Feature Drop: New features and upgrades for the Pixel portfolio\\n\\n\\n\\n By\\n \\n \\n Mikaela Kraft\\n \\n\\n Jun 11, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nEntrepreneurs\\nSupport for European and Israeli startups working on AI and climate solutions\\n\\n\\n\\n By\\n \\n \\n Matt Brittin\\n \\n\\n Jun 11, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nAI\\nNotebookLM goes global with Slides support and better ways to fact-check\\n\\n\\n\\n By\\n \\n \\n Steven Johnson\\n \\n\\n Raiza Martin\\n \\n\\n Jun 06, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nArts & Culture\\nA new AI tool to help monitor coral reef health\\n\\n\\n\\n By\\n \\n \\n Steve Simpson\\n \\n\\n Ben Williams\\n \\n\\n Jun 06, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nAI\\nI tried 8 of our newest AI products and updates\\n\\n\\n\\n By\\n \\n \\n Chaim Gartenberg\\n \\n\\n Jun 05, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nEntrepreneurs\\nApply to our new program for startups using AI to improve U.S. infrastructure\\n\\n\\n\\n By\\n \\n \\n Lisa Gevelber\\n \\n\\n Jun 05, 2024\\n\\n\\n\\n\\n\\n\\n.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nLet’s stay in touch. Get the latest news from Google in your inbox.\\n\\n\\nSubscribe\\nNo thanks\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Follow Us\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPrivacy\\n \\n\\n\\nTerms\\n \\n\\n\\nAbout Google\\n \\n\\n\\nGoogle Products\\n \\n\\n\\nAbout the Keyword\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Help\\n \\n\\n\\n\\n\\n\\n Deutsch\\n \\n\\n English\\n \\n\\n English (Africa)\\n \\n\\n English (Australia)\\n \\n\\n English (Canada)\\n \\n\\n English (India)\\n \\n\\n English (MENA)\\n \\n\\n Español (España)\\n \\n\\n Español (Latinoamérica)\\n \\n\\n Français (Canada)\\n \\n\\n Français (France)\\n \\n\\n Italiano\\n \\n\\n Nederlands (Nederland)\\n \\n\\n Polski\\n \\n\\n Português (Brasil)\\n \\n\\n اللغة العربية (MENA)\\n \\n\\n 日本語 (日本)\\n \\n\\n 한국어\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\", metadata={'source': 'https://blog.google/technology/ai/google-gemini-ai/#sundar-note', 'title': 'Introducing Gemini: Google’s most capable AI model yet', 'description': 'Gemini is our most capable and general model, built to be multimodal and optimized for three different sizes: Ultra, Pro and Nano.', 'language': 'en-us'})]\n" + "[Document(page_content=\"\\n\\n\\n\\n\\n\\nIntroducing Gemini: Google’s most capable AI model yet\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nSkip to main content\\n\\n\\n\\n\\n\\n The Keyword\\n \\n\\n\\n\\n\\n Introducing Gemini: our largest and most capable AI model\\n \\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Latest stories\\n \\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Android\\n \\n \\n\\n\\n\\n Chrome\\n \\n \\n\\n\\n\\n Chromebooks\\n \\n \\n\\n\\n\\n Google Play\\n \\n \\n\\n\\n\\n Wear OS by Google\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Chromecast\\n \\n \\n\\n\\n\\n Fitbit\\n \\n \\n\\n\\n\\n Google Nest\\n \\n \\n\\n\\n\\n Pixel\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Gemini\\n \\n \\n\\n\\n\\n Google Assistant\\n \\n \\n\\n\\n\\n Maps\\n \\n \\n\\n\\n\\n News\\n \\n \\n\\n\\n\\n Search\\n \\n \\n\\n\\n\\n Shopping\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Photos\\n \\n \\n\\n\\n\\n Translate\\n \\n \\n\\n\\n\\n Registry\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Docs, Sheets and Slides\\n \\n \\n\\n\\n\\n Gmail\\n \\n \\n\\n\\n\\n Google Cloud\\n \\n \\n\\n\\n\\n Meet\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n Android\\n\\n \\n \\n\\n\\n\\n Chrome\\n\\n \\n \\n\\n\\n\\n Chromebooks\\n\\n \\n \\n\\n\\n\\n Google Play\\n\\n \\n \\n\\n\\n\\n Wear OS by Google\\n\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n Chromecast\\n\\n \\n \\n\\n\\n\\n Fitbit\\n\\n \\n \\n\\n\\n\\n Google Nest\\n\\n \\n \\n\\n\\n\\n Pixel\\n\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n Gemini\\n\\n \\n \\n\\n\\n\\n Google Assistant\\n\\n \\n \\n\\n\\n\\n Maps\\n\\n \\n \\n\\n\\n\\n News\\n\\n \\n \\n\\n\\n\\n Search\\n\\n \\n \\n\\n\\n\\n Shopping\\n\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n Photos\\n\\n \\n \\n\\n\\n\\n Translate\\n\\n \\n \\n\\n\\n\\n Registry\\n\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n Docs, Sheets and Slides\\n\\n \\n \\n\\n\\n\\n Gmail\\n\\n \\n \\n\\n\\n\\n Google Cloud\\n\\n \\n \\n\\n\\n\\n Meet\\n\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Diversity and inclusion\\n \\n \\n\\n\\n\\n Education\\n \\n \\n\\n\\n\\n Google.org\\n \\n \\n\\n\\n\\n Grow with Google\\n \\n \\n\\n\\n\\n Sustainability\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n AI\\n \\n \\n\\n\\n\\n Developers\\n \\n \\n\\n\\n\\n Families\\n \\n \\n\\n\\n\\n Next billion users\\n \\n \\n\\n\\n\\n Safety and security\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Data centers and infrastructure\\n \\n \\n\\n\\n\\n Doodles\\n \\n \\n\\n\\n\\n Googlers\\n \\n \\n\\n\\n\\n Life at Google\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Google in Asia\\n \\n \\n\\n\\n\\n Google in Europe\\n \\n \\n\\n\\n\\n Google in Latin America\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Sundar Pichai, CEO\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n Diversity and inclusion\\n\\n \\n \\n\\n\\n\\n Education\\n\\n \\n \\n\\n\\n\\n Google.org\\n\\n \\n \\n\\n\\n\\n Grow with Google\\n\\n \\n \\n\\n\\n\\n Sustainability\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n AI\\n\\n \\n \\n\\n\\n\\n Developers\\n\\n \\n \\n\\n\\n\\n Families\\n\\n \\n \\n\\n\\n\\n Next billion users\\n\\n \\n \\n\\n\\n\\n Safety and security\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n Data centers and infrastructure\\n\\n \\n \\n\\n\\n\\n Doodles\\n\\n \\n \\n\\n\\n\\n Googlers\\n\\n \\n \\n\\n\\n\\n Life at Google\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n Google in Asia\\n\\n \\n \\n\\n\\n\\n Google in Europe\\n\\n \\n \\n\\n\\n\\n Google in Latin America\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n Sundar Pichai, CEO\\n\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n The Keyword\\n \\n\\n\\n\\n\\n\\n\\n\\n Latest stories\\n \\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Android\\n \\n \\n\\n\\n\\n Chrome\\n \\n \\n\\n\\n\\n Chromebooks\\n \\n \\n\\n\\n\\n Google Play\\n \\n \\n\\n\\n\\n Wear OS by Google\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Chromecast\\n \\n \\n\\n\\n\\n Fitbit\\n \\n \\n\\n\\n\\n Google Nest\\n \\n \\n\\n\\n\\n Pixel\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Gemini\\n \\n \\n\\n\\n\\n Google Assistant\\n \\n \\n\\n\\n\\n Maps\\n \\n \\n\\n\\n\\n News\\n \\n \\n\\n\\n\\n Search\\n \\n \\n\\n\\n\\n Shopping\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Photos\\n \\n \\n\\n\\n\\n Translate\\n \\n \\n\\n\\n\\n Registry\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Docs, Sheets and Slides\\n \\n \\n\\n\\n\\n Gmail\\n \\n \\n\\n\\n\\n Google Cloud\\n \\n \\n\\n\\n\\n Meet\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Diversity and inclusion\\n \\n \\n\\n\\n\\n Education\\n \\n \\n\\n\\n\\n Google.org\\n \\n \\n\\n\\n\\n Grow with Google\\n \\n \\n\\n\\n\\n Sustainability\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n AI\\n \\n \\n\\n\\n\\n Developers\\n \\n \\n\\n\\n\\n Families\\n \\n \\n\\n\\n\\n Next billion users\\n \\n \\n\\n\\n\\n Safety and security\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Data centers and infrastructure\\n \\n \\n\\n\\n\\n Doodles\\n \\n \\n\\n\\n\\n Googlers\\n \\n \\n\\n\\n\\n Life at Google\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Google in Asia\\n \\n \\n\\n\\n\\n Google in Europe\\n \\n \\n\\n\\n\\n Google in Latin America\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Sundar Pichai, CEO\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPress corner\\n\\n\\n\\n\\n RSS feed\\n \\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nAI\\n\\n\\nIntroducing Gemini: our largest and most capable AI model\\n\\n\\n\\n\\n\\n\\n\\nDec 06, 2023\\n[[read-time]] min read\\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Making AI more helpful for everyone\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nSundar Pichai\\n\\n CEO of Google and Alphabet\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nDemis Hassabis\\n\\n CEO and Co-Founder, Google DeepMind\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nIn this story\\n\\n\\nIn this story\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nNote from Sundar\\n\\n\\nIntroducing Gemini\\n\\n\\nState-of-the-art performance\\n\\n\\nNext-generation capabilities\\n\\n\\nScalable and efficient\\n\\n\\nResponsibility and safety\\n\\n\\nAvailability\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nA note from Google and Alphabet CEO Sundar Pichai:Every technology shift is an opportunity to advance scientific discovery, accelerate human progress, and improve lives. I believe the transition we are seeing right now with AI will be the most profound in our lifetimes, far bigger than the shift to mobile or to the web before it. AI has the potential to create opportunities — from the everyday to the extraordinary — for people everywhere. It will bring new waves of innovation and economic progress and drive knowledge, learning, creativity and productivity on a scale we haven’t seen before.That’s what excites me: the chance to make AI helpful for everyone, everywhere in the world.Nearly eight years into our journey as an AI-first company, the pace of progress is only accelerating: Millions of people are now using generative AI across our products to do things they couldn’t even a year ago, from finding answers to more complex questions to using new tools to collaborate and create. At the same time, developers are using our models and infrastructure to build new generative AI applications, and startups and enterprises around the world are growing with our AI tools.This is incredible momentum, and yet, we’re only beginning to scratch the surface of what’s possible.We’re approaching this work boldly and responsibly. That means being ambitious in our research and pursuing the capabilities that will bring enormous benefits to people and society, while building in safeguards and working collaboratively with governments and experts to address risks as AI becomes more capable. And we continue to invest in the very best tools, foundation models and infrastructure and bring them to our products and to others, guided by our AI Principles.Now, we’re taking the next step on our journey with Gemini, our most capable and general model yet, with state-of-the-art performance across many leading benchmarks. Our first version, Gemini 1.0, is optimized for different sizes: Ultra, Pro and Nano. These are the first models of the Gemini era and the first realization of the vision we had when we formed Google DeepMind earlier this year. This new era of models represents one of the biggest science and engineering efforts we’ve undertaken as a company. I’m genuinely excited for what’s ahead, and for the opportunities Gemini will unlock for people everywhere.– Sundar\\n\\n\\n\\n\\n\\nIntroducing GeminiBy Demis Hassabis, CEO and Co-Founder of Google DeepMind, on behalf of the Gemini teamAI has been the focus of my life's work, as for many of my research colleagues. Ever since programming AI for computer games as a teenager, and throughout my years as a neuroscience researcher trying to understand the workings of the brain, I’ve always believed that if we could build smarter machines, we could harness them to benefit humanity in incredible ways.This promise of a world responsibly empowered by AI continues to drive our work at Google DeepMind. For a long time, we’ve wanted to build a new generation of AI models, inspired by the way people understand and interact with the world. AI that feels less like a smart piece of software and more like something useful and intuitive — an expert helper or assistant.Today, we’re a step closer to this vision as we introduce Gemini, the most capable and general model we’ve ever built.Gemini is the result of large-scale collaborative efforts by teams across Google, including our colleagues at Google Research. It was built from the ground up to be multimodal, which means it can generalize and seamlessly understand, operate across and combine different types of information including text, code, audio, image and video.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nIntroducing Gemini: our largest and most capable AI model\\n\\n\\n\\n\\n\\n\\nGemini is also our most flexible model yet — able to efficiently run on everything from data centers to mobile devices. Its state-of-the-art capabilities will significantly enhance the way developers and enterprise customers build and scale with AI.We’ve optimized Gemini 1.0, our first version, for three different sizes:Gemini Ultra — our largest and most capable model for highly complex tasks.Gemini Pro — our best model for scaling across a wide range of tasks.Gemini Nano — our most efficient model for on-device tasks.\\n\\n\\n\\n\\n\\nState-of-the-art performanceWe've been rigorously testing our Gemini models and evaluating their performance on a wide variety of tasks. From natural image, audio and video understanding to mathematical reasoning, Gemini Ultra’s performance exceeds current state-of-the-art results on 30 of the 32 widely-used academic benchmarks used in large language model (LLM) research and development.With a score of 90.0%, Gemini Ultra is the first model to outperform human experts on MMLU (massive multitask language understanding), which uses a combination of 57 subjects such as math, physics, history, law, medicine and ethics for testing both world knowledge and problem-solving abilities.Our new benchmark approach to MMLU enables Gemini to use its reasoning capabilities to think more carefully before answering difficult questions, leading to significant improvements over just using its first impression.\\n\\n\\n\\n\\n\\n\\nGemini surpasses state-of-the-art performance on a range of benchmarks including text and coding.\\n\\n\\n\\nGemini Ultra also achieves a state-of-the-art score of 59.4% on the new MMMU benchmark, which consists of multimodal tasks spanning different domains requiring deliberate reasoning.With the image benchmarks we tested, Gemini Ultra outperformed previous state-of-the-art models, without assistance from optical character recognition (OCR) systems that extract text from images for further processing. These benchmarks highlight Gemini’s native multimodality and indicate early signs of Gemini's more complex reasoning abilities.See more details in our Gemini technical report.\\n\\n\\n\\n\\n\\n\\nGemini surpasses state-of-the-art performance on a range of multimodal benchmarks.\\n\\n\\n\\n\\nNext-generation capabilitiesUntil now, the standard approach to creating multimodal models involved training separate components for different modalities and then stitching them together to roughly mimic some of this functionality. These models can sometimes be good at performing certain tasks, like describing images, but struggle with more conceptual and complex reasoning.We designed Gemini to be natively multimodal, pre-trained from the start on different modalities. Then we fine-tuned it with additional multimodal data to further refine its effectiveness. This helps Gemini seamlessly understand and reason about all kinds of inputs from the ground up, far better than existing multimodal models — and its capabilities are state of the art in nearly every domain.Learn more about Gemini’s capabilities and see how it works.Sophisticated reasoningGemini 1.0’s sophisticated multimodal reasoning capabilities can help make sense of complex written and visual information. This makes it uniquely skilled at uncovering knowledge that can be difficult to discern amid vast amounts of data.Its remarkable ability to extract insights from hundreds of thousands of documents through reading, filtering and understanding information will help deliver new breakthroughs at digital speeds in many fields from science to finance.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini unlocks new scientific insights\\n\\n\\n\\n\\n\\n\\nUnderstanding text, images, audio and moreGemini 1.0 was trained to recognize and understand text, images, audio and more at the same time, so it better understands nuanced information and can answer questions relating to complicated topics. This makes it especially good at explaining reasoning in complex subjects like math and physics.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini explains reasoning in math and physics\\n\\n\\n\\n\\n\\n\\nAdvanced codingOur first version of Gemini can understand, explain and generate high-quality code in the world’s most popular programming languages, like Python, Java, C++, and Go. Its ability to work across languages and reason about complex information makes it one of the leading foundation models for coding in the world.Gemini Ultra excels in several coding benchmarks, including HumanEval, an important industry-standard for evaluating performance on coding tasks, and Natural2Code, our internal held-out dataset, which uses author-generated sources instead of web-based information.Gemini can also be used as the engine for more advanced coding systems. Two years ago we presented AlphaCode, the first AI code generation system to reach a competitive level of performance in programming competitions.Using a specialized version of Gemini, we created a more advanced code generation system, AlphaCode 2, which excels at solving competitive programming problems that go beyond coding to involve complex math and theoretical computer science.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini excels at coding and competitive programming\\n\\n\\n\\n\\n\\n\\nWhen evaluated on the same platform as the original AlphaCode, AlphaCode 2 shows massive improvements, solving nearly twice as many problems, and we estimate that it performs better than 85% of competition participants — up from nearly 50% for AlphaCode. When programmers collaborate with AlphaCode 2 by defining certain properties for the code samples to follow, it performs even better.We’re excited for programmers to increasingly use highly capable AI models as collaborative tools that can help them reason about the problems, propose code designs and assist with implementation — so they can release apps and design better services, faster.See more details in our AlphaCode 2 technical report.\\n\\n\\n\\n\\n\\nMore reliable, scalable and efficientWe trained Gemini 1.0 at scale on our AI-optimized infrastructure using Google’s in-house designed Tensor Processing Units (TPUs) v4 and v5e. And we designed it to be our most reliable and scalable model to train, and our most efficient to serve.On TPUs, Gemini runs significantly faster than earlier, smaller and less-capable models. These custom-designed AI accelerators have been at the heart of Google's AI-powered products that serve billions of users like Search, YouTube, Gmail, Google Maps, Google Play and Android. They’ve also enabled companies around the world to train large-scale AI models cost-efficiently.Today, we’re announcing the most powerful, efficient and scalable TPU system to date, Cloud TPU v5p, designed for training cutting-edge AI models. This next generation TPU will accelerate Gemini’s development and help developers and enterprise customers train large-scale generative AI models faster, allowing new products and capabilities to reach customers sooner.\\n\\n\\n\\n\\n\\n\\nA row of Cloud TPU v5p AI accelerator supercomputers in a Google data center.\\n\\n\\n\\n\\nBuilt with responsibility and safety at the coreAt Google, we’re committed to advancing bold and responsible AI in everything we do. Building upon Google’s AI Principles and the robust safety policies across our products, we’re adding new protections to account for Gemini’s multimodal capabilities. At each stage of development, we’re considering potential risks and working to test and mitigate them.Gemini has the most comprehensive safety evaluations of any Google AI model to date, including for bias and toxicity. We’ve conducted novel research into potential risk areas like cyber-offense, persuasion and autonomy, and have applied Google Research’s best-in-class adversarial testing techniques to help identify critical safety issues in advance of Gemini’s deployment.To identify blindspots in our internal evaluation approach, we’re working with a diverse group of external experts and partners to stress-test our models across a range of issues.To diagnose content safety issues during Gemini’s training phases and ensure its output follows our policies, we’re using benchmarks such as Real Toxicity Prompts, a set of 100,000 prompts with varying degrees of toxicity pulled from the web, developed by experts at the Allen Institute for AI. Further details on this work are coming soon.To limit harm, we built dedicated safety classifiers to identify, label and sort out content involving violence or negative stereotypes, for example. Combined with robust filters, this layered approach is designed to make Gemini safer and more inclusive for everyone. Additionally, we’re continuing to address known challenges for models such as factuality, grounding, attribution and corroboration.Responsibility and safety will always be central to the development and deployment of our models. This is a long-term commitment that requires building collaboratively, so we’re partnering with the industry and broader ecosystem on defining best practices and setting safety and security benchmarks through organizations like MLCommons, the Frontier Model Forum and its AI Safety Fund, and our Secure AI Framework (SAIF), which was designed to help mitigate security risks specific to AI systems across the public and private sectors. We’ll continue partnering with researchers, governments and civil society groups around the world as we develop Gemini.\\n\\n\\n\\n\\n\\nMaking Gemini available to the worldGemini 1.0 is now rolling out across a range of products and platforms:Gemini Pro in Google productsWe’re bringing Gemini to billions of people through Google products.Starting today, Bard will use a fine-tuned version of Gemini Pro for more advanced reasoning, planning, understanding and more. This is the biggest upgrade to Bard since it launched. It will be available in English in more than 170 countries and territories, and we plan to expand to different modalities and support new languages and locations in the near future.We’re also bringing Gemini to Pixel. Pixel 8 Pro is the first smartphone engineered to run Gemini Nano, which is powering new features like Summarize in the Recorder app and rolling out in Smart Reply in Gboard, starting with WhatsApp, Line and KakaoTalk1 — with more messaging apps coming next year.In the coming months, Gemini will be available in more of our products and services like Search, Ads, Chrome and Duet AI.We’re already starting to experiment with Gemini in Search, where it's making our Search Generative Experience (SGE) faster for users, with a 40% reduction in latency in English in the U.S., alongside improvements in quality.Building with GeminiStarting on December 13, developers and enterprise customers can access Gemini Pro via the Gemini API in Google AI Studio or Google Cloud Vertex AI.Google AI Studio is a free, web-based developer tool to prototype and launch apps quickly with an API key. When it's time for a fully-managed AI platform, Vertex AI allows customization of Gemini with full data control and benefits from additional Google Cloud features for enterprise security, safety, privacy and data governance and compliance.Android developers will also be able to build with Gemini Nano, our most efficient model for on-device tasks, via AICore, a new system capability available in Android 14, starting on Pixel 8 Pro devices. Sign up for an early preview of AICore.Gemini Ultra coming soonFor Gemini Ultra, we’re currently completing extensive trust and safety checks, including red-teaming by trusted external parties, and further refining the model using fine-tuning and reinforcement learning from human feedback (RLHF) before making it broadly available.As part of this process, we’ll make Gemini Ultra available to select customers, developers, partners and safety and responsibility experts for early experimentation and feedback before rolling it out to developers and enterprise customers early next year.Early next year, we’ll also launch Bard Advanced, a new, cutting-edge AI experience that gives you access to our best models and capabilities, starting with Gemini Ultra.\\n\\n\\n\\n\\nThe Gemini era: enabling a future of innovationThis is a significant milestone in the development of AI, and the start of a new era for us at Google as we continue to rapidly innovate and responsibly advance the capabilities of our models.We’ve made great progress on Gemini so far and we’re working hard to further extend its capabilities for future versions, including advances in planning and memory, and increasing the context window for processing even more information to give better responses.We’re excited by the amazing possibilities of a world responsibly empowered by AI — a future of innovation that will enhance creativity, extend knowledge, advance science and transform the way billions of people live and work around the world.\\n\\n\\n\\n\\n\\n\\n\\n\\nCollection\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nCollection\\n\\nMore about Gemini\\nExplore our collection to find out more about Gemini, the most capable and general model we’ve ever built.\\n\\nSee more\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Get more stories from Google in your inbox.\\n \\n\\n\\n\\n\\n\\n Email address\\n \\n\\n\\n\\n\\n\\n Your information will be used in accordance with\\n \\nGoogle's privacy policy.\\n\\n\\n Subscribe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nDone. Just one step more.\\n\\nCheck your inbox to confirm your subscription.\\n\\nYou are already subscribed to our newsletter.\\n\\n\\n\\n You can also subscribe with a\\n \\ndifferent email address\\n\\n .\\n \\n\\n\\n\\n\\n\\n\\nPOSTED IN:\\n\\n\\n\\n\\n\\n\\nAI\\n\\n\\n \\n\\n\\n\\n\\n\\nGemini\\n\\n\\n \\n\\n\\n\\n\\n\\nDevelopers\\n\\n\\n \\n\\n\\n\\n\\n\\nGoogle Cloud\\n\\n\\n \\n\\n\\n\\n\\n\\nResearch\\n\\n\\n \\n\\n\\n\\n\\n\\nGoogle DeepMind\\n\\n\\n \\n\\n\\n\\n\\n\\nPixel\\n\\n\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nRead Article\\n\\n\\n\\n\\n\\n\\n\\nMore Information\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n1\\n\\nUpdated on Dec 13 to include additional messaging apps\\n\\n\\n\\nCollapse\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Related stories\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nLife at Google\\nQuiz: Test your knowledge of Google’s May news\\n\\n\\n\\n By\\n \\n \\n Molly McHugh-Johnson\\n \\n\\n Jun 13, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nResearch\\nIntroducing Google's new Academic Research Awards\\n\\n\\n\\n By\\n \\n \\n Ashley Gardner\\n \\n\\n Cori Grainger\\n \\n\\n Jun 13, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPixel\\nJune Feature Drop: New features and upgrades for the Pixel portfolio\\n\\n\\n\\n By\\n \\n \\n Mikaela Kraft\\n \\n\\n Jun 11, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nEntrepreneurs\\nSupport for European and Israeli startups working on AI and climate solutions\\n\\n\\n\\n By\\n \\n \\n Matt Brittin\\n \\n\\n Jun 11, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nAI\\nNotebookLM goes global with Slides support and better ways to fact-check\\n\\n\\n\\n By\\n \\n \\n Steven Johnson\\n \\n\\n Raiza Martin\\n \\n\\n Jun 06, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nArts & Culture\\nA new AI tool to help monitor coral reef health\\n\\n\\n\\n By\\n \\n \\n Steve Simpson\\n \\n\\n Ben Williams\\n \\n\\n Jun 06, 2024\\n\\n\\n\\n\\n\\n\\n.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nLet’s stay in touch. Get the latest news from Google in your inbox.\\n\\n\\nSubscribe\\nNo thanks\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Follow Us\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPrivacy\\n \\n\\n\\nTerms\\n \\n\\n\\nAbout Google\\n \\n\\n\\nGoogle Products\\n \\n\\n\\nAbout the Keyword\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Help\\n \\n\\n\\n\\n\\n\\n Deutsch\\n \\n\\n English\\n \\n\\n English (Africa)\\n \\n\\n English (Australia)\\n \\n\\n English (Canada)\\n \\n\\n English (India)\\n \\n\\n English (MENA)\\n \\n\\n Español (España)\\n \\n\\n Español (Latinoamérica)\\n \\n\\n Français (Canada)\\n \\n\\n Français (France)\\n \\n\\n Italiano\\n \\n\\n Nederlands (Nederland)\\n \\n\\n Polski\\n \\n\\n Português (Brasil)\\n \\n\\n اللغة العربية (MENA)\\n \\n\\n 日本語 (日本)\\n \\n\\n 한국어\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\", metadata={'source': 'https://blog.google/technology/ai/google-gemini-ai/#sundar-note', 'title': 'Introducing Gemini: Google’s most capable AI model yet', 'description': 'Gemini is our most capable and general model, built to be multimodal and optimized for three different sizes: Ultra, Pro and Nano.', 'language': 'en-us'})]\n" ] } ], @@ -232,17 +218,18 @@ "id": "4xlf_F_4B6lB" }, "source": [ - "### Initialize Gemini\n", + "### Initialize the Gemini model\n", "\n", "You must import the `ChatGoogleGenerativeAI` LLM from LangChain to initialize your model.\n", - " In this example you will use **gemini-pro**, as it supports text summarization. To know more about the text model, read Google AI's [language documentation](https://ai.google.dev/models/gemini).\n", "\n", - "You can configure the model parameters such as ***temperature*** or ***top_p***, by passing the appropriate values when creating the `ChatGoogleGenerativeAI` LLM. To learn more about the parameters and their uses, read Google AI's [concepts guide](https://ai.google.dev/docs/concepts#model_parameters)." + "In this example you will use Gemini 1.5 Flash, (`gemini-1.5-flash-latest`), as it supports text summarization. To know more about this model and the other models availabe, read Google AI's [language documentation](https://ai.google.dev/models/gemini).\n", + "\n", + "You can configure the model parameters such as `temperature` or `top_p`, by passing the appropriate values when creating the `ChatGoogleGenerativeAI` LLM. To learn more about the parameters and their uses, read Google AI's [concepts guide](https://ai.google.dev/docs/concepts#model_parameters)." ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "metadata": { "id": "WWA9F0ZqB-8k" }, @@ -254,8 +241,10 @@ "# to the parameter `google_api_key` of the `ChatGoogleGenerativeAI` function:\n", "# `google_api_key=\"key\"`.\n", "\n", - "llm = ChatGoogleGenerativeAI(model=\"gemini-1.5-flash-latest\",\n", - " temperature=0.7, top_p=0.85)" + "llm = ChatGoogleGenerativeAI(google_api_key=GOOGLE_API_KEY,\n", + " model=\"gemini-1.5-flash-latest\",\n", + " temperature=0.7,\n", + " top_p=0.85)" ] }, { @@ -266,18 +255,18 @@ "source": [ "### Create prompt templates\n", "\n", - "You'll use LangChain's [PromptTemplate](https://python.langchain.com/docs/modules/model_io/prompts/prompt_templates/) to generate prompts for summarizing the text.\n", + "You'll use LangChain's [`PromptTemplate`](https://python.langchain.com/docs/modules/model_io/prompts/prompt_templates/) to generate prompts for summarizing the text.\n", "\n", "To summarize the text from the website, you will need the following prompts.\n", "1. Prompt to extract the data from the output of `WebBaseLoader`, named `doc_prompt`\n", - "2. Prompt for the LLM model (Gemini) to summarize the extracted text, named `llm_prompt`.\n", + "2. Prompt for the Gemini model to summarize the extracted text, named `llm_prompt`.\n", "\n", "In the `llm_prompt`, the variable `text` will be replaced later by the text from the website." ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": { "id": "rixvvvaNKLe_" }, @@ -320,7 +309,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "metadata": { "id": "EMZomQdyKMr5" }, @@ -349,7 +338,7 @@ " )\n", " }\n", " | llm_prompt # Prompt for Gemini\n", - " | llm # Gemini function\n", + " | llm # Gemini API function\n", " | StrOutputParser() # output parser\n", ")" ] @@ -367,7 +356,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": { "id": "k9_GxkA5ePRR" }, @@ -378,10 +367,10 @@ "type": "string" }, "text/plain": [ - "'Google has announced Gemini, its most advanced AI model yet. Gemini is multimodal, meaning it can understand and process various types of information, including text, code, audio, images, and video. It surpasses existing models in performance across various benchmarks, particularly in reasoning and multimodal tasks. \\n\\nGemini is available in three sizes: Ultra, Pro, and Nano. Gemini Pro is being integrated into Google products like Bard, Pixel, and Search, while Gemini Nano is available for on-device tasks. Developers can access Gemini Pro through APIs, and Gemini Ultra will be available for early access soon. \\n\\nGoogle emphasizes its commitment to responsible AI development, including comprehensive safety evaluations and collaborations with external experts to mitigate potential risks. The company sees Gemini as a major step towards a future where AI empowers innovation, creativity, and knowledge advancement for everyone. \\n'" + "\"Google has introduced Gemini, its most capable AI model yet. It's multimodal, meaning it can understand and process various types of information, including text, code, audio, images, and video. Gemini is optimized for different sizes: Ultra (largest and most capable), Pro (best for scaling across tasks), and Nano (most efficient for on-device tasks). \\n\\nGemini surpasses current state-of-the-art performance on various benchmarks, including language understanding, reasoning, and coding. It's also more reliable, scalable, and efficient than previous models.\\n\\nGoogle emphasizes responsibility and safety in Gemini's development, implementing extensive safety evaluations and working with external experts. \\n\\nGemini is being rolled out across Google products, including Bard, Pixel, Search, Ads, Chrome, and Duet AI. Developers and enterprise customers can access Gemini Pro through APIs, while Android developers can use Gemini Nano via AICore. \\n\\nGemini Ultra will be available to select customers, developers, and partners for early experimentation before a broader rollout early next year. \\n\\nGoogle sees Gemini as a significant milestone in AI development, enabling a future of innovation that enhances creativity, expands knowledge, advances science, and transforms how people live and work. \\n\"" ] }, - "execution_count": 11, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -398,7 +387,7 @@ "source": [ "# Conclusion\n", "\n", - "That's it. You have successfully created an LLM application to summarize text using LangChain and Gemini." + "That's it. You have successfully created an LLM application to summarize text using LangChain and the Gemini API." ] } ], From 841fd582f684144d5e2f9650eed3ff8d6263beaa Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Thu, 13 Jun 2024 13:02:53 -0700 Subject: [PATCH 7/9] Update URL for summarization --- examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb index 963966f4b..edcd23217 100644 --- a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb +++ b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb @@ -48,7 +48,7 @@ "source": [ "\n", " \n", "
\n", - " Run in Google Colab\n", + " Run in Google Colab\n", "
\n" ] From fe8bdf9310dd0adab8a102041589b2d059009fd0 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Sun, 23 Jun 2024 23:05:47 -0700 Subject: [PATCH 8/9] Update to all LangChain integration examples --- .../Gemini_LangChain_QA_Chroma_WebLoad.ipynb | 211 +++--- ...Gemini_LangChain_QA_Pinecone_WebLoad.ipynb | 630 ++++++++++++++++++ ...mini_LangChain_Summarization_WebLoad.ipynb | 141 ++-- 3 files changed, 835 insertions(+), 147 deletions(-) create mode 100644 examples/langchain/Gemini_LangChain_QA_Pinecone_WebLoad.ipynb diff --git a/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb index ac0cbedc4..c9c767759 100644 --- a/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb +++ b/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb @@ -11,14 +11,13 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { - "cellView": "form", "id": "tuOe1ymfHZPu" }, "outputs": [], "source": [ - "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", + "# @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", @@ -37,7 +36,7 @@ "id": "0c5ea3f4a75c" }, "source": [ - "# Question Answering using Gemini, LangChain, and Chroma" + "# Gemini API: Question Answering using LangChain and Chroma" ] }, { @@ -87,43 +86,95 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "metadata": { - "id": "olK4Ejjzuj76" + "id": "olK4Ejjzuj76", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "138de6db-8520-4da7-af94-97fdf05573cf" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m1.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.2/49.2 kB\u001b[0m \u001b[31m1.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25h" + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m241.2/241.2 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m55.4/55.4 kB\u001b[0m \u001b[31m1.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m3.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m802.4/802.4 kB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m12.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.2/49.2 kB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m302.9/302.9 kB\u001b[0m \u001b[31m15.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m20.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m26.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m25.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m32.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m40.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m46.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m48.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m33.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m43.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m47.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m42.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m47.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m32.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m63.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m65.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m42.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m61.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m75.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m146.9/146.9 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m598.7/598.7 kB\u001b[0m \u001b[31m20.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m559.5/559.5 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m42.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m92.0/92.0 kB\u001b[0m \u001b[31m7.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.4/62.4 kB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.3/41.3 kB\u001b[0m \u001b[31m3.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.8/6.8 MB\u001b[0m \u001b[31m87.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m59.9/59.9 kB\u001b[0m \u001b[31m7.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m107.0/107.0 kB\u001b[0m \u001b[31m12.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.3/67.3 kB\u001b[0m \u001b[31m8.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", + " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", + " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m283.7/283.7 kB\u001b[0m \u001b[31m25.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m74.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.6/67.6 kB\u001b[0m \u001b[31m7.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m145.0/145.0 kB\u001b[0m \u001b[31m16.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.9/71.9 kB\u001b[0m \u001b[31m8.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.6/53.6 kB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m9.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m7.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.0/46.0 kB\u001b[0m \u001b[31m6.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m52.5/52.5 kB\u001b[0m \u001b[31m6.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m130.5/130.5 kB\u001b[0m \u001b[31m15.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m341.4/341.4 kB\u001b[0m \u001b[31m32.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.4/3.4 MB\u001b[0m \u001b[31m87.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m64.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m130.2/130.2 kB\u001b[0m \u001b[31m15.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m307.7/307.7 kB\u001b[0m \u001b[31m30.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m86.8/86.8 kB\u001b[0m \u001b[31m11.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Building wheel for pypika (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n" ] } ], "source": [ - "!pip install --quiet langchain\n", - "!pip install --quiet langchain-google-genai\n", - "!pip install --quiet chromadb\n", - "!pip install --quiet langchain-community" + "!pip install --quiet langchain-core==0.1.23\n", + "!pip install --quiet langchain==0.1.1\n", + "!pip install --quiet langchain-google-genai==0.0.6\n", + "!pip install --quiet -U langchain-community==0.0.20\n", + "!pip install --quiet chromadb" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "metadata": { "id": "TcvGPVdXu05F" }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:root:USER_AGENT environment variable not set, consider setting it to identify your requests.\n" - ] - } - ], + "outputs": [], "source": [ "from langchain import PromptTemplate\n", "from langchain import hub\n", @@ -138,37 +189,27 @@ { "cell_type": "markdown", "metadata": { - "id": "wiGHSFmZaniK" + "id": "FQOGMejVu-6D" }, "source": [ - "## Set up your API key\n", - "\n", - "To use Gemini you need an API key. You can create an API key with one click in Google AI Studio. After creating the API key, you can either set an environment variable named GOOGLE_API_KEY to your API Key or pass the API key as an argument when using the ChatGoogleGenerativeAI class to access Google's gemini and gemini-vision models or the GoogleGenerativeAIEmbeddings class to access Google's Generative AI embedding model using LangChain.\n", + "## Configure your API key\n", "\n", - "In this tutorial, you will set the environment variable `GOOGLE_API_KEY` to configure Gemini to use your API key." + "To run the following cell, your API key must be stored 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](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb) for an example.\n" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "metadata": { - "id": "xId4sR52utS0" + "id": "ysayz8skEfBW" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Gemini API Key:··········\n" - ] - } - ], + "outputs": [], "source": [ - "# Run this cell and paste the API key in the prompt\n", "import os\n", - "import getpass\n", + "from google.colab import userdata\n", + "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n", "\n", - "os.environ['GOOGLE_API_KEY'] = getpass.getpass('Gemini API Key:')" + "os.environ[\"GOOGLE_API_KEY\"] = GOOGLE_API_KEY" ] }, { @@ -238,7 +279,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": { "id": "DeNX9QFM0V-C" }, @@ -261,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 5, "metadata": { "id": "EDL9YLRb9Bw2" }, @@ -277,7 +318,7 @@ "final_text = text_content_1.split(\"Cloud TPU v5p\",1)[0]\n", "\n", "# Convert the text to LangChain's `Document` format\n", - "docs = [Document(page_content=final_text, metadata={\"source\": \"local\"})]" + "docs = [Document(page_content=final_text, metadata={\"source\": \"local\"})]" ] }, { @@ -295,7 +336,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 6, "metadata": { "id": "8NXNTrjp0jdh" }, @@ -303,10 +344,6 @@ "source": [ "from langchain_google_genai import GoogleGenerativeAIEmbeddings\n", "\n", - "# If there is no environment variable set for the API key, you can pass the API\n", - "# key to the parameter `google_api_key` of the `GoogleGenerativeAIEmbeddings`\n", - "# function: `google_api_key = \"key\"`.\n", - "\n", "gemini_embeddings = GoogleGenerativeAIEmbeddings(model=\"models/embedding-001\")" ] }, @@ -325,7 +362,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 7, "metadata": { "id": "n1VwhUQMvpcN" }, @@ -357,22 +394,18 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 8, "metadata": { - "id": "s3t4kmzIOZQq" + "id": "s3t4kmzIOZQq", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "7460ae1f-14bd-404c-c770-fa5750a294ce" }, "outputs": [ { - "name": "stderr", "output_type": "stream", - "text": [ - "/usr/local/lib/python3.10/dist-packages/langchain_core/_api/deprecation.py:119: LangChainDeprecationWarning: The method `BaseRetriever.get_relevant_documents` was deprecated in langchain-core 0.1.46 and will be removed in 0.3.0. Use invoke instead.\n", - " warn_deprecated(\n" - ] - }, - { "name": "stdout", - "output_type": "stream", "text": [ "1\n" ] @@ -429,14 +462,14 @@ "### Initialize Gemini\n", "\n", "You must import `ChatGoogleGenerativeAI` from LangChain to initialize your model.\n", - " In this example, you will use **gemini-pro**, as it supports text summarization. To know more about the text model, read Google AI's [language documentation](https://ai.google.dev/models/gemini).\n", + " In this example, you will use **gemini-1.5-flash-latest**, as it supports text summarization. To know more about the text model, read Google AI's [language documentation](https://ai.google.dev/models/gemini).\n", "\n", "You can configure the model parameters such as ***temperature*** or ***top_p***, by passing the appropriate values when initializing the `ChatGoogleGenerativeAI` LLM. To learn more about the parameters and their uses, read Google AI's [concepts guide](https://ai.google.dev/docs/concepts#model_parameters)." ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 9, "metadata": { "id": "CaA1vRCh7s36" }, @@ -444,11 +477,12 @@ "source": [ "from langchain_google_genai import ChatGoogleGenerativeAI\n", "\n", - "# If there is no environment variable set for the API key, you can pass the API\n", - "# key to the parameter `google_api_key` of the `ChatGoogleGenerativeAI` function:\n", - "# `google_api_key=\"key\"`.\n", - "llm = ChatGoogleGenerativeAI(model=\"gemini-1.5-flash-latest\",\n", - " temperature=0.7, top_p=0.85)" + "# To configure model parameters use the `generation_config` parameter.\n", + "# eg. generation_config = {\"temperature\": 0.7, \"topP\": 0.8, \"topK\": 40}\n", + "# If you only want to set a custom temperature for the model use the\n", + "# \"temperature\" parameter directly.\n", + "\n", + "llm = ChatGoogleGenerativeAI(model=\"gemini-1.5-flash-latest\")" ] }, { @@ -466,14 +500,18 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 10, "metadata": { - "id": "90Czqh074dEC" + "id": "90Czqh074dEC", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "9e167c1e-50d1-423f-b53c-421170f2f4e8" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ "input_variables=['context', 'question'] template=\"You are an assistant for question-answering tasks.\\nUse the following context to answer the question.\\nIf you don't know the answer, just say that you don't know.\\nUse five sentences maximum and keep the answer concise.\\n\\nQuestion: {question} \\nContext: {context} \\nAnswer:\"\n" ] @@ -511,7 +549,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 11, "metadata": { "id": "gj5sWzpwp7vc" }, @@ -559,23 +597,28 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 12, "metadata": { - "id": "4vIaopCsIq0B" + "id": "4vIaopCsIq0B", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 105 + }, + "outputId": "4cfa55f2-8de2-4f37-eb00-41e7db7f2a9e" }, "outputs": [ { + "output_type": "execute_result", "data": { + "text/plain": [ + "\"Gemini is Google's largest and most capable AI model, designed to be highly flexible and efficient across various devices, from data centers to mobile devices. It's optimized in three sizes: Ultra, Pro, and Nano, catering to different complexity levels and task requirements. Gemini surpasses state-of-the-art performance on multiple benchmarks, including text, code, and multimodal tasks, showcasing its advanced reasoning abilities. This model is trained to understand and process information across various modalities, including text, images, audio, and more, making it ideal for complex tasks like coding and scientific research. \\n\"" + ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" - }, - "text/plain": [ - "\"Gemini is Google's largest and most capable AI model, designed to be flexible and efficient across various platforms. It excels in a wide range of tasks, including natural language understanding, image and video comprehension, mathematical reasoning, and coding. Gemini comes in three sizes: Ultra, Pro, and Nano, each optimized for different use cases. Gemini Ultra has achieved state-of-the-art performance on multiple benchmarks, surpassing human experts in some areas. \\n\"" - ] + } }, - "execution_count": 16, "metadata": {}, - "output_type": "execute_result" + "execution_count": 12 } ], "source": [ @@ -596,8 +639,8 @@ ], "metadata": { "colab": { - "name": "Gemini_LangChain_QA_Chroma_WebLoad.ipynb", - "toc_visible": true + "toc_visible": true, + "provenance": [] }, "kernelspec": { "display_name": "Python 3", @@ -606,4 +649,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file diff --git a/examples/langchain/Gemini_LangChain_QA_Pinecone_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_QA_Pinecone_WebLoad.ipynb new file mode 100644 index 000000000..d403affec --- /dev/null +++ b/examples/langchain/Gemini_LangChain_QA_Pinecone_WebLoad.ipynb @@ -0,0 +1,630 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "YdsMOBaBfyT0" + }, + "source": [ + "##### Copyright 2024 Google LLC." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "rIIf_RgOf3sr" + }, + "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": "TySweisNf_Am" + }, + "source": [ + "# Gemini API: Question Answering using LangChain and Pinecone" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "awKO767lQIWh" + }, + "source": [ + "\n", + " \n", + "
\n", + " Run in Google Colab\n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "bA5Hys5PU_nt" + }, + "source": [ + "## Overview\n", + "\n", + "[Gemini](https://ai.google.dev/models/gemini) is a family of generative AI models that lets developers generate content and solve problems. These models are designed and trained to handle both text and images as input.\n", + "\n", + "[LangChain](https://www.langchain.com/) is a data framework designed to make integration of Large Language Models (LLM) like Gemini easier for applications.\n", + "\n", + "[Pinecone](https://www.pinecone.io/) is a cloud-first vector database that allows users to search across billions of embeddings with ultra-low query latency.\n", + "\n", + "In this notebook, you'll learn how to create an application that answers questions using data from a website with the help of Gemini, LangChain, and Pinecone." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_qRjVe1tZhsx" + }, + "source": [ + "## Setup\n", + "\n", + "First, you must install the packages and set the necessary environment variables.\n", + "\n", + "### Installation\n", + "\n", + "Install LangChain's Python library, `langchain` and LangChain's integration package for Gemini, `langchain-google-genai`. Next, install LangChain's integration package for the new version of Pinecone, `langchain-pinecone` and the `pinecone-client`, which is Pinecone's Python SDK. Finally, install `langchain-community` to access the `WebBaseLoader` module later." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "olK4Ejjzuj76" + }, + "outputs": [], + "source": [ + "!pip install --quiet langchain==0.1.1\n", + "!pip install --quiet langchain-google-genai==0.0.6\n", + "!pip install --quiet langchain-pinecone\n", + "!pip install --quiet pinecone-client\n", + "!pip install --quiet langchain-community==0.0.20" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FQOGMejVu-6D" + }, + "source": [ + "## Configure your API key\n", + "\n", + "To run the following cell, your API key must be stored 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](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb) for an example.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "ysayz8skEfBW" + }, + "outputs": [], + "source": [ + "import os\n", + "from google.colab import userdata\n", + "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n", + "\n", + "os.environ[\"GOOGLE_API_KEY\"] = GOOGLE_API_KEY" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MPQLjFvRooqn" + }, + "source": [ + "### Setup Pinecone\n", + "\n", + "To use Pinecone in your application, you must have an API key. To create an API key you have to set up a Pinecone account. Visit [Pinecone's app page](https://app.pinecone.io/), and Sign up/Log in to your account. Then navigate to the \"API Keys\" section and copy your API key.\n", + "\n", + "For more detailed instructions on getting the API key, you can read Pinecone's [Quickstart documentation](https://docs.pinecone.io/docs/quickstart#2-get-your-api-key).\n", + "\n", + "Set the environment variable `PINECONE_API_KEY` to configure Pinecone to use your API key.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "A7jTZLEApgtm" + }, + "outputs": [], + "source": [ + "PINECONE_API_KEY=userdata.get('PINECONE_API_KEY')\n", + "\n", + "os.environ['PINECONE_API_KEY'] = PINECONE_API_KEY" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YGOKV3XflBCe" + }, + "source": [ + "## Basic steps\n", + "LLMs are trained offline on a large corpus of public data. Hence they cannot answer questions based on custom or private data accurately without additional context.\n", + "\n", + "If you want to make use of LLMs to answer questions based on private data, you have to provide the relevant documents as context alongside your prompt. This approach is called Retrieval Augmented Generation (RAG).\n", + "\n", + "You will use this approach to create a question-answering assistant using the Gemini text model integrated through LangChain. The assistant is expected to answer questions about Gemini model. To make this possible you will add more context to the assistant using data from a website.\n", + "\n", + "In this tutorial, you'll implement the two main components in an RAG-based architecture:\n", + "\n", + "1. Retriever\n", + "\n", + " Based on the user's query, the retriever retrieves relevant snippets that add context from the document. In this tutorial, the document is the website data.\n", + " The relevant snippets are passed as context to the next stage - \"Generator\".\n", + "\n", + "2. Generator\n", + "\n", + " The relevant snippets from the website data are passed to the LLM along with the user's query to generate accurate answers.\n", + "\n", + "You'll learn more about these stages in the upcoming sections while implementing the application." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kPhs4mDkjdgY" + }, + "source": [ + "## Import the required libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "TcvGPVdXu05F" + }, + "outputs": [], + "source": [ + "from langchain import hub\n", + "from langchain import PromptTemplate\n", + "from langchain.docstore.document import Document\n", + "from langchain.document_loaders import WebBaseLoader\n", + "from langchain.schema import StrOutputParser\n", + "from langchain.schema.prompt_template import format_document\n", + "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", + "from langchain_pinecone import Pinecone\n", + "\n", + "from pinecone import Pinecone as pc\n", + "from pinecone import PodSpec" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "qZ3tM0T2lbVm" + }, + "source": [ + "## Retriever\n", + "\n", + "In this stage, you will perform the following steps:\n", + "\n", + "1. Read and parse the website data using LangChain.\n", + "\n", + "2. Create embeddings of the website data.\n", + "\n", + " Embeddings are numerical representations (vectors) of text. Hence, text with similar meaning will have similar embedding vectors. You'll make use of Gemini's embedding model to create the embedding vectors of the website data.\n", + "\n", + "3. Store the embeddings in Pinecone's vector store.\n", + " \n", + " Pinecone is a vector database. The Pinecone vector store helps in the efficient retrieval of similar vectors. Thus, for adding context to the prompt for the LLM, relevant embeddings of the text matching the user's question can be retrieved easily using Pinecone.\n", + "\n", + "4. Create a Retriever from the Pinecone vector store.\n", + "\n", + " The retriever will be used to pass relevant website embeddings to the LLM along with user queries." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "W2N-NCPElqN3" + }, + "source": [ + "### Read and parse the website data\n", + "\n", + "LangChain provides a wide variety of document loaders. To read the website data as a document, you will use the `WebBaseLoader` from LangChain.\n", + "\n", + "To know more about how to read and parse input data from different sources using the document loaders of LangChain, read LangChain's [document loaders guide](https://python.langchain.com/docs/integrations/document_loaders)." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "DeNX9QFM0V-C" + }, + "outputs": [], + "source": [ + "loader = WebBaseLoader(\"https://blog.google/technology/ai/google-gemini-ai/\")\n", + "docs = loader.load()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "y2N6RoTDlwsM" + }, + "source": [ + "If you only want to select a specific portion of the website data to add context to the prompt, you can use regex, text slicing, or text splitting.\n", + "\n", + "In this example, you'll use Python's `split()` function to extract the required portion of the text. The extracted text should be converted back to LangChain's `Document` format." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "id": "qOwDregSBVVG" + }, + "outputs": [], + "source": [ + "# Extract the text from the website data document\n", + "text_content = docs[0].page_content\n", + "# The text content between the substrings \"code, audio, image and video.\" to\n", + "# \"Cloud TPU v5p\" is relevant for this tutorial. You can use Python's `split()`\n", + "# to select the required content.\n", + "text_content_1 = text_content.split(\"code, audio, image and video.\",1)[1]\n", + "final_text = text_content_1.split(\"Cloud TPU v5p\",1)[0]\n", + "\n", + "# Convert the text to LangChain's `Document` format\n", + "docs = [Document(page_content=final_text, metadata={\"source\": \"local\"})]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sgGVAFqWl20v" + }, + "source": [ + "### Initialize Gemini's embedding model\n", + "\n", + "To create the embeddings from the website data, you'll use Gemini's embedding model, **embedding-001** which supports creating text embeddings.\n", + "\n", + "To use this embedding model, you have to import `GoogleGenerativeAIEmbeddings` from LangChain. To know more about the embedding model, read Google AI's [language documentation](https://ai.google.dev/models/gemini)." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "8NXNTrjp0jdh" + }, + "outputs": [], + "source": [ + "from langchain_google_genai import GoogleGenerativeAIEmbeddings\n", + "\n", + "gemini_embeddings = GoogleGenerativeAIEmbeddings(model=\"models/embedding-001\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Zr5xeWUXmnUe" + }, + "source": [ + "### Store the data using Pinecone\n", + "\n", + "\n", + "To create a Pinecone vector database, first, you have to initialize your Pinecone client connection using the API key you set previously.\n", + "\n", + "In Pinecone, vector embeddings have to be stored in indexes. An index represents the vector data's top-level organizational unit. The vectors in any index must have the same dimensionality and distance metric for calculating similarity. You can read more about indexes in [Pinecone's Indexes documentation](https://docs.pinecone.io/docs/indexes).\n", + "\n", + "First, you'll create an index using Pinecone's `create_index` function. Pinecone allows you to create two types of indexes, Serverless indexes and Pod-based indexes. Pinecone's free starter plan lets you create only one project and one pod-based starter index with sufficient resources to support 100,000 vectors. For this tutorial, you have to create a pod-based starter index. To know more about different indexes and how they can be created, read Pinecone's [create indexes guide](https://docs.pinecone.io/docs/new-api#creating-indexes).\n", + "\n", + "\n", + "Next, you'll insert the documents you extracted earlier from the website data into the newly created index using LangChain's `Pinecone.from_documents`. Under the hood, this function creates embeddings from the documents created by the document loader of LangChain using any specified embedding model and inserts them into the specified index in a Pinecone vector database. \n", + "\n", + "You have to specify the `docs` you created from the website data using LangChain's `WebBasedLoader` and the `gemini_embeddings` as the embedding model when invoking the `from_documents` function to create the vector database from the website data." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "n1VwhUQMvpcN" + }, + "outputs": [], + "source": [ + "# Initialize Pinecone client\n", + "\n", + "pine_client= pc(\n", + " api_key = os.getenv(\"PINECONE_API_KEY\"), # API key from app.pinecone.io\n", + " )\n", + "index_name = \"langchain-demo\"\n", + "\n", + "# First, check if the index already exists. If it doesn't, create a new one.\n", + "if index_name not in pine_client.list_indexes().names():\n", + " # Create a new index.\n", + " # https://docs.pinecone.io/docs/new-api#creating-a-starter-index\n", + " print(\"Creating index\")\n", + " pine_client.create_index(name=index_name,\n", + " # `cosine` distance metric compares different documents\n", + " # for similarity.\n", + " # Read more about different distance metrics from\n", + " # https://docs.pinecone.io/docs/indexes#distance-metrics.\n", + " metric=\"cosine\",\n", + " # The Gemini embedding model `embedding-001` uses\n", + " # 768 dimensions.\n", + " dimension=768,\n", + " # Specify the pod details.\n", + " spec=PodSpec(\n", + " # Starter indexes are hosted in the `gcp-starter`\n", + " # environment.\n", + " environment=\"gcp-starter\",\n", + " pod_type=\"starter\",\n", + " pods=1)\n", + " )\n", + " print(pine_client.describe_index(index_name))\n", + "\n", + "vectorstore = Pinecone.from_documents(docs,\n", + " gemini_embeddings, index_name=index_name)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "BuSjapvHnc6T" + }, + "source": [ + "### Create a retriever using Pinecone\n", + "\n", + "You'll now create a retriever that can retrieve website data embeddings from the newly created Pinecone vector store. This retriever can be later used to pass embeddings that provide more context to the LLM for answering user's queries.\n", + "\n", + "Invoke the `as_retriever` function of the vector store you initialized in the last step, to create a retriever." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "qndTwf0tnQDv", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "1ff5c16c-e2d0-4e1a-e6ad-9ca8d9c65626" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "3\n" + ] + } + ], + "source": [ + "retriever = vectorstore.as_retriever()\n", + "# Check if the retriever is working by trying to fetch the relevant docs related\n", + "# to the word 'MMLU'(Massive Multitask Language Understanding). If the length is\n", + "# greater than zero, it means that the retriever is functioning well.\n", + "print(len(retriever.invoke(\"MMLU\")))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7Qw00lvPnjfR" + }, + "source": [ + "## Generator\n", + "\n", + "The Generator prompts the LLM for an answer when the user asks a question. The retriever you created in the previous stage from the Pinecone vector store will be used to pass relevant embeddings from the website data to the LLM to provide more context to the user's query.\n", + "\n", + "You'll perform the following steps in this stage:\n", + "\n", + "1. Chain together the following:\n", + " * A prompt for extracting the relevant embeddings using the retriever.\n", + " * A prompt for answering any question using LangChain.\n", + " * An LLM model from Gemini for prompting.\n", + " \n", + "2. Run the created chain with a question as input to prompt the model for an answer.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "c2MK2wLwnkLg" + }, + "source": [ + "### Initialize Gemini\n", + "\n", + "You must import `ChatGoogleGenerativeAI` from LangChain to initialize your model.\n", + " In this example, you will use **gemini-1.5-flash-latest**, as it supports text summarization. To know more about the text model, read Google AI's [language documentation](https://ai.google.dev/models/gemini).\n", + "\n", + "You can configure the model parameters such as ***temperature*** or ***top_p***, by passing the appropriate values when initializing the `ChatGoogleGenerativeAI` LLM. To learn more about the parameters and their uses, read Google AI's [concepts guide](https://ai.google.dev/docs/concepts#model_parameters)." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "CaA1vRCh7s36" + }, + "outputs": [], + "source": [ + "from langchain_google_genai import ChatGoogleGenerativeAI\n", + "\n", + "# To configure model parameters use the `generation_config` parameter.\n", + "# eg. generation_config = {\"temperature\": 0.7, \"topP\": 0.8, \"topK\": 40}\n", + "# If you only want to set a custom temperature for the model use the\n", + "# \"temperature\" parameter directly.\n", + "\n", + "llm = ChatGoogleGenerativeAI(model=\"gemini-1.5-flash-latest\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2BeLN6RXnuS2" + }, + "source": [ + "### Create prompt templates\n", + "\n", + "You'll use LangChain's [PromptTemplate](https://python.langchain.com/docs/modules/model_io/prompts/prompt_templates/) to generate prompts to the LLM for answering questions.\n", + "\n", + "In the `llm_prompt`, the variable `question` will be replaced later by the input question, and the variable `context` will be replaced by the relevant text from the website retrieved from the Pinecone vector store." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "90Czqh074dEC", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "940d6adb-320d-4c21-f283-08090f32c2d0" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "input_variables=['context', 'question'] template=\"You are an assistant for question-answering tasks.\\nUse the following context to answer the question.\\nIf you don't know the answer, just say that you don't know.\\nUse five sentences maximum and keep the answer concise.\\n\\nQuestion: {question}\\nContext: {context}\\nAnswer:\"\n" + ] + } + ], + "source": [ + "# Prompt template to query Gemini\n", + "llm_prompt_template = \"\"\"You are an assistant for question-answering tasks.\n", + "Use the following context to answer the question.\n", + "If you don't know the answer, just say that you don't know.\n", + "Use five sentences maximum and keep the answer concise.\n", + "\n", + "Question: {question}\n", + "Context: {context}\n", + "Answer:\"\"\"\n", + "\n", + "llm_prompt = PromptTemplate.from_template(llm_prompt_template)\n", + "\n", + "print(llm_prompt)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TkWpzMmpnx7b" + }, + "source": [ + "### Create a stuff documents chain\n", + "\n", + "LangChain provides [Chains](https://python.langchain.com/docs/modules/chains/) for chaining together LLMs with each other or other components for complex applications. You will create a **stuff documents chain** for this application. A stuff documents chain lets you combine all the relevant documents, insert them into the prompt, and pass that prompt to the LLM.\n", + "\n", + "You can create a stuff documents chain using the [LangChain Expression Language (LCEL)](https://python.langchain.com/docs/expression_language).\n", + "\n", + "To learn more about different types of document chains, read LangChain's [chains guide](https://python.langchain.com/docs/modules/chains/document/).\n", + "\n", + "The stuff documents chain for this application retrieves the relevant website data and passes it as the context to an LLM prompt along with the input question." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "id": "gj5sWzpwp7vc" + }, + "outputs": [], + "source": [ + "# Combine data from documents to readable string format.\n", + "def format_docs(docs):\n", + " return \"\\n\\n\".join(doc.page_content for doc in docs)\n", + "\n", + "# Create stuff documents chain using LCEL.\n", + "# This is called a chain because you are chaining\n", + "# together different elements with the LLM.\n", + "# In the following example, to create a stuff chain,\n", + "# you will combine content, prompt, LLM model, and\n", + "# output parser together like a chain using LCEL.\n", + "#\n", + "# The chain implements the following pipeline:\n", + "# 1. Extract data from documents and save to the variable `context`.\n", + "# 2. Use the `RunnablePassthrough` option to provide question during invoke.\n", + "# 3. The `context` and `question` are then passed to the prompt and\n", + "# input variables in the prompt are populated.\n", + "# 4. The prompt is then passed to the LLM (`gemini-pro`).\n", + "# 5. Output from the LLM is passed through an output parser\n", + "# to structure the model response.\n", + "rag_chain = (\n", + " {\"context\": retriever | format_docs, \"question\": RunnablePassthrough()}\n", + " | llm_prompt\n", + " | llm\n", + " | StrOutputParser()\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gmHx_F7DoMgM" + }, + "source": [ + "### Prompt the model\n", + "\n", + "You can now query the LLM by passing any question to the `invoke()` function of the stuff documents chain you created previously." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "id": "95W-sbTjoGGj", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 70 + }, + "outputId": "cf6940c9-2e25-48ea-dff5-d2ace096c068" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "\"Gemini is Google's latest and most capable AI model, designed to be flexible and efficient across various platforms. It excels in various tasks like image, audio, and video understanding, mathematical reasoning, and coding. Gemini comes in three sizes: Ultra, Pro, and Nano, catering to different complexities and computational needs. Its multimodal capabilities and advanced reasoning abilities are considered state-of-the-art in many domains. \\n\"" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "rag_chain.invoke(\"What is Gemini?\")" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb index edcd23217..d831cf42e 100644 --- a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb +++ b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb @@ -13,12 +13,11 @@ "cell_type": "code", "execution_count": 1, "metadata": { - "cellView": "form", "id": "tuOe1ymfHZPu" }, "outputs": [], "source": [ - "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", + "# @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", @@ -37,7 +36,7 @@ "id": "f22a409c18ef" }, "source": [ - "# Summarize large documents using LangChain and Gemini" + "# Gemini API: Summarize large documents using LangChain" ] }, { @@ -85,30 +84,55 @@ }, { "cell_type": "code", - "execution_count": 2, + "source": [ + "!pip install --quiet langchain-core==0.1.23\n", + "!pip install --quiet langchain==0.1.1\n", + "!pip install --quiet langchain-google-genai==0.0.6\n", + "!pip install --quiet -U langchain-community==0.0.20" + ], "metadata": { - "id": "yERdO0eFJpb-" + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "-49oubeWCHfO", + "outputId": "fb9656cc-5271-4397-e406-4536c18844e8" }, + "execution_count": 2, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m974.0/974.0 kB\u001b[0m \u001b[31m7.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m314.7/314.7 kB\u001b[0m \u001b[31m10.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m125.2/125.2 kB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.7/142.7 kB\u001b[0m \u001b[31m8.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m11.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.2/49.2 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m241.2/241.2 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m55.4/55.4 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m3.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m802.4/802.4 kB\u001b[0m \u001b[31m8.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m42.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.2/49.2 kB\u001b[0m \u001b[31m3.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m302.9/302.9 kB\u001b[0m \u001b[31m19.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m48.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m53.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m67.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m39.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m51.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m37.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m40.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m45.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m56.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m56.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m60.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m78.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m80.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m76.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m80.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m69.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m76.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m83.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m146.9/146.9 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m598.7/598.7 kB\u001b[0m \u001b[31m6.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h" ] } - ], - "source": [ - "!pip install --quiet langchain\n", - "!pip install --quiet langchain-google-genai\n", - "!pip install --quiet -U langchain-community" ] }, { @@ -117,15 +141,7 @@ "metadata": { "id": "rAv0UicpKARZ" }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:root:USER_AGENT environment variable not set, consider setting it to identify your requests.\n" - ] - } - ], + "outputs": [], "source": [ "from langchain import PromptTemplate\n", "from langchain.document_loaders import WebBaseLoader\n", @@ -136,25 +152,27 @@ { "cell_type": "markdown", "metadata": { - "id": "e1dZNWvUzksX" + "id": "FQOGMejVu-6D" }, "source": [ "## Configure 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](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb) for an example." + "To run the following cell, your API key must be stored 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](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication.ipynb) for an example.\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { - "id": "1RO5jvTTddtc" + "id": "ysayz8skEfBW" }, "outputs": [], "source": [ - "# Run this cell and paste the API key in the prompt\n", + "import os\n", "from google.colab import userdata\n", - "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')" + "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n", + "\n", + "os.environ[\"GOOGLE_API_KEY\"] = GOOGLE_API_KEY" ] }, { @@ -196,20 +214,10 @@ "metadata": { "id": "TTgmyxXzKCSq" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[Document(page_content=\"\\n\\n\\n\\n\\n\\nIntroducing Gemini: Google’s most capable AI model yet\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nSkip to main content\\n\\n\\n\\n\\n\\n The Keyword\\n \\n\\n\\n\\n\\n Introducing Gemini: our largest and most capable AI model\\n \\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Latest stories\\n \\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Android\\n \\n \\n\\n\\n\\n Chrome\\n \\n \\n\\n\\n\\n Chromebooks\\n \\n \\n\\n\\n\\n Google Play\\n \\n \\n\\n\\n\\n Wear OS by Google\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Chromecast\\n \\n \\n\\n\\n\\n Fitbit\\n \\n \\n\\n\\n\\n Google Nest\\n \\n \\n\\n\\n\\n Pixel\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Gemini\\n \\n \\n\\n\\n\\n Google Assistant\\n \\n \\n\\n\\n\\n Maps\\n \\n \\n\\n\\n\\n News\\n \\n \\n\\n\\n\\n Search\\n \\n \\n\\n\\n\\n Shopping\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Photos\\n \\n \\n\\n\\n\\n Translate\\n \\n \\n\\n\\n\\n Registry\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Docs, Sheets and Slides\\n \\n \\n\\n\\n\\n Gmail\\n \\n \\n\\n\\n\\n Google Cloud\\n \\n \\n\\n\\n\\n Meet\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n Android\\n\\n \\n \\n\\n\\n\\n Chrome\\n\\n \\n \\n\\n\\n\\n Chromebooks\\n\\n \\n \\n\\n\\n\\n Google Play\\n\\n \\n \\n\\n\\n\\n Wear OS by Google\\n\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n Chromecast\\n\\n \\n \\n\\n\\n\\n Fitbit\\n\\n \\n \\n\\n\\n\\n Google Nest\\n\\n \\n \\n\\n\\n\\n Pixel\\n\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n Gemini\\n\\n \\n \\n\\n\\n\\n Google Assistant\\n\\n \\n \\n\\n\\n\\n Maps\\n\\n \\n \\n\\n\\n\\n News\\n\\n \\n \\n\\n\\n\\n Search\\n\\n \\n \\n\\n\\n\\n Shopping\\n\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n Photos\\n\\n \\n \\n\\n\\n\\n Translate\\n\\n \\n \\n\\n\\n\\n Registry\\n\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n Docs, Sheets and Slides\\n\\n \\n \\n\\n\\n\\n Gmail\\n\\n \\n \\n\\n\\n\\n Google Cloud\\n\\n \\n \\n\\n\\n\\n Meet\\n\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Diversity and inclusion\\n \\n \\n\\n\\n\\n Education\\n \\n \\n\\n\\n\\n Google.org\\n \\n \\n\\n\\n\\n Grow with Google\\n \\n \\n\\n\\n\\n Sustainability\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n AI\\n \\n \\n\\n\\n\\n Developers\\n \\n \\n\\n\\n\\n Families\\n \\n \\n\\n\\n\\n Next billion users\\n \\n \\n\\n\\n\\n Safety and security\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Data centers and infrastructure\\n \\n \\n\\n\\n\\n Doodles\\n \\n \\n\\n\\n\\n Googlers\\n \\n \\n\\n\\n\\n Life at Google\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Google in Asia\\n \\n \\n\\n\\n\\n Google in Europe\\n \\n \\n\\n\\n\\n Google in Latin America\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Sundar Pichai, CEO\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n Diversity and inclusion\\n\\n \\n \\n\\n\\n\\n Education\\n\\n \\n \\n\\n\\n\\n Google.org\\n\\n \\n \\n\\n\\n\\n Grow with Google\\n\\n \\n \\n\\n\\n\\n Sustainability\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n AI\\n\\n \\n \\n\\n\\n\\n Developers\\n\\n \\n \\n\\n\\n\\n Families\\n\\n \\n \\n\\n\\n\\n Next billion users\\n\\n \\n \\n\\n\\n\\n Safety and security\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n Data centers and infrastructure\\n\\n \\n \\n\\n\\n\\n Doodles\\n\\n \\n \\n\\n\\n\\n Googlers\\n\\n \\n \\n\\n\\n\\n Life at Google\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n Google in Asia\\n\\n \\n \\n\\n\\n\\n Google in Europe\\n\\n \\n \\n\\n\\n\\n Google in Latin America\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n Sundar Pichai, CEO\\n\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n The Keyword\\n \\n\\n\\n\\n\\n\\n\\n\\n Latest stories\\n \\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Product updates\\n \\n\\n\\n\\n Android, Chrome & Play\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Android\\n \\n \\n\\n\\n\\n Chrome\\n \\n \\n\\n\\n\\n Chromebooks\\n \\n \\n\\n\\n\\n Google Play\\n \\n \\n\\n\\n\\n Wear OS by Google\\n \\n \\n\\n\\n\\n\\n\\n Devices & Services\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Chromecast\\n \\n \\n\\n\\n\\n Fitbit\\n \\n \\n\\n\\n\\n Google Nest\\n \\n \\n\\n\\n\\n Pixel\\n \\n \\n\\n\\n\\n\\n\\n Explore & Get Answers\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Gemini\\n \\n \\n\\n\\n\\n Google Assistant\\n \\n \\n\\n\\n\\n Maps\\n \\n \\n\\n\\n\\n News\\n \\n \\n\\n\\n\\n Search\\n \\n \\n\\n\\n\\n Shopping\\n \\n \\n\\n\\n\\n\\n\\n Connect & Communicate\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Photos\\n \\n \\n\\n\\n\\n Translate\\n \\n \\n\\n\\n\\n Registry\\n \\n \\n\\n\\n\\n\\n\\n In The Cloud\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Docs, Sheets and Slides\\n \\n \\n\\n\\n\\n Gmail\\n \\n \\n\\n\\n\\n Google Cloud\\n \\n \\n\\n\\n\\n Meet\\n \\n \\n\\n\\n\\n More on the Cloud Blog\\n \\n \\n\\n\\n\\n\\n\\n\\n\\n\\n See all product updates\\n \\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Company news\\n \\n\\n\\n\\n Outreach & initiatives\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Diversity and inclusion\\n \\n \\n\\n\\n\\n Education\\n \\n \\n\\n\\n\\n Google.org\\n \\n \\n\\n\\n\\n Grow with Google\\n \\n \\n\\n\\n\\n Sustainability\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Technology\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n AI\\n \\n \\n\\n\\n\\n Developers\\n \\n \\n\\n\\n\\n Families\\n \\n \\n\\n\\n\\n Next billion users\\n \\n \\n\\n\\n\\n Safety and security\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Inside Google\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Data centers and infrastructure\\n \\n \\n\\n\\n\\n Doodles\\n \\n \\n\\n\\n\\n Googlers\\n \\n \\n\\n\\n\\n Life at Google\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Around the globe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Google in Asia\\n \\n \\n\\n\\n\\n Google in Europe\\n \\n \\n\\n\\n\\n Google in Latin America\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n Authors\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Sundar Pichai, CEO\\n \\n \\n\\n\\n\\n Ruth Porat, SVP and CFO\\n \\n \\n\\n\\n\\n Kent Walker, SVP\\n \\n \\n\\n\\n\\n See all\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPress corner\\n\\n\\n\\n\\n RSS feed\\n \\n\\n\\n\\n\\n\\n Subscribe\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nAI\\n\\n\\nIntroducing Gemini: our largest and most capable AI model\\n\\n\\n\\n\\n\\n\\n\\nDec 06, 2023\\n[[read-time]] min read\\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Making AI more helpful for everyone\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nSundar Pichai\\n\\n CEO of Google and Alphabet\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nDemis Hassabis\\n\\n CEO and Co-Founder, Google DeepMind\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\nShare\\n\\n\\n\\n\\n\\n\\nTwitter\\n\\n\\n\\n\\n\\nFacebook\\n\\n\\n\\n\\n\\nLinkedIn\\n\\n\\n\\n\\n\\nMail\\n\\n\\n\\n\\n\\n\\nCopy link\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nIn this story\\n\\n\\nIn this story\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nNote from Sundar\\n\\n\\nIntroducing Gemini\\n\\n\\nState-of-the-art performance\\n\\n\\nNext-generation capabilities\\n\\n\\nScalable and efficient\\n\\n\\nResponsibility and safety\\n\\n\\nAvailability\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nA note from Google and Alphabet CEO Sundar Pichai:Every technology shift is an opportunity to advance scientific discovery, accelerate human progress, and improve lives. I believe the transition we are seeing right now with AI will be the most profound in our lifetimes, far bigger than the shift to mobile or to the web before it. AI has the potential to create opportunities — from the everyday to the extraordinary — for people everywhere. It will bring new waves of innovation and economic progress and drive knowledge, learning, creativity and productivity on a scale we haven’t seen before.That’s what excites me: the chance to make AI helpful for everyone, everywhere in the world.Nearly eight years into our journey as an AI-first company, the pace of progress is only accelerating: Millions of people are now using generative AI across our products to do things they couldn’t even a year ago, from finding answers to more complex questions to using new tools to collaborate and create. At the same time, developers are using our models and infrastructure to build new generative AI applications, and startups and enterprises around the world are growing with our AI tools.This is incredible momentum, and yet, we’re only beginning to scratch the surface of what’s possible.We’re approaching this work boldly and responsibly. That means being ambitious in our research and pursuing the capabilities that will bring enormous benefits to people and society, while building in safeguards and working collaboratively with governments and experts to address risks as AI becomes more capable. And we continue to invest in the very best tools, foundation models and infrastructure and bring them to our products and to others, guided by our AI Principles.Now, we’re taking the next step on our journey with Gemini, our most capable and general model yet, with state-of-the-art performance across many leading benchmarks. Our first version, Gemini 1.0, is optimized for different sizes: Ultra, Pro and Nano. These are the first models of the Gemini era and the first realization of the vision we had when we formed Google DeepMind earlier this year. This new era of models represents one of the biggest science and engineering efforts we’ve undertaken as a company. I’m genuinely excited for what’s ahead, and for the opportunities Gemini will unlock for people everywhere.– Sundar\\n\\n\\n\\n\\n\\nIntroducing GeminiBy Demis Hassabis, CEO and Co-Founder of Google DeepMind, on behalf of the Gemini teamAI has been the focus of my life's work, as for many of my research colleagues. Ever since programming AI for computer games as a teenager, and throughout my years as a neuroscience researcher trying to understand the workings of the brain, I’ve always believed that if we could build smarter machines, we could harness them to benefit humanity in incredible ways.This promise of a world responsibly empowered by AI continues to drive our work at Google DeepMind. For a long time, we’ve wanted to build a new generation of AI models, inspired by the way people understand and interact with the world. AI that feels less like a smart piece of software and more like something useful and intuitive — an expert helper or assistant.Today, we’re a step closer to this vision as we introduce Gemini, the most capable and general model we’ve ever built.Gemini is the result of large-scale collaborative efforts by teams across Google, including our colleagues at Google Research. It was built from the ground up to be multimodal, which means it can generalize and seamlessly understand, operate across and combine different types of information including text, code, audio, image and video.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nIntroducing Gemini: our largest and most capable AI model\\n\\n\\n\\n\\n\\n\\nGemini is also our most flexible model yet — able to efficiently run on everything from data centers to mobile devices. Its state-of-the-art capabilities will significantly enhance the way developers and enterprise customers build and scale with AI.We’ve optimized Gemini 1.0, our first version, for three different sizes:Gemini Ultra — our largest and most capable model for highly complex tasks.Gemini Pro — our best model for scaling across a wide range of tasks.Gemini Nano — our most efficient model for on-device tasks.\\n\\n\\n\\n\\n\\nState-of-the-art performanceWe've been rigorously testing our Gemini models and evaluating their performance on a wide variety of tasks. From natural image, audio and video understanding to mathematical reasoning, Gemini Ultra’s performance exceeds current state-of-the-art results on 30 of the 32 widely-used academic benchmarks used in large language model (LLM) research and development.With a score of 90.0%, Gemini Ultra is the first model to outperform human experts on MMLU (massive multitask language understanding), which uses a combination of 57 subjects such as math, physics, history, law, medicine and ethics for testing both world knowledge and problem-solving abilities.Our new benchmark approach to MMLU enables Gemini to use its reasoning capabilities to think more carefully before answering difficult questions, leading to significant improvements over just using its first impression.\\n\\n\\n\\n\\n\\n\\nGemini surpasses state-of-the-art performance on a range of benchmarks including text and coding.\\n\\n\\n\\nGemini Ultra also achieves a state-of-the-art score of 59.4% on the new MMMU benchmark, which consists of multimodal tasks spanning different domains requiring deliberate reasoning.With the image benchmarks we tested, Gemini Ultra outperformed previous state-of-the-art models, without assistance from optical character recognition (OCR) systems that extract text from images for further processing. These benchmarks highlight Gemini’s native multimodality and indicate early signs of Gemini's more complex reasoning abilities.See more details in our Gemini technical report.\\n\\n\\n\\n\\n\\n\\nGemini surpasses state-of-the-art performance on a range of multimodal benchmarks.\\n\\n\\n\\n\\nNext-generation capabilitiesUntil now, the standard approach to creating multimodal models involved training separate components for different modalities and then stitching them together to roughly mimic some of this functionality. These models can sometimes be good at performing certain tasks, like describing images, but struggle with more conceptual and complex reasoning.We designed Gemini to be natively multimodal, pre-trained from the start on different modalities. Then we fine-tuned it with additional multimodal data to further refine its effectiveness. This helps Gemini seamlessly understand and reason about all kinds of inputs from the ground up, far better than existing multimodal models — and its capabilities are state of the art in nearly every domain.Learn more about Gemini’s capabilities and see how it works.Sophisticated reasoningGemini 1.0’s sophisticated multimodal reasoning capabilities can help make sense of complex written and visual information. This makes it uniquely skilled at uncovering knowledge that can be difficult to discern amid vast amounts of data.Its remarkable ability to extract insights from hundreds of thousands of documents through reading, filtering and understanding information will help deliver new breakthroughs at digital speeds in many fields from science to finance.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini unlocks new scientific insights\\n\\n\\n\\n\\n\\n\\nUnderstanding text, images, audio and moreGemini 1.0 was trained to recognize and understand text, images, audio and more at the same time, so it better understands nuanced information and can answer questions relating to complicated topics. This makes it especially good at explaining reasoning in complex subjects like math and physics.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini explains reasoning in math and physics\\n\\n\\n\\n\\n\\n\\nAdvanced codingOur first version of Gemini can understand, explain and generate high-quality code in the world’s most popular programming languages, like Python, Java, C++, and Go. Its ability to work across languages and reason about complex information makes it one of the leading foundation models for coding in the world.Gemini Ultra excels in several coding benchmarks, including HumanEval, an important industry-standard for evaluating performance on coding tasks, and Natural2Code, our internal held-out dataset, which uses author-generated sources instead of web-based information.Gemini can also be used as the engine for more advanced coding systems. Two years ago we presented AlphaCode, the first AI code generation system to reach a competitive level of performance in programming competitions.Using a specialized version of Gemini, we created a more advanced code generation system, AlphaCode 2, which excels at solving competitive programming problems that go beyond coding to involve complex math and theoretical computer science.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n10:25\\n\\n\\n\\n\\nGemini excels at coding and competitive programming\\n\\n\\n\\n\\n\\n\\nWhen evaluated on the same platform as the original AlphaCode, AlphaCode 2 shows massive improvements, solving nearly twice as many problems, and we estimate that it performs better than 85% of competition participants — up from nearly 50% for AlphaCode. When programmers collaborate with AlphaCode 2 by defining certain properties for the code samples to follow, it performs even better.We’re excited for programmers to increasingly use highly capable AI models as collaborative tools that can help them reason about the problems, propose code designs and assist with implementation — so they can release apps and design better services, faster.See more details in our AlphaCode 2 technical report.\\n\\n\\n\\n\\n\\nMore reliable, scalable and efficientWe trained Gemini 1.0 at scale on our AI-optimized infrastructure using Google’s in-house designed Tensor Processing Units (TPUs) v4 and v5e. And we designed it to be our most reliable and scalable model to train, and our most efficient to serve.On TPUs, Gemini runs significantly faster than earlier, smaller and less-capable models. These custom-designed AI accelerators have been at the heart of Google's AI-powered products that serve billions of users like Search, YouTube, Gmail, Google Maps, Google Play and Android. They’ve also enabled companies around the world to train large-scale AI models cost-efficiently.Today, we’re announcing the most powerful, efficient and scalable TPU system to date, Cloud TPU v5p, designed for training cutting-edge AI models. This next generation TPU will accelerate Gemini’s development and help developers and enterprise customers train large-scale generative AI models faster, allowing new products and capabilities to reach customers sooner.\\n\\n\\n\\n\\n\\n\\nA row of Cloud TPU v5p AI accelerator supercomputers in a Google data center.\\n\\n\\n\\n\\nBuilt with responsibility and safety at the coreAt Google, we’re committed to advancing bold and responsible AI in everything we do. Building upon Google’s AI Principles and the robust safety policies across our products, we’re adding new protections to account for Gemini’s multimodal capabilities. At each stage of development, we’re considering potential risks and working to test and mitigate them.Gemini has the most comprehensive safety evaluations of any Google AI model to date, including for bias and toxicity. We’ve conducted novel research into potential risk areas like cyber-offense, persuasion and autonomy, and have applied Google Research’s best-in-class adversarial testing techniques to help identify critical safety issues in advance of Gemini’s deployment.To identify blindspots in our internal evaluation approach, we’re working with a diverse group of external experts and partners to stress-test our models across a range of issues.To diagnose content safety issues during Gemini’s training phases and ensure its output follows our policies, we’re using benchmarks such as Real Toxicity Prompts, a set of 100,000 prompts with varying degrees of toxicity pulled from the web, developed by experts at the Allen Institute for AI. Further details on this work are coming soon.To limit harm, we built dedicated safety classifiers to identify, label and sort out content involving violence or negative stereotypes, for example. Combined with robust filters, this layered approach is designed to make Gemini safer and more inclusive for everyone. Additionally, we’re continuing to address known challenges for models such as factuality, grounding, attribution and corroboration.Responsibility and safety will always be central to the development and deployment of our models. This is a long-term commitment that requires building collaboratively, so we’re partnering with the industry and broader ecosystem on defining best practices and setting safety and security benchmarks through organizations like MLCommons, the Frontier Model Forum and its AI Safety Fund, and our Secure AI Framework (SAIF), which was designed to help mitigate security risks specific to AI systems across the public and private sectors. We’ll continue partnering with researchers, governments and civil society groups around the world as we develop Gemini.\\n\\n\\n\\n\\n\\nMaking Gemini available to the worldGemini 1.0 is now rolling out across a range of products and platforms:Gemini Pro in Google productsWe’re bringing Gemini to billions of people through Google products.Starting today, Bard will use a fine-tuned version of Gemini Pro for more advanced reasoning, planning, understanding and more. This is the biggest upgrade to Bard since it launched. It will be available in English in more than 170 countries and territories, and we plan to expand to different modalities and support new languages and locations in the near future.We’re also bringing Gemini to Pixel. Pixel 8 Pro is the first smartphone engineered to run Gemini Nano, which is powering new features like Summarize in the Recorder app and rolling out in Smart Reply in Gboard, starting with WhatsApp, Line and KakaoTalk1 — with more messaging apps coming next year.In the coming months, Gemini will be available in more of our products and services like Search, Ads, Chrome and Duet AI.We’re already starting to experiment with Gemini in Search, where it's making our Search Generative Experience (SGE) faster for users, with a 40% reduction in latency in English in the U.S., alongside improvements in quality.Building with GeminiStarting on December 13, developers and enterprise customers can access Gemini Pro via the Gemini API in Google AI Studio or Google Cloud Vertex AI.Google AI Studio is a free, web-based developer tool to prototype and launch apps quickly with an API key. When it's time for a fully-managed AI platform, Vertex AI allows customization of Gemini with full data control and benefits from additional Google Cloud features for enterprise security, safety, privacy and data governance and compliance.Android developers will also be able to build with Gemini Nano, our most efficient model for on-device tasks, via AICore, a new system capability available in Android 14, starting on Pixel 8 Pro devices. Sign up for an early preview of AICore.Gemini Ultra coming soonFor Gemini Ultra, we’re currently completing extensive trust and safety checks, including red-teaming by trusted external parties, and further refining the model using fine-tuning and reinforcement learning from human feedback (RLHF) before making it broadly available.As part of this process, we’ll make Gemini Ultra available to select customers, developers, partners and safety and responsibility experts for early experimentation and feedback before rolling it out to developers and enterprise customers early next year.Early next year, we’ll also launch Bard Advanced, a new, cutting-edge AI experience that gives you access to our best models and capabilities, starting with Gemini Ultra.\\n\\n\\n\\n\\nThe Gemini era: enabling a future of innovationThis is a significant milestone in the development of AI, and the start of a new era for us at Google as we continue to rapidly innovate and responsibly advance the capabilities of our models.We’ve made great progress on Gemini so far and we’re working hard to further extend its capabilities for future versions, including advances in planning and memory, and increasing the context window for processing even more information to give better responses.We’re excited by the amazing possibilities of a world responsibly empowered by AI — a future of innovation that will enhance creativity, extend knowledge, advance science and transform the way billions of people live and work around the world.\\n\\n\\n\\n\\n\\n\\n\\n\\nCollection\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nCollection\\n\\nMore about Gemini\\nExplore our collection to find out more about Gemini, the most capable and general model we’ve ever built.\\n\\nSee more\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Get more stories from Google in your inbox.\\n \\n\\n\\n\\n\\n\\n Email address\\n \\n\\n\\n\\n\\n\\n Your information will be used in accordance with\\n \\nGoogle's privacy policy.\\n\\n\\n Subscribe\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nDone. Just one step more.\\n\\nCheck your inbox to confirm your subscription.\\n\\nYou are already subscribed to our newsletter.\\n\\n\\n\\n You can also subscribe with a\\n \\ndifferent email address\\n\\n .\\n \\n\\n\\n\\n\\n\\n\\nPOSTED IN:\\n\\n\\n\\n\\n\\n\\nAI\\n\\n\\n \\n\\n\\n\\n\\n\\nGemini\\n\\n\\n \\n\\n\\n\\n\\n\\nDevelopers\\n\\n\\n \\n\\n\\n\\n\\n\\nGoogle Cloud\\n\\n\\n \\n\\n\\n\\n\\n\\nResearch\\n\\n\\n \\n\\n\\n\\n\\n\\nGoogle DeepMind\\n\\n\\n \\n\\n\\n\\n\\n\\nPixel\\n\\n\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nRead Article\\n\\n\\n\\n\\n\\n\\n\\nMore Information\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n1\\n\\nUpdated on Dec 13 to include additional messaging apps\\n\\n\\n\\nCollapse\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Related stories\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nLife at Google\\nQuiz: Test your knowledge of Google’s May news\\n\\n\\n\\n By\\n \\n \\n Molly McHugh-Johnson\\n \\n\\n Jun 13, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nResearch\\nIntroducing Google's new Academic Research Awards\\n\\n\\n\\n By\\n \\n \\n Ashley Gardner\\n \\n\\n Cori Grainger\\n \\n\\n Jun 13, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPixel\\nJune Feature Drop: New features and upgrades for the Pixel portfolio\\n\\n\\n\\n By\\n \\n \\n Mikaela Kraft\\n \\n\\n Jun 11, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nEntrepreneurs\\nSupport for European and Israeli startups working on AI and climate solutions\\n\\n\\n\\n By\\n \\n \\n Matt Brittin\\n \\n\\n Jun 11, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nAI\\nNotebookLM goes global with Slides support and better ways to fact-check\\n\\n\\n\\n By\\n \\n \\n Steven Johnson\\n \\n\\n Raiza Martin\\n \\n\\n Jun 06, 2024\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nArts & Culture\\nA new AI tool to help monitor coral reef health\\n\\n\\n\\n By\\n \\n \\n Steve Simpson\\n \\n\\n Ben Williams\\n \\n\\n Jun 06, 2024\\n\\n\\n\\n\\n\\n\\n.\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nLet’s stay in touch. Get the latest news from Google in your inbox.\\n\\n\\nSubscribe\\nNo thanks\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n Follow Us\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\nPrivacy\\n \\n\\n\\nTerms\\n \\n\\n\\nAbout Google\\n \\n\\n\\nGoogle Products\\n \\n\\n\\nAbout the Keyword\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n Help\\n \\n\\n\\n\\n\\n\\n Deutsch\\n \\n\\n English\\n \\n\\n English (Africa)\\n \\n\\n English (Australia)\\n \\n\\n English (Canada)\\n \\n\\n English (India)\\n \\n\\n English (MENA)\\n \\n\\n Español (España)\\n \\n\\n Español (Latinoamérica)\\n \\n\\n Français (Canada)\\n \\n\\n Français (France)\\n \\n\\n Italiano\\n \\n\\n Nederlands (Nederland)\\n \\n\\n Polski\\n \\n\\n Português (Brasil)\\n \\n\\n اللغة العربية (MENA)\\n \\n\\n 日本語 (日本)\\n \\n\\n 한국어\\n \\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\", metadata={'source': 'https://blog.google/technology/ai/google-gemini-ai/#sundar-note', 'title': 'Introducing Gemini: Google’s most capable AI model yet', 'description': 'Gemini is our most capable and general model, built to be multimodal and optimized for three different sizes: Ultra, Pro and Nano.', 'language': 'en-us'})]\n" - ] - } - ], + "outputs": [], "source": [ "loader = WebBaseLoader(\"https://blog.google/technology/ai/google-gemini-ai/#sundar-note\")\n", - "docs = loader.load()\n", - "\n", - "print(docs)" + "docs = loader.load()" ] }, { @@ -237,14 +245,12 @@ "source": [ "from langchain_google_genai import ChatGoogleGenerativeAI\n", "\n", - "# If there is no env variable set for API key, you can pass the API key\n", - "# to the parameter `google_api_key` of the `ChatGoogleGenerativeAI` function:\n", - "# `google_api_key=\"key\"`.\n", + "# To configure model parameters use the `generation_config` parameter.\n", + "# eg. generation_config = {\"temperature\": 0.7, \"topP\": 0.8, \"topK\": 40}\n", + "# If you only want to set a custom temperature for the model use the\n", + "# \"temperature\" parameter directly.\n", "\n", - "llm = ChatGoogleGenerativeAI(google_api_key=GOOGLE_API_KEY,\n", - " model=\"gemini-1.5-flash-latest\",\n", - " temperature=0.7,\n", - " top_p=0.85)" + "llm = ChatGoogleGenerativeAI(model=\"gemini-1.5-flash-latest\")" ] }, { @@ -268,12 +274,16 @@ "cell_type": "code", "execution_count": 7, "metadata": { - "id": "rixvvvaNKLe_" + "id": "rixvvvaNKLe_", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "863573d1-7659-4a15-acf7-3fc85548e843" }, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ "input_variables=['text'] template='Write a concise summary of the following:\\n\"{text}\"\\nCONCISE SUMMARY:'\n" ] @@ -358,21 +368,26 @@ "cell_type": "code", "execution_count": 9, "metadata": { - "id": "k9_GxkA5ePRR" + "id": "k9_GxkA5ePRR", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 140 + }, + "outputId": "e838934c-0893-4b59-ec25-ee7dc787c590" }, "outputs": [ { + "output_type": "execute_result", "data": { + "text/plain": [ + "\"Google has introduced Gemini, its most capable AI model yet. Gemini is multimodal, meaning it can understand and interact with various forms of information, including text, code, audio, images, and video. It comes in three sizes: Ultra (for complex tasks), Pro (for a wide range of tasks), and Nano (for on-device tasks). Gemini surpasses existing models in performance benchmarks across various domains, including natural language understanding, reasoning, and coding. \\n\\nGoogle emphasizes Gemini's safety and responsibility features, including comprehensive bias and toxicity evaluation, adversarial testing, and collaboration with external experts. \\n\\nGemini is being integrated into various Google products, such as Bard, Pixel, Search, and Ads, and will be available to developers through APIs. \\n\\nThe release of Gemini marks a significant milestone in AI development, opening up new possibilities for innovation and enhancing human capabilities in various areas. \\n\"" + ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" - }, - "text/plain": [ - "\"Google has introduced Gemini, its most capable AI model yet. It's multimodal, meaning it can understand and process various types of information, including text, code, audio, images, and video. Gemini is optimized for different sizes: Ultra (largest and most capable), Pro (best for scaling across tasks), and Nano (most efficient for on-device tasks). \\n\\nGemini surpasses current state-of-the-art performance on various benchmarks, including language understanding, reasoning, and coding. It's also more reliable, scalable, and efficient than previous models.\\n\\nGoogle emphasizes responsibility and safety in Gemini's development, implementing extensive safety evaluations and working with external experts. \\n\\nGemini is being rolled out across Google products, including Bard, Pixel, Search, Ads, Chrome, and Duet AI. Developers and enterprise customers can access Gemini Pro through APIs, while Android developers can use Gemini Nano via AICore. \\n\\nGemini Ultra will be available to select customers, developers, and partners for early experimentation before a broader rollout early next year. \\n\\nGoogle sees Gemini as a significant milestone in AI development, enabling a future of innovation that enhances creativity, expands knowledge, advances science, and transforms how people live and work. \\n\"" - ] + } }, - "execution_count": 9, "metadata": {}, - "output_type": "execute_result" + "execution_count": 9 } ], "source": [ @@ -393,8 +408,8 @@ ], "metadata": { "colab": { - "name": "Gemini_LangChain_Summarization_WebLoad.ipynb", - "toc_visible": true + "toc_visible": true, + "provenance": [] }, "kernelspec": { "display_name": "Python 3", @@ -403,4 +418,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file From 9de0cfbd46349b5427d6079e338d17879da9287c Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Sun, 23 Jun 2024 23:08:05 -0700 Subject: [PATCH 9/9] Reformat notebooks --- .../Gemini_LangChain_QA_Chroma_WebLoad.ipynb | 50 ++++++----------- ...Gemini_LangChain_QA_Pinecone_WebLoad.ipynb | 41 +++++--------- ...mini_LangChain_Summarization_WebLoad.ipynb | 56 ++++++++----------- 3 files changed, 54 insertions(+), 93 deletions(-) diff --git a/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb index c9c767759..ff90970aa 100644 --- a/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb +++ b/examples/langchain/Gemini_LangChain_QA_Chroma_WebLoad.ipynb @@ -13,6 +13,7 @@ "cell_type": "code", "execution_count": null, "metadata": { + "cellView": "form", "id": "tuOe1ymfHZPu" }, "outputs": [], @@ -88,16 +89,12 @@ "cell_type": "code", "execution_count": 1, "metadata": { - "id": "olK4Ejjzuj76", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "138de6db-8520-4da7-af94-97fdf05573cf" + "id": "olK4Ejjzuj76" }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m241.2/241.2 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m55.4/55.4 kB\u001b[0m \u001b[31m1.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", @@ -396,16 +393,12 @@ "cell_type": "code", "execution_count": 8, "metadata": { - "id": "s3t4kmzIOZQq", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "7460ae1f-14bd-404c-c770-fa5750a294ce" + "id": "s3t4kmzIOZQq" }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "1\n" ] @@ -502,16 +495,12 @@ "cell_type": "code", "execution_count": 10, "metadata": { - "id": "90Czqh074dEC", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "9e167c1e-50d1-423f-b53c-421170f2f4e8" + "id": "90Czqh074dEC" }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "input_variables=['context', 'question'] template=\"You are an assistant for question-answering tasks.\\nUse the following context to answer the question.\\nIf you don't know the answer, just say that you don't know.\\nUse five sentences maximum and keep the answer concise.\\n\\nQuestion: {question} \\nContext: {context} \\nAnswer:\"\n" ] @@ -599,26 +588,21 @@ "cell_type": "code", "execution_count": 12, "metadata": { - "id": "4vIaopCsIq0B", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 105 - }, - "outputId": "4cfa55f2-8de2-4f37-eb00-41e7db7f2a9e" + "id": "4vIaopCsIq0B" }, "outputs": [ { - "output_type": "execute_result", "data": { - "text/plain": [ - "\"Gemini is Google's largest and most capable AI model, designed to be highly flexible and efficient across various devices, from data centers to mobile devices. It's optimized in three sizes: Ultra, Pro, and Nano, catering to different complexity levels and task requirements. Gemini surpasses state-of-the-art performance on multiple benchmarks, including text, code, and multimodal tasks, showcasing its advanced reasoning abilities. This model is trained to understand and process information across various modalities, including text, images, audio, and more, making it ideal for complex tasks like coding and scientific research. \\n\"" - ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" - } + }, + "text/plain": [ + "\"Gemini is Google's largest and most capable AI model, designed to be highly flexible and efficient across various devices, from data centers to mobile devices. It's optimized in three sizes: Ultra, Pro, and Nano, catering to different complexity levels and task requirements. Gemini surpasses state-of-the-art performance on multiple benchmarks, including text, code, and multimodal tasks, showcasing its advanced reasoning abilities. This model is trained to understand and process information across various modalities, including text, images, audio, and more, making it ideal for complex tasks like coding and scientific research. \\n\"" + ] }, + "execution_count": 12, "metadata": {}, - "execution_count": 12 + "output_type": "execute_result" } ], "source": [ @@ -639,8 +623,8 @@ ], "metadata": { "colab": { - "toc_visible": true, - "provenance": [] + "name": "Gemini_LangChain_QA_Chroma_WebLoad.ipynb", + "toc_visible": true }, "kernelspec": { "display_name": "Python 3", @@ -649,4 +633,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/examples/langchain/Gemini_LangChain_QA_Pinecone_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_QA_Pinecone_WebLoad.ipynb index d403affec..8758b488d 100644 --- a/examples/langchain/Gemini_LangChain_QA_Pinecone_WebLoad.ipynb +++ b/examples/langchain/Gemini_LangChain_QA_Pinecone_WebLoad.ipynb @@ -13,6 +13,7 @@ "cell_type": "code", "execution_count": 1, "metadata": { + "cellView": "form", "id": "rIIf_RgOf3sr" }, "outputs": [], @@ -399,16 +400,12 @@ "cell_type": "code", "execution_count": 10, "metadata": { - "id": "qndTwf0tnQDv", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "1ff5c16c-e2d0-4e1a-e6ad-9ca8d9c65626" + "id": "qndTwf0tnQDv" }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "3\n" ] @@ -491,16 +488,12 @@ "cell_type": "code", "execution_count": 12, "metadata": { - "id": "90Czqh074dEC", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "940d6adb-320d-4c21-f283-08090f32c2d0" + "id": "90Czqh074dEC" }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "input_variables=['context', 'question'] template=\"You are an assistant for question-answering tasks.\\nUse the following context to answer the question.\\nIf you don't know the answer, just say that you don't know.\\nUse five sentences maximum and keep the answer concise.\\n\\nQuestion: {question}\\nContext: {context}\\nAnswer:\"\n" ] @@ -589,26 +582,21 @@ "cell_type": "code", "execution_count": 14, "metadata": { - "id": "95W-sbTjoGGj", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 70 - }, - "outputId": "cf6940c9-2e25-48ea-dff5-d2ace096c068" + "id": "95W-sbTjoGGj" }, "outputs": [ { - "output_type": "execute_result", "data": { - "text/plain": [ - "\"Gemini is Google's latest and most capable AI model, designed to be flexible and efficient across various platforms. It excels in various tasks like image, audio, and video understanding, mathematical reasoning, and coding. Gemini comes in three sizes: Ultra, Pro, and Nano, catering to different complexities and computational needs. Its multimodal capabilities and advanced reasoning abilities are considered state-of-the-art in many domains. \\n\"" - ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" - } + }, + "text/plain": [ + "\"Gemini is Google's latest and most capable AI model, designed to be flexible and efficient across various platforms. It excels in various tasks like image, audio, and video understanding, mathematical reasoning, and coding. Gemini comes in three sizes: Ultra, Pro, and Nano, catering to different complexities and computational needs. Its multimodal capabilities and advanced reasoning abilities are considered state-of-the-art in many domains. \\n\"" + ] }, + "execution_count": 14, "metadata": {}, - "execution_count": 14 + "output_type": "execute_result" } ], "source": [ @@ -618,7 +606,8 @@ ], "metadata": { "colab": { - "provenance": [] + "name": "Gemini_LangChain_QA_Pinecone_WebLoad.ipynb", + "toc_visible": true }, "kernelspec": { "display_name": "Python 3", @@ -627,4 +616,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb index d831cf42e..f0b7b6b78 100644 --- a/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb +++ b/examples/langchain/Gemini_LangChain_Summarization_WebLoad.ipynb @@ -13,6 +13,7 @@ "cell_type": "code", "execution_count": 1, "metadata": { + "cellView": "form", "id": "tuOe1ymfHZPu" }, "outputs": [], @@ -84,24 +85,14 @@ }, { "cell_type": "code", - "source": [ - "!pip install --quiet langchain-core==0.1.23\n", - "!pip install --quiet langchain==0.1.1\n", - "!pip install --quiet langchain-google-genai==0.0.6\n", - "!pip install --quiet -U langchain-community==0.0.20" - ], + "execution_count": 2, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "-49oubeWCHfO", - "outputId": "fb9656cc-5271-4397-e406-4536c18844e8" + "id": "-49oubeWCHfO" }, - "execution_count": 2, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m241.2/241.2 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m55.4/55.4 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", @@ -133,6 +124,12 @@ "\u001b[?25h" ] } + ], + "source": [ + "!pip install --quiet langchain-core==0.1.23\n", + "!pip install --quiet langchain==0.1.1\n", + "!pip install --quiet langchain-google-genai==0.0.6\n", + "!pip install --quiet -U langchain-community==0.0.20" ] }, { @@ -274,16 +271,12 @@ "cell_type": "code", "execution_count": 7, "metadata": { - "id": "rixvvvaNKLe_", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "863573d1-7659-4a15-acf7-3fc85548e843" + "id": "rixvvvaNKLe_" }, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "input_variables=['text'] template='Write a concise summary of the following:\\n\"{text}\"\\nCONCISE SUMMARY:'\n" ] @@ -368,26 +361,21 @@ "cell_type": "code", "execution_count": 9, "metadata": { - "id": "k9_GxkA5ePRR", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 140 - }, - "outputId": "e838934c-0893-4b59-ec25-ee7dc787c590" + "id": "k9_GxkA5ePRR" }, "outputs": [ { - "output_type": "execute_result", "data": { - "text/plain": [ - "\"Google has introduced Gemini, its most capable AI model yet. Gemini is multimodal, meaning it can understand and interact with various forms of information, including text, code, audio, images, and video. It comes in three sizes: Ultra (for complex tasks), Pro (for a wide range of tasks), and Nano (for on-device tasks). Gemini surpasses existing models in performance benchmarks across various domains, including natural language understanding, reasoning, and coding. \\n\\nGoogle emphasizes Gemini's safety and responsibility features, including comprehensive bias and toxicity evaluation, adversarial testing, and collaboration with external experts. \\n\\nGemini is being integrated into various Google products, such as Bard, Pixel, Search, and Ads, and will be available to developers through APIs. \\n\\nThe release of Gemini marks a significant milestone in AI development, opening up new possibilities for innovation and enhancing human capabilities in various areas. \\n\"" - ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" - } + }, + "text/plain": [ + "\"Google has introduced Gemini, its most capable AI model yet. Gemini is multimodal, meaning it can understand and interact with various forms of information, including text, code, audio, images, and video. It comes in three sizes: Ultra (for complex tasks), Pro (for a wide range of tasks), and Nano (for on-device tasks). Gemini surpasses existing models in performance benchmarks across various domains, including natural language understanding, reasoning, and coding. \\n\\nGoogle emphasizes Gemini's safety and responsibility features, including comprehensive bias and toxicity evaluation, adversarial testing, and collaboration with external experts. \\n\\nGemini is being integrated into various Google products, such as Bard, Pixel, Search, and Ads, and will be available to developers through APIs. \\n\\nThe release of Gemini marks a significant milestone in AI development, opening up new possibilities for innovation and enhancing human capabilities in various areas. \\n\"" + ] }, + "execution_count": 9, "metadata": {}, - "execution_count": 9 + "output_type": "execute_result" } ], "source": [ @@ -408,8 +396,8 @@ ], "metadata": { "colab": { - "toc_visible": true, - "provenance": [] + "name": "Gemini_LangChain_Summarization_WebLoad.ipynb", + "toc_visible": true }, "kernelspec": { "display_name": "Python 3", @@ -418,4 +406,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +}