diff --git a/gemini/evaluation/evaluate_models_in_vertex_ai_studio_and_model_garden.ipynb b/gemini/evaluation/evaluate_models_in_vertex_ai_studio_and_model_garden.ipynb index a3be634bd86..b58418d3eb0 100644 --- a/gemini/evaluation/evaluate_models_in_vertex_ai_studio_and_model_garden.ipynb +++ b/gemini/evaluation/evaluate_models_in_vertex_ai_studio_and_model_garden.ipynb @@ -1602,7 +1602,7 @@ "for i, prompt_template in enumerate(prompt_templates):\n", " eval_result = summarization_eval_task.evaluate(\n", " prompt_template=prompt_template,\n", - " model=model,\n", + " model=gemini_model,\n", " # Customize eval service rate limit based on your project's Gemini-1.5-pro model quota to improve speed.\n", " # See more details in https://cloud.google.com/vertex-ai/generative-ai/docs/models/run-evaluation#increase-quota\n", " evaluation_service_qps=1,\n", diff --git a/gemini/use-cases/intro_multimodal_use_cases.ipynb b/gemini/use-cases/intro_multimodal_use_cases.ipynb index dd5df3f03e3..6ca61a3b2ce 100644 --- a/gemini/use-cases/intro_multimodal_use_cases.ipynb +++ b/gemini/use-cases/intro_multimodal_use_cases.ipynb @@ -173,13 +173,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "id": "kc4WxYmLSBW5" }, - "outputs": [], - "source": [ - "%pip install --upgrade --quiet google-genai gitpython magika" + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mWARNING: Skipping /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/google_cloud_aiplatform-1.50.0.dist-info due to invalid metadata entry 'name'\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mWARNING: Skipping /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/google_cloud_storage-2.16.0.dist-info due to invalid metadata entry 'name'\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mDEPRECATION: Loading egg at /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/fsspec-2024.3.1-py3.11.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mDEPRECATION: Loading egg at /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/google_cloud_documentai_toolbox-0.12.2a0-py3.11.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mDEPRECATION: Loading egg at /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/google_cloud_documentai_toolbox-0.11.1a0-py3.11.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mWARNING: Skipping /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/google_cloud_aiplatform-1.50.0.dist-info due to invalid metadata entry 'name'\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mWARNING: Skipping /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/google_cloud_storage-2.16.0.dist-info due to invalid metadata entry 'name'\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mWARNING: Skipping /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/google_cloud_aiplatform-1.50.0.dist-info due to invalid metadata entry 'name'\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mWARNING: Skipping /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/google_cloud_aiplatform-1.50.0.dist-info due to invalid metadata entry 'name'\u001b[0m\u001b[33m\n", + "\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.0\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip3.11 install --upgrade pip\u001b[0m\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip install --upgrade --quiet google-genai gitingest" ] }, { @@ -263,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": { "id": "JGOJHtgDe5-r" }, @@ -293,14 +313,18 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 8, "metadata": { "id": "JTk488WDPBtQ" }, "outputs": [], "source": [ "from IPython.display import Audio, Image, Markdown, Video, display\n", - "from google.genai.types import CreateCachedContentConfig, GenerateContentConfig, Part" + "from gitingest import ingest\n", + "from google.genai.types import CreateCachedContentConfig, GenerateContentConfig, Part\n", + "import nest_asyncio\n", + "\n", + "nest_asyncio.apply()" ] }, { @@ -316,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "id": "2998506fe6d1" }, @@ -347,11 +371,90 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "577574234d7e" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "Okay, here's the average weather in Mountain View, CA in mid-May, followed by outfit suggestions:\n", + "\n", + "**Average Weather in Mountain View, CA in Mid-May:**\n", + "\n", + "* **Temperature:** Expect daytime highs in the mid-70s Fahrenheit (around 24-25 degrees Celsius). Evenings can cool down considerably, dropping into the low to mid-50s Fahrenheit (around 12-13 degrees Celsius).\n", + "* **Sunshine:** Mountain View typically enjoys plenty of sunshine in May.\n", + "* **Rain:** Rainfall is relatively low in May. You can expect a few rainy days a month, but the amount of rain is usually low.\n", + "* **Wind:** The breeze can be strong and add to the coolness in the evening.\n", + "* **Fog/Marine Layer:** Occasionally, the marine layer might drift in from the coast in the mornings, burning off by midday. This can bring cooler temperatures and mist.\n", + "\n", + "**Outfit Suggestions:**\n", + "\n", + "The key to dressing in Mountain View in May is layering. The temperature can fluctuate quite a bit between day and night.\n", + "\n", + "**Daytime Outfits:**\n", + "\n", + "* **Option 1 (Casual):**\n", + " * **Top:** A short-sleeved t-shirt or lightweight blouse in a breathable fabric like cotton, linen, or rayon.\n", + " * **Bottom:** Jeans, chinos, or a comfortable skirt (denim, cotton).\n", + " * **Shoes:** Sneakers, sandals, or flats.\n", + " * **Layer:** A light cardigan or denim jacket to throw on if it's breezy or if the marine layer is present.\n", + " * **Accessories:** Sunglasses, a hat (if desired), and sunscreen.\n", + "\n", + "* **Option 2 (Slightly More Dressy):**\n", + " * **Top:** A nice blouse or a lightweight knit top.\n", + " * **Bottom:** Dress pants, a midi skirt, or a flowy dress.\n", + " * **Shoes:** Loafers, ballet flats, or comfortable wedges.\n", + " * **Layer:** A blazer or a light jacket.\n", + " * **Accessories:** A scarf or a necklace.\n", + "\n", + "* **Option 3 (Active):**\n", + " * **Top:** A moisture-wicking t-shirt or tank top.\n", + " * **Bottom:** Leggings, shorts, or athletic pants.\n", + " * **Shoes:** Sneakers or running shoes.\n", + " * **Layer:** A light windbreaker or jacket.\n", + "\n", + "**Evening Outfits:**\n", + "\n", + "The evenings can be significantly cooler, so layering is essential.\n", + "\n", + "* **Option 1 (Casual):**\n", + " * **Top:** The same top you wore during the day.\n", + " * **Bottom:** The same bottom you wore during the day.\n", + " * **Layer:** A heavier sweater, fleece jacket, or light down jacket.\n", + " * **Shoes:** The same shoes you wore during the day or closed-toe shoes if you're wearing sandals during the day.\n", + " * **Accessories:** A scarf, gloves (especially if you get cold easily), and a hat (optional).\n", + "\n", + "* **Option 2 (Slightly More Dressy):**\n", + " * **Top:** The same top you wore during the day.\n", + " * **Bottom:** The same bottom you wore during the day.\n", + " * **Layer:** A stylish jacket (leather, denim, or trench coat) or a dressy sweater.\n", + " * **Shoes:** Loafers, booties or comfortable heels.\n", + " * **Accessories:** A statement necklace or a nice scarf.\n", + "\n", + "* **Option 3 (Comfortable):**\n", + " * **Top:** A long-sleeved shirt.\n", + " * **Bottom:** Comfortable sweatpants or leggings.\n", + " * **Layer:** A thick jacket.\n", + " * **Shoes:** Slippers or warm socks\n", + "\n", + "**Important Considerations:**\n", + "\n", + "* **Fabric:** Choose breathable fabrics like cotton, linen, or rayon for daytime wear.\n", + "* **Shoes:** Comfortable walking shoes are a must, as you'll likely be doing some walking.\n", + "* **Always check the forecast:** While these are averages, weather can be unpredictable. Check the forecast before you go to pack accordingly.\n", + "* **Bring a bag:** A tote bag or backpack is useful for carrying layers, water, sunscreen, and other essentials.\n", + "* **Personal Preference:** Adjust these suggestions based on your own comfort level and style.\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "question = \"What is the average weather in Mountain View, CA in the middle of May?\"\n", "prompt = \"\"\"\n", @@ -660,78 +763,14 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": { "id": "ad22725252dc" }, "outputs": [], "source": [ "# The GitHub repository URL\n", - "repo_url = \"https://github.com/GoogleCloudPlatform/microservices-demo\" # @param {type:\"string\"}\n", - "\n", - "# The location to clone the repo\n", - "repo_dir = \"./repo\"" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "2375783544c5" - }, - "source": [ - "#### Define helper functions for processing GitHub repository" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "id": "362b2fd89bce" - }, - "outputs": [], - "source": [ - "import os\n", - "from pathlib import Path\n", - "import shutil\n", - "\n", - "import git\n", - "import magika\n", - "\n", - "m = magika.Magika()\n", - "\n", - "\n", - "def clone_repo(repo_url: str, repo_dir: str) -> None:\n", - " \"\"\"Shallow clone a GitHub repository\"\"\"\n", - " if os.path.exists(repo_dir):\n", - " shutil.rmtree(repo_dir)\n", - " os.makedirs(repo_dir, exist_ok=True)\n", - " git.Repo.clone_from(repo_url, repo_dir, depth=1)\n", - "\n", - "\n", - "def extract_code(repo_dir: str) -> tuple[list[str], str]:\n", - " \"\"\"Create an index and extract content of code/text files\"\"\"\n", - " code_index = []\n", - " code_text_lines = [] # Use a list for efficient concatenation\n", - "\n", - " for root, _, files in os.walk(repo_dir):\n", - " for file in files:\n", - " file_path = os.path.join(root, file)\n", - " relative_path = os.path.relpath(file_path, repo_dir)\n", - " code_index.append(relative_path)\n", - "\n", - " # Identify if the file is text or code\n", - " file_type = m.identify_path(Path(file_path))\n", - " if file_type.output.group in (\"text\", \"code\"):\n", - " try:\n", - " with open(file_path, encoding=\"utf-8\") as f:\n", - " code_text_lines.append(f\"----- File: {relative_path} -----\\n\")\n", - " code_text_lines.append(f.read())\n", - " code_text_lines.append(\"\\n-------------------------\\n\")\n", - " except (OSError, UnicodeDecodeError):\n", - " # Skip files that can't be read\n", - " pass\n", - "\n", - " return code_index, \"\".join(code_text_lines)" + "repo_url = \"https://github.com/GoogleCloudPlatform/microservices-demo\" # @param {type:\"string\"}" ] }, { @@ -747,14 +786,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "7f7e3cce09c7" }, "outputs": [], "source": [ - "clone_repo(repo_url, repo_dir)\n", - "code_index, code_text = extract_code(repo_dir)" + "exclude_patterns = [\n", + " \"*.png\",\n", + " \"*.jpg\",\n", + " \"*.jpeg\",\n", + " \"*.gif\",\n", + " \"*.svg\",\n", + " \"*.ico\",\n", + " \"*.webp\",\n", + " \"*.jar\",\n", + " \".git/\",\n", + " \"*.gitkeep\",\n", + "]\n", + "_, code_index, code_text = ingest(repo_url, exclude_patterns=exclude_patterns)" ] }, { @@ -773,7 +823,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "daeff13cca4a" },