diff --git a/audio/speech/getting-started/get_started_with_chirp_2_sdk.ipynb b/audio/speech/getting-started/get_started_with_chirp_2_sdk.ipynb index 02101cfe015..f9257fd20bb 100644 --- a/audio/speech/getting-started/get_started_with_chirp_2_sdk.ipynb +++ b/audio/speech/getting-started/get_started_with_chirp_2_sdk.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/audio/speech/getting-started/get_started_with_chirp_2_sdk_features.ipynb b/audio/speech/getting-started/get_started_with_chirp_2_sdk_features.ipynb index d86baa61cee..3a2b18f3817 100644 --- a/audio/speech/getting-started/get_started_with_chirp_2_sdk_features.ipynb +++ b/audio/speech/getting-started/get_started_with_chirp_2_sdk_features.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/audio/speech/getting-started/get_started_with_chirp_sdk.ipynb b/audio/speech/getting-started/get_started_with_chirp_sdk.ipynb index 0a48669020d..edcb8602c2a 100644 --- a/audio/speech/getting-started/get_started_with_chirp_sdk.ipynb +++ b/audio/speech/getting-started/get_started_with_chirp_sdk.ipynb @@ -50,7 +50,31 @@ " Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/audio/speech/use-cases/storytelling/storytelling.ipynb b/audio/speech/use-cases/storytelling/storytelling.ipynb index d944931cd45..4cacb34cebe 100644 --- a/audio/speech/use-cases/storytelling/storytelling.ipynb +++ b/audio/speech/use-cases/storytelling/storytelling.ipynb @@ -1,731 +1,755 @@ { - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "ur8xi4C7S06n" - }, - "outputs": [], - "source": [ - "# Copyright 2024 Google LLC\n", - "#\n", - "# 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": "JAPoU8Sm5E6e" - }, - "source": [ - "# Narrate a Multi-character Story with Gemini and Text-to-Speech\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - "
\n", - " \n", - " \"Google
Run in Colab\n", - "
\n", - "
\n", - " \n", - " \"Google
Run in Colab Enterprise\n", - "
\n", - "
\n", - " \n", - " \"Vertex
Open in Vertex AI Workbench\n", - "
\n", - "
\n", - " \n", - " \"GitHub
View on GitHub\n", - "
\n", - "
\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "42cc0c827290" - }, - "source": [ - "| | |\n", - "|-|-|\n", - "| Author(s) | [Holt Skinner](https://github.com/holtskinner) |" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "tvgnzT1CKxrO" - }, - "source": [ - "## Overview\n", - "\n", - "This notebook demonstrates how to use the [Gemini API in Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/overview) to generate a play script and create an audio performance with each character having a distinct voice using the [Text-to-Speech API](https://cloud.google.com/text-to-speech).\n", - "\n", - "The steps performed include:\n", - "\n", - "- Create a story using Gemini\n", - "- Assign each character to a voice.\n", - "- Synthesize each line based on character voice.\n", - "- Combine audio files into one MP3 file." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "aed92deeb4a0" - }, - "source": [ - "### Costs\n", - "\n", - "This tutorial uses billable components of Google Cloud:\n", - "\n", - "* Gemini API in Vertex AI\n", - "* Text-to-Speech\n", - "* Cloud Storage\n", - "\n", - "Learn about [Text-to-Speech pricing](https://cloud.google.com/text-to-speech/pricing),\n", - "and [Cloud Storage pricing](https://cloud.google.com/storage/pricing),\n", - "and use the [Pricing Calculator](https://cloud.google.com/products/calculator/)\n", - "to generate a cost estimate based on your projected usage." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "i7EUnXsZhAGF" - }, - "source": [ - "## Getting Started\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "NNSWiCNPjh_p" - }, - "source": [ - "### Install Vertex AI SDK, other packages and their dependencies\n", - "\n", - "Install the following packages required to execute this notebook." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "2b4ef9b72d43" - }, - "outputs": [], - "source": [ - "%pip install --user --upgrade -q google-cloud-aiplatform google-cloud-texttospeech pydub pandas tqdm" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "J3a6juReciKR" - }, - "source": [ - "If you're running on a Mac, you will need to install [FFmpeg](https://ffmpeg.org/)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "BzCUF4oqciKR" - }, - "outputs": [], - "source": [ - "import platform\n", - "\n", - "# Check if the system is macOS\n", - "if platform.system() == \"Darwin\":\n", - " # Install using Homebrew\n", - " !brew install ffmpeg" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "gbWwuHK8j1xm" - }, - "source": [ - "### Run the following cell to restart the kernel." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "f200f10a1da3" - }, - "outputs": [], - "source": [ - "# Automatically restart kernel after installs so that your environment can access the new packages\n", - "import IPython\n", - "\n", - "app = IPython.Application.instance()\n", - "app.kernel.do_shutdown(True)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "GTdx_NRxkD5M" - }, - "source": [ - "
\n", - "⚠️ The kernel is going to restart. Please wait until it is finished before continuing to the next step. ⚠️\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "YbMFqPZ3tnwz" - }, - "source": [ - "Set the project and region.\n", - "\n", - "* Please note the **available regions** for Text-to-Speech, see [documentation](https://cloud.google.com/text-to-speech/docs/endpoints)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "GjSsu6cmUdEx" - }, - "outputs": [], - "source": [ - "PROJECT_ID = \"YOUR_PROJECT_ID\" # @param {type:\"string\"}\n", - "\n", - "TTS_LOCATION = \"us\" # @param {type:\"string\"}\n", - "VERTEXAI_LOCATION = \"us-central1\" # @param {type:\"string\"}" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "opUxT_k5TdgP" - }, - "source": [ - "### Authenticating your notebook environment\n", - "\n", - "* If you are using **Colab** to run this notebook, run the cell below and continue.\n", - "* If you are using **Vertex AI Workbench**, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "vbNgv4q1T2Mi" - }, - "outputs": [], - "source": [ - "import sys\n", - "\n", - "# Additional authentication is required for Google Colab\n", - "if \"google.colab\" in sys.modules:\n", - " # Authenticate user to Google Cloud\n", - " from google.colab import auth\n", - "\n", - " auth.authenticate_user()\n", - "\n", - "! gcloud config set project {PROJECT_ID}\n", - "! gcloud auth application-default set-quota-project {PROJECT_ID}\n", - "! gcloud auth application-default login -q" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "c93f8e645f6e" - }, - "source": [ - "Initialize the [Vertex AI SDK](https://cloud.google.com/vertex-ai/docs/python-sdk/use-vertex-ai-python-sdk)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "baf18b29f8a8" - }, - "outputs": [], - "source": [ - "import vertexai\n", - "\n", - "# Initialize Vertex AI\n", - "vertexai.init(project=PROJECT_ID, location=VERTEXAI_LOCATION)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "960505627ddf" - }, - "source": [ - "### Import libraries" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "PyQmSRbKA8r-" - }, - "outputs": [], - "source": [ - "import json\n", - "import os\n", - "import random\n", - "import re\n", - "\n", - "from IPython.display import Audio\n", - "from google.api_core.client_options import ClientOptions\n", - "from google.cloud import texttospeech_v1beta1 as texttospeech\n", - "import pandas as pd\n", - "from pydub import AudioSegment\n", - "from tqdm import tqdm\n", - "from vertexai.generative_models import GenerationConfig, GenerativeModel" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "v4gUI8WqciKS" - }, - "source": [ - "### Define constants" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "6Pl3un_YciKS" - }, - "outputs": [], - "source": [ - "DEFAULT_LANGUAGE = \"en\"\n", - "NARRATOR_VOICE = \"en-GB-Studio-B\"\n", - "DEFAULT_VOICE = \"en-GB-Neural2-B\"\n", - "\n", - "SILENCE_LENGTH = 200 # In Milliseconds\n", - "TXT_EXTENSION = \".txt\"\n", - "\n", - "tts_client = texttospeech.TextToSpeechClient(\n", - " client_options=ClientOptions(\n", - " api_endpoint=f\"{TTS_LOCATION}-texttospeech.googleapis.com\"\n", - " )\n", - ")\n", - "\n", - "SYSTEM_INSTRUCTION = \"\"\"You are a creative and ambitious play writer. Your goal is to write a play for audio performance. Include a narrator character to describe the scenes and actions occurring.\"\"\"\n", - "\n", - "model = GenerativeModel(\n", - " \"gemini-1.5-pro\",\n", - " system_instruction=SYSTEM_INSTRUCTION,\n", - " generation_config=GenerationConfig(\n", - " max_output_tokens=8192,\n", - " temperature=1,\n", - " top_p=0.95,\n", - " response_mime_type=\"application/json\",\n", - " response_schema={\n", - " \"type\": \"OBJECT\",\n", - " \"properties\": {\n", - " \"title\": {\"type\": \"STRING\", \"description\": \"The title of the story\"},\n", - " \"characters\": {\n", - " \"type\": \"ARRAY\",\n", - " \"items\": {\n", - " \"type\": \"OBJECT\",\n", - " \"properties\": {\n", - " \"name\": {\n", - " \"type\": \"STRING\",\n", - " \"description\": \"The name of the character\",\n", - " },\n", - " \"gender\": {\n", - " \"type\": \"STRING\",\n", - " \"description\": \"The gender of the character\",\n", - " },\n", - " },\n", - " \"required\": [\"name\", \"gender\"],\n", - " },\n", - " },\n", - " \"scenes\": {\n", - " \"type\": \"ARRAY\",\n", - " \"items\": {\n", - " \"type\": \"OBJECT\",\n", - " \"properties\": {\n", - " \"setting\": {\n", - " \"type\": \"STRING\",\n", - " \"description\": \"The setting of the scene\",\n", - " },\n", - " \"dialogue\": {\n", - " \"type\": \"ARRAY\",\n", - " \"items\": {\n", - " \"type\": \"OBJECT\",\n", - " \"properties\": {\n", - " \"speaker\": {\n", - " \"type\": \"STRING\",\n", - " \"description\": \"The speaker of the line\",\n", - " },\n", - " \"line\": {\n", - " \"type\": \"STRING\",\n", - " \"description\": \"The line spoken by the speaker\",\n", - " },\n", - " },\n", - " \"required\": [\"speaker\", \"line\"],\n", - " },\n", - " },\n", - " },\n", - " \"required\": [\"setting\", \"dialogue\"],\n", - " },\n", - " },\n", - " },\n", - " \"required\": [\"title\", \"characters\", \"scenes\"],\n", - " },\n", - " ),\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "v5CEc4-Wrjk2" - }, - "source": [ - "### Helper functions" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "kYx2wwhjrmD6" - }, - "outputs": [], - "source": [ - "def list_voices(language_code: str = DEFAULT_LANGUAGE) -> list[dict]:\n", - " response = tts_client.list_voices(language_code=language_code)\n", - "\n", - " return [\n", - " {\n", - " \"name\": voice.name,\n", - " \"gender\": texttospeech.SsmlVoiceGender(voice.ssml_gender).name.lower(),\n", - " }\n", - " for voice in response.voices\n", - " if (\"News\" in voice.name or \"Studio\" in voice.name or \"Casual\" in voice.name)\n", - " and voice.name != NARRATOR_VOICE\n", - " and \"en-IN\" not in voice.name\n", - " ]\n", - "\n", - "\n", - "def create_character_map(\n", - " characters: list[dict[str, str]], voices: list[dict]\n", - ") -> dict[str, str]:\n", - " \"\"\"Maps characters to voices based on gender identified by Gemini.\"\"\"\n", - "\n", - " if len(characters) > len(voices):\n", - " print(f\"Too many characters {len(characters)}. Max {len(voices)}\")\n", - "\n", - " character_map: dict[str, str] = {}\n", - " male_voices = [voice[\"name\"] for voice in voices if voice[\"gender\"] == \"male\"]\n", - " female_voices = [voice[\"name\"] for voice in voices if voice[\"gender\"] == \"female\"]\n", - "\n", - " for character in characters:\n", - " name = character[\"name\"]\n", - " gender = character[\"gender\"].lower()\n", - "\n", - " if name == \"Narrator\":\n", - " voice = NARRATOR_VOICE\n", - " elif gender == \"female\" and female_voices:\n", - " voice = female_voices.pop(random.randrange(len(female_voices)))\n", - " elif gender == \"male\" and male_voices:\n", - " voice = male_voices.pop(random.randrange(len(male_voices)))\n", - " else:\n", - " if male_voices and female_voices:\n", - " chosen_pool = random.choice([male_voices, female_voices])\n", - " elif male_voices:\n", - " chosen_pool = male_voices\n", - " elif female_voices:\n", - " chosen_pool = female_voices\n", - " else:\n", - " raise ValueError(\"Not enough voices to assign to all characters.\")\n", - "\n", - " voice = chosen_pool.pop(random.randrange(len(chosen_pool)))\n", - "\n", - " character_map[name] = voice\n", - "\n", - " return character_map\n", - "\n", - "\n", - "def synthesize_text(\n", - " file_prefix: str, file_index: str, text: str, voice_name: str\n", - ") -> str:\n", - " output_file = f\"{file_prefix}-{file_index}.mp3\"\n", - "\n", - " language_code = re.search(r\"\\b[a-z]{2}-[A-Z]{2}\\b\", voice_name).group()\n", - "\n", - " response = tts_client.synthesize_speech(\n", - " input=texttospeech.SynthesisInput(text=text),\n", - " voice=texttospeech.VoiceSelectionParams(\n", - " language_code=language_code,\n", - " name=voice_name,\n", - " ),\n", - " audio_config=texttospeech.AudioConfig(\n", - " audio_encoding=texttospeech.AudioEncoding.MP3\n", - " ),\n", - " )\n", - "\n", - " # The response's audio_content is binary.\n", - " with open(output_file, \"wb\") as f:\n", - " f.write(response.audio_content)\n", - " return output_file\n", - "\n", - "\n", - "def combine_audio_files(audio_files: list[str], file_prefix: str) -> str:\n", - " full_audio = AudioSegment.silent(duration=SILENCE_LENGTH)\n", - "\n", - " for file in audio_files:\n", - " sound = AudioSegment.from_mp3(file)\n", - " silence = AudioSegment.silent(duration=SILENCE_LENGTH)\n", - " full_audio += sound + silence\n", - " os.remove(file)\n", - "\n", - " outfile_name = f\"{file_prefix}-complete.mp3\"\n", - " full_audio.export(outfile_name, format=\"mp3\")\n", - " return outfile_name\n", - "\n", - "\n", - "def generate_audio_clips(\n", - " play_object: dict, character_map: dict[str, str]\n", - ") -> tuple[list[str], str]:\n", - " file_prefix = re.sub(r\"[^\\w.-]\", \"_\", play_object[\"title\"]).lower()\n", - " output_files: list[str] = []\n", - "\n", - " lines: list[dict] = [\n", - " {\n", - " \"line\": play_object[\"title\"],\n", - " \"voice\": character_map.get(\"Narrator\", NARRATOR_VOICE),\n", - " }\n", - " ]\n", - "\n", - " # Process each scene in the play\n", - " for scene in play_object[\"scenes\"]:\n", - " # Add the scene setting with the Narrator's voice\n", - " lines.append(\n", - " {\n", - " \"line\": \"Setting... \" + scene[\"setting\"],\n", - " \"voice\": character_map.get(\"Narrator\", NARRATOR_VOICE),\n", - " }\n", - " )\n", - "\n", - " # Process each dialogue in the scene\n", - " for dialogue in scene[\"dialogue\"]:\n", - " lines.append(\n", - " {\n", - " \"line\": dialogue[\"line\"],\n", - " \"voice\": character_map.get(dialogue[\"speaker\"], DEFAULT_VOICE),\n", - " }\n", - " )\n", - "\n", - " for file_index, line in tqdm(enumerate(lines, start=1), \"Generating audio clips\"):\n", - " output_files.append(\n", - " synthesize_text(file_prefix, file_index, line[\"line\"], line[\"voice\"])\n", - " )\n", - "\n", - " return output_files, file_prefix" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "4fa56795fdeb" - }, - "source": [ - "## Generate play with Gemini" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "476afe69c41f" - }, - "outputs": [], - "source": [ - "PROMPT = \"\"\"Write an interesting and humorous version of the play Macbeth by William Shakespeare.\"\"\"\n", - "\n", - "response = model.generate_content(PROMPT)\n", - "play_object = json.loads(response.text)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ed3f9e28f5a9" - }, - "source": [ - "Alternatively, load a pre-generated play." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "c3f5cac8983e" - }, - "outputs": [], - "source": [ - "with open(\"macbeth_the_sitcom.json\") as f:\n", - " play_object = json.loads(f.read())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "4e67586ace6c" - }, - "outputs": [], - "source": [ - "play_object" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "F4NR_30rfuhA" - }, - "source": [ - "## Get available English voices" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "0KqGXuRVuBDf" - }, - "outputs": [], - "source": [ - "all_voices = list_voices()\n", - "print(pd.DataFrame(all_voices))" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "LKMhnJ6mf6bb" - }, - "source": [ - "## Assign voices to characters" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "otMX_-lfgIG1" - }, - "outputs": [], - "source": [ - "character_to_voice = create_character_map(play_object[\"characters\"], all_voices)\n", - "character_to_voice" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "p-laS59bgKo5" - }, - "source": [ - "## Send play text to Text-to-Speech and output each line as an audio file\n", - "\n", - "The Text-to-Speech API can only create audio with one voice per API call, so we need to create separate files for each line." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "L6rYY43xgLwh" - }, - "outputs": [], - "source": [ - "output_files, file_prefix = generate_audio_clips(play_object, character_to_voice)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "5tAMk2RbgO-C" - }, - "source": [ - "## Combine audio files into a single file\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "xl0ZnHStgRg3" - }, - "outputs": [], - "source": [ - "outfile_name = combine_audio_files(output_files, file_prefix)\n", - "print(f\"Audio content written to file {outfile_name}\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ce553e1efe43" - }, - "source": [ - "## Listen to the audio" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "d_ax6LxzciKT" - }, - "outputs": [], - "source": [ - "Audio(outfile_name)" - ] - } - ], - "metadata": { - "colab": { - "name": "storytelling.ipynb", - "toc_visible": true - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - } - }, - "nbformat": 4, - "nbformat_minor": 0 + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ur8xi4C7S06n" + }, + "outputs": [], + "source": [ + "# Copyright 2024 Google LLC\n", + "#\n", + "# 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": "JAPoU8Sm5E6e" + }, + "source": [ + "# Narrate a Multi-character Story with Gemini and Text-to-Speech\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \"Google
Run in Colab\n", + "
\n", + "
\n", + " \n", + " \"Google
Run in Colab Enterprise\n", + "
\n", + "
\n", + " \n", + " \"Vertex
Open in Vertex AI Workbench\n", + "
\n", + "
\n", + " \n", + " \"GitHub
View on GitHub\n", + "
\n", + "
\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "42cc0c827290" + }, + "source": [ + "| | |\n", + "|-|-|\n", + "| Author(s) | [Holt Skinner](https://github.com/holtskinner) |" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tvgnzT1CKxrO" + }, + "source": [ + "## Overview\n", + "\n", + "This notebook demonstrates how to use the [Gemini API in Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/overview) to generate a play script and create an audio performance with each character having a distinct voice using the [Text-to-Speech API](https://cloud.google.com/text-to-speech).\n", + "\n", + "The steps performed include:\n", + "\n", + "- Create a story using Gemini\n", + "- Assign each character to a voice.\n", + "- Synthesize each line based on character voice.\n", + "- Combine audio files into one MP3 file." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "aed92deeb4a0" + }, + "source": [ + "### Costs\n", + "\n", + "This tutorial uses billable components of Google Cloud:\n", + "\n", + "* Gemini API in Vertex AI\n", + "* Text-to-Speech\n", + "* Cloud Storage\n", + "\n", + "Learn about [Text-to-Speech pricing](https://cloud.google.com/text-to-speech/pricing),\n", + "and [Cloud Storage pricing](https://cloud.google.com/storage/pricing),\n", + "and use the [Pricing Calculator](https://cloud.google.com/products/calculator/)\n", + "to generate a cost estimate based on your projected usage." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "i7EUnXsZhAGF" + }, + "source": [ + "## Getting Started\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NNSWiCNPjh_p" + }, + "source": [ + "### Install Vertex AI SDK, other packages and their dependencies\n", + "\n", + "Install the following packages required to execute this notebook." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "2b4ef9b72d43" + }, + "outputs": [], + "source": [ + "%pip install --user --upgrade -q google-cloud-aiplatform google-cloud-texttospeech pydub pandas tqdm" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "J3a6juReciKR" + }, + "source": [ + "If you're running on a Mac, you will need to install [FFmpeg](https://ffmpeg.org/)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "BzCUF4oqciKR" + }, + "outputs": [], + "source": [ + "import platform\n", + "\n", + "# Check if the system is macOS\n", + "if platform.system() == \"Darwin\":\n", + " # Install using Homebrew\n", + " !brew install ffmpeg" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gbWwuHK8j1xm" + }, + "source": [ + "### Run the following cell to restart the kernel." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "f200f10a1da3" + }, + "outputs": [], + "source": [ + "# Automatically restart kernel after installs so that your environment can access the new packages\n", + "import IPython\n", + "\n", + "app = IPython.Application.instance()\n", + "app.kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "GTdx_NRxkD5M" + }, + "source": [ + "
\n", + "⚠️ The kernel is going to restart. Please wait until it is finished before continuing to the next step. ⚠️\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YbMFqPZ3tnwz" + }, + "source": [ + "Set the project and region.\n", + "\n", + "* Please note the **available regions** for Text-to-Speech, see [documentation](https://cloud.google.com/text-to-speech/docs/endpoints)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "GjSsu6cmUdEx" + }, + "outputs": [], + "source": [ + "PROJECT_ID = \"YOUR_PROJECT_ID\" # @param {type:\"string\"}\n", + "\n", + "TTS_LOCATION = \"us\" # @param {type:\"string\"}\n", + "VERTEXAI_LOCATION = \"us-central1\" # @param {type:\"string\"}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "opUxT_k5TdgP" + }, + "source": [ + "### Authenticating your notebook environment\n", + "\n", + "* If you are using **Colab** to run this notebook, run the cell below and continue.\n", + "* If you are using **Vertex AI Workbench**, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "vbNgv4q1T2Mi" + }, + "outputs": [], + "source": [ + "import sys\n", + "\n", + "# Additional authentication is required for Google Colab\n", + "if \"google.colab\" in sys.modules:\n", + " # Authenticate user to Google Cloud\n", + " from google.colab import auth\n", + "\n", + " auth.authenticate_user()\n", + "\n", + "! gcloud config set project {PROJECT_ID}\n", + "! gcloud auth application-default set-quota-project {PROJECT_ID}\n", + "! gcloud auth application-default login -q" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "c93f8e645f6e" + }, + "source": [ + "Initialize the [Vertex AI SDK](https://cloud.google.com/vertex-ai/docs/python-sdk/use-vertex-ai-python-sdk)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "baf18b29f8a8" + }, + "outputs": [], + "source": [ + "import vertexai\n", + "\n", + "# Initialize Vertex AI\n", + "vertexai.init(project=PROJECT_ID, location=VERTEXAI_LOCATION)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "960505627ddf" + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "PyQmSRbKA8r-" + }, + "outputs": [], + "source": [ + "import json\n", + "import os\n", + "import random\n", + "import re\n", + "\n", + "from IPython.display import Audio\n", + "from google.api_core.client_options import ClientOptions\n", + "from google.cloud import texttospeech_v1beta1 as texttospeech\n", + "import pandas as pd\n", + "from pydub import AudioSegment\n", + "from tqdm import tqdm\n", + "from vertexai.generative_models import GenerationConfig, GenerativeModel" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "v4gUI8WqciKS" + }, + "source": [ + "### Define constants" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "6Pl3un_YciKS" + }, + "outputs": [], + "source": [ + "DEFAULT_LANGUAGE = \"en\"\n", + "NARRATOR_VOICE = \"en-GB-Studio-B\"\n", + "DEFAULT_VOICE = \"en-GB-Neural2-B\"\n", + "\n", + "SILENCE_LENGTH = 200 # In Milliseconds\n", + "TXT_EXTENSION = \".txt\"\n", + "\n", + "tts_client = texttospeech.TextToSpeechClient(\n", + " client_options=ClientOptions(\n", + " api_endpoint=f\"{TTS_LOCATION}-texttospeech.googleapis.com\"\n", + " )\n", + ")\n", + "\n", + "SYSTEM_INSTRUCTION = \"\"\"You are a creative and ambitious play writer. Your goal is to write a play for audio performance. Include a narrator character to describe the scenes and actions occurring.\"\"\"\n", + "\n", + "model = GenerativeModel(\n", + " \"gemini-1.5-pro\",\n", + " system_instruction=SYSTEM_INSTRUCTION,\n", + " generation_config=GenerationConfig(\n", + " max_output_tokens=8192,\n", + " temperature=1,\n", + " top_p=0.95,\n", + " response_mime_type=\"application/json\",\n", + " response_schema={\n", + " \"type\": \"OBJECT\",\n", + " \"properties\": {\n", + " \"title\": {\"type\": \"STRING\", \"description\": \"The title of the story\"},\n", + " \"characters\": {\n", + " \"type\": \"ARRAY\",\n", + " \"items\": {\n", + " \"type\": \"OBJECT\",\n", + " \"properties\": {\n", + " \"name\": {\n", + " \"type\": \"STRING\",\n", + " \"description\": \"The name of the character\",\n", + " },\n", + " \"gender\": {\n", + " \"type\": \"STRING\",\n", + " \"description\": \"The gender of the character\",\n", + " },\n", + " },\n", + " \"required\": [\"name\", \"gender\"],\n", + " },\n", + " },\n", + " \"scenes\": {\n", + " \"type\": \"ARRAY\",\n", + " \"items\": {\n", + " \"type\": \"OBJECT\",\n", + " \"properties\": {\n", + " \"setting\": {\n", + " \"type\": \"STRING\",\n", + " \"description\": \"The setting of the scene\",\n", + " },\n", + " \"dialogue\": {\n", + " \"type\": \"ARRAY\",\n", + " \"items\": {\n", + " \"type\": \"OBJECT\",\n", + " \"properties\": {\n", + " \"speaker\": {\n", + " \"type\": \"STRING\",\n", + " \"description\": \"The speaker of the line\",\n", + " },\n", + " \"line\": {\n", + " \"type\": \"STRING\",\n", + " \"description\": \"The line spoken by the speaker\",\n", + " },\n", + " },\n", + " \"required\": [\"speaker\", \"line\"],\n", + " },\n", + " },\n", + " },\n", + " \"required\": [\"setting\", \"dialogue\"],\n", + " },\n", + " },\n", + " },\n", + " \"required\": [\"title\", \"characters\", \"scenes\"],\n", + " },\n", + " ),\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "v5CEc4-Wrjk2" + }, + "source": [ + "### Helper functions" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "kYx2wwhjrmD6" + }, + "outputs": [], + "source": [ + "def list_voices(language_code: str = DEFAULT_LANGUAGE) -> list[dict]:\n", + " response = tts_client.list_voices(language_code=language_code)\n", + "\n", + " return [\n", + " {\n", + " \"name\": voice.name,\n", + " \"gender\": texttospeech.SsmlVoiceGender(voice.ssml_gender).name.lower(),\n", + " }\n", + " for voice in response.voices\n", + " if (\"News\" in voice.name or \"Studio\" in voice.name or \"Casual\" in voice.name)\n", + " and voice.name != NARRATOR_VOICE\n", + " and \"en-IN\" not in voice.name\n", + " ]\n", + "\n", + "\n", + "def create_character_map(\n", + " characters: list[dict[str, str]], voices: list[dict]\n", + ") -> dict[str, str]:\n", + " \"\"\"Maps characters to voices based on gender identified by Gemini.\"\"\"\n", + "\n", + " if len(characters) > len(voices):\n", + " print(f\"Too many characters {len(characters)}. Max {len(voices)}\")\n", + "\n", + " character_map: dict[str, str] = {}\n", + " male_voices = [voice[\"name\"] for voice in voices if voice[\"gender\"] == \"male\"]\n", + " female_voices = [voice[\"name\"] for voice in voices if voice[\"gender\"] == \"female\"]\n", + "\n", + " for character in characters:\n", + " name = character[\"name\"]\n", + " gender = character[\"gender\"].lower()\n", + "\n", + " if name == \"Narrator\":\n", + " voice = NARRATOR_VOICE\n", + " elif gender == \"female\" and female_voices:\n", + " voice = female_voices.pop(random.randrange(len(female_voices)))\n", + " elif gender == \"male\" and male_voices:\n", + " voice = male_voices.pop(random.randrange(len(male_voices)))\n", + " else:\n", + " if male_voices and female_voices:\n", + " chosen_pool = random.choice([male_voices, female_voices])\n", + " elif male_voices:\n", + " chosen_pool = male_voices\n", + " elif female_voices:\n", + " chosen_pool = female_voices\n", + " else:\n", + " raise ValueError(\"Not enough voices to assign to all characters.\")\n", + "\n", + " voice = chosen_pool.pop(random.randrange(len(chosen_pool)))\n", + "\n", + " character_map[name] = voice\n", + "\n", + " return character_map\n", + "\n", + "\n", + "def synthesize_text(\n", + " file_prefix: str, file_index: str, text: str, voice_name: str\n", + ") -> str:\n", + " output_file = f\"{file_prefix}-{file_index}.mp3\"\n", + "\n", + " language_code = re.search(r\"\\b[a-z]{2}-[A-Z]{2}\\b\", voice_name).group()\n", + "\n", + " response = tts_client.synthesize_speech(\n", + " input=texttospeech.SynthesisInput(text=text),\n", + " voice=texttospeech.VoiceSelectionParams(\n", + " language_code=language_code,\n", + " name=voice_name,\n", + " ),\n", + " audio_config=texttospeech.AudioConfig(\n", + " audio_encoding=texttospeech.AudioEncoding.MP3\n", + " ),\n", + " )\n", + "\n", + " # The response's audio_content is binary.\n", + " with open(output_file, \"wb\") as f:\n", + " f.write(response.audio_content)\n", + " return output_file\n", + "\n", + "\n", + "def combine_audio_files(audio_files: list[str], file_prefix: str) -> str:\n", + " full_audio = AudioSegment.silent(duration=SILENCE_LENGTH)\n", + "\n", + " for file in audio_files:\n", + " sound = AudioSegment.from_mp3(file)\n", + " silence = AudioSegment.silent(duration=SILENCE_LENGTH)\n", + " full_audio += sound + silence\n", + " os.remove(file)\n", + "\n", + " outfile_name = f\"{file_prefix}-complete.mp3\"\n", + " full_audio.export(outfile_name, format=\"mp3\")\n", + " return outfile_name\n", + "\n", + "\n", + "def generate_audio_clips(\n", + " play_object: dict, character_map: dict[str, str]\n", + ") -> tuple[list[str], str]:\n", + " file_prefix = re.sub(r\"[^\\w.-]\", \"_\", play_object[\"title\"]).lower()\n", + " output_files: list[str] = []\n", + "\n", + " lines: list[dict] = [\n", + " {\n", + " \"line\": play_object[\"title\"],\n", + " \"voice\": character_map.get(\"Narrator\", NARRATOR_VOICE),\n", + " }\n", + " ]\n", + "\n", + " # Process each scene in the play\n", + " for scene in play_object[\"scenes\"]:\n", + " # Add the scene setting with the Narrator's voice\n", + " lines.append(\n", + " {\n", + " \"line\": \"Setting... \" + scene[\"setting\"],\n", + " \"voice\": character_map.get(\"Narrator\", NARRATOR_VOICE),\n", + " }\n", + " )\n", + "\n", + " # Process each dialogue in the scene\n", + " for dialogue in scene[\"dialogue\"]:\n", + " lines.append(\n", + " {\n", + " \"line\": dialogue[\"line\"],\n", + " \"voice\": character_map.get(dialogue[\"speaker\"], DEFAULT_VOICE),\n", + " }\n", + " )\n", + "\n", + " for file_index, line in tqdm(enumerate(lines, start=1), \"Generating audio clips\"):\n", + " output_files.append(\n", + " synthesize_text(file_prefix, file_index, line[\"line\"], line[\"voice\"])\n", + " )\n", + "\n", + " return output_files, file_prefix" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4fa56795fdeb" + }, + "source": [ + "## Generate play with Gemini" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "476afe69c41f" + }, + "outputs": [], + "source": [ + "PROMPT = \"\"\"Write an interesting and humorous version of the play Macbeth by William Shakespeare.\"\"\"\n", + "\n", + "response = model.generate_content(PROMPT)\n", + "play_object = json.loads(response.text)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ed3f9e28f5a9" + }, + "source": [ + "Alternatively, load a pre-generated play." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "c3f5cac8983e" + }, + "outputs": [], + "source": [ + "with open(\"macbeth_the_sitcom.json\") as f:\n", + " play_object = json.loads(f.read())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "4e67586ace6c" + }, + "outputs": [], + "source": [ + "play_object" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "F4NR_30rfuhA" + }, + "source": [ + "## Get available English voices" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "0KqGXuRVuBDf" + }, + "outputs": [], + "source": [ + "all_voices = list_voices()\n", + "print(pd.DataFrame(all_voices))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LKMhnJ6mf6bb" + }, + "source": [ + "## Assign voices to characters" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "otMX_-lfgIG1" + }, + "outputs": [], + "source": [ + "character_to_voice = create_character_map(play_object[\"characters\"], all_voices)\n", + "character_to_voice" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "p-laS59bgKo5" + }, + "source": [ + "## Send play text to Text-to-Speech and output each line as an audio file\n", + "\n", + "The Text-to-Speech API can only create audio with one voice per API call, so we need to create separate files for each line." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "L6rYY43xgLwh" + }, + "outputs": [], + "source": [ + "output_files, file_prefix = generate_audio_clips(play_object, character_to_voice)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5tAMk2RbgO-C" + }, + "source": [ + "## Combine audio files into a single file\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "xl0ZnHStgRg3" + }, + "outputs": [], + "source": [ + "outfile_name = combine_audio_files(output_files, file_prefix)\n", + "print(f\"Audio content written to file {outfile_name}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ce553e1efe43" + }, + "source": [ + "## Listen to the audio" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "d_ax6LxzciKT" + }, + "outputs": [], + "source": [ + "Audio(outfile_name)" + ] + } + ], + "metadata": { + "colab": { + "name": "storytelling.ipynb", + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 } diff --git a/conversation/data-store-status-checker/data_store_checker.ipynb b/conversation/data-store-status-checker/data_store_checker.ipynb index 77a45911a01..f136c62c8fa 100644 --- a/conversation/data-store-status-checker/data_store_checker.ipynb +++ b/conversation/data-store-status-checker/data_store_checker.ipynb @@ -30,6 +30,31 @@ " \n", " \n", "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n", + "\n", "


\n", "\n", "## What is a Data Store?\n", @@ -47,7 +72,7 @@ "\n", "## Limitations\n", "\n", - "This notebook cannot be used for `Search` applications that use standard website indexing.\n" + "This notebook cannot be used for `Search` applications that use standard website indexing." ] }, { diff --git a/embeddings/embedding-similarity-visualization.ipynb b/embeddings/embedding-similarity-visualization.ipynb index fa04f6c317a..632dcb6c565 100644 --- a/embeddings/embedding-similarity-visualization.ipynb +++ b/embeddings/embedding-similarity-visualization.ipynb @@ -47,7 +47,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/embeddings/hybrid-search.ipynb b/embeddings/hybrid-search.ipynb index 1b743483606..f14e942b7fb 100644 --- a/embeddings/hybrid-search.ipynb +++ b/embeddings/hybrid-search.ipynb @@ -79,7 +79,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/embeddings/intro-textemb-vectorsearch.ipynb b/embeddings/intro-textemb-vectorsearch.ipynb index 3e7d56bc594..386f4370a64 100644 --- a/embeddings/intro-textemb-vectorsearch.ipynb +++ b/embeddings/intro-textemb-vectorsearch.ipynb @@ -58,7 +58,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/embeddings/intro_embeddings_tuning.ipynb b/embeddings/intro_embeddings_tuning.ipynb index 9f506ce1a4a..a0daa944d88 100644 --- a/embeddings/intro_embeddings_tuning.ipynb +++ b/embeddings/intro_embeddings_tuning.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/embeddings/intro_multimodal_embeddings.ipynb b/embeddings/intro_multimodal_embeddings.ipynb index 975111865da..7a625ee5b5e 100644 --- a/embeddings/intro_multimodal_embeddings.ipynb +++ b/embeddings/intro_multimodal_embeddings.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/embeddings/task-type-embedding.ipynb b/embeddings/task-type-embedding.ipynb index 327c523204c..1f84eae1f91 100644 --- a/embeddings/task-type-embedding.ipynb +++ b/embeddings/task-type-embedding.ipynb @@ -62,7 +62,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/embeddings/use-cases/outlier-detection/bq-vector-search-outlier-detection-audit-logs.ipynb b/embeddings/use-cases/outlier-detection/bq-vector-search-outlier-detection-audit-logs.ipynb index 4c5ff257572..220e4bb838e 100644 --- a/embeddings/use-cases/outlier-detection/bq-vector-search-outlier-detection-audit-logs.ipynb +++ b/embeddings/use-cases/outlier-detection/bq-vector-search-outlier-detection-audit-logs.ipynb @@ -58,7 +58,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/embeddings/use-cases/outlier-detection/bq-vector-search-outlier-detection-infra-logs.ipynb b/embeddings/use-cases/outlier-detection/bq-vector-search-outlier-detection-infra-logs.ipynb index 6c42578206a..24d76985da1 100644 --- a/embeddings/use-cases/outlier-detection/bq-vector-search-outlier-detection-infra-logs.ipynb +++ b/embeddings/use-cases/outlier-detection/bq-vector-search-outlier-detection-infra-logs.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/embeddings/vector-search-quickstart.ipynb b/embeddings/vector-search-quickstart.ipynb index e1d3dd4a6aa..e7327ffdd81 100644 --- a/embeddings/vector-search-quickstart.ipynb +++ b/embeddings/vector-search-quickstart.ipynb @@ -47,7 +47,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/batch-prediction/intro_batch_prediction.ipynb b/gemini/batch-prediction/intro_batch_prediction.ipynb index a4150b6dbe5..11fcdfd504f 100644 --- a/gemini/batch-prediction/intro_batch_prediction.ipynb +++ b/gemini/batch-prediction/intro_batch_prediction.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/batch-prediction/intro_batch_prediction_using_bigquery_input.ipynb b/gemini/batch-prediction/intro_batch_prediction_using_bigquery_input.ipynb index d79f7402a2f..17f5563483f 100644 --- a/gemini/batch-prediction/intro_batch_prediction_using_bigquery_input.ipynb +++ b/gemini/batch-prediction/intro_batch_prediction_using_bigquery_input.ipynb @@ -58,7 +58,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/chat-completions/intro_chat_completions_api.ipynb b/gemini/chat-completions/intro_chat_completions_api.ipynb index e2f668e02ca..7479baa586b 100644 --- a/gemini/chat-completions/intro_chat_completions_api.ipynb +++ b/gemini/chat-completions/intro_chat_completions_api.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/context-caching/intro_context_caching.ipynb b/gemini/context-caching/intro_context_caching.ipynb index cd51a919c68..c0820c754ce 100644 --- a/gemini/context-caching/intro_context_caching.ipynb +++ b/gemini/context-caching/intro_context_caching.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/controlled-generation/intro_controlled_generation.ipynb b/gemini/controlled-generation/intro_controlled_generation.ipynb index caade0c7685..64c9e26323a 100644 --- a/gemini/controlled-generation/intro_controlled_generation.ipynb +++ b/gemini/controlled-generation/intro_controlled_generation.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/bring_your_own_autorater_with_custom_metric.ipynb b/gemini/evaluation/bring_your_own_autorater_with_custom_metric.ipynb index 3c701cd2a28..a0c1e032d0e 100644 --- a/gemini/evaluation/bring_your_own_autorater_with_custom_metric.ipynb +++ b/gemini/evaluation/bring_your_own_autorater_with_custom_metric.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/bring_your_own_computation_based_metric.ipynb b/gemini/evaluation/bring_your_own_computation_based_metric.ipynb index 43dbdfafe04..1b1e70dbcec 100644 --- a/gemini/evaluation/bring_your_own_computation_based_metric.ipynb +++ b/gemini/evaluation/bring_your_own_computation_based_metric.ipynb @@ -54,7 +54,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/compare_and_migrate_from_palm_to_gemini.ipynb b/gemini/evaluation/compare_and_migrate_from_palm_to_gemini.ipynb index 9b73c1ad8f6..c399abbcf73 100644 --- a/gemini/evaluation/compare_and_migrate_from_palm_to_gemini.ipynb +++ b/gemini/evaluation/compare_and_migrate_from_palm_to_gemini.ipynb @@ -54,7 +54,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/compare_generative_ai_models.ipynb b/gemini/evaluation/compare_generative_ai_models.ipynb index 524332bfd5a..e5bf52ce2dc 100644 --- a/gemini/evaluation/compare_generative_ai_models.ipynb +++ b/gemini/evaluation/compare_generative_ai_models.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/customize_model_based_metrics.ipynb b/gemini/evaluation/customize_model_based_metrics.ipynb index ea61e5744db..fc741089047 100644 --- a/gemini/evaluation/customize_model_based_metrics.ipynb +++ b/gemini/evaluation/customize_model_based_metrics.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/enhancing_quality_and_explainability_with_eval.ipynb b/gemini/evaluation/enhancing_quality_and_explainability_with_eval.ipynb index df3db4c7cc0..6efd4c89006 100644 --- a/gemini/evaluation/enhancing_quality_and_explainability_with_eval.ipynb +++ b/gemini/evaluation/enhancing_quality_and_explainability_with_eval.ipynb @@ -53,7 +53,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/evaluate_and_compare_gemini_model_settings.ipynb b/gemini/evaluation/evaluate_and_compare_gemini_model_settings.ipynb index 1b70aa61598..b84df68bfce 100644 --- a/gemini/evaluation/evaluate_and_compare_gemini_model_settings.ipynb +++ b/gemini/evaluation/evaluate_and_compare_gemini_model_settings.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/evaluate_gemini_tool_use.ipynb b/gemini/evaluation/evaluate_gemini_tool_use.ipynb index be9070722c6..a938f645df1 100644 --- a/gemini/evaluation/evaluate_gemini_tool_use.ipynb +++ b/gemini/evaluation/evaluate_gemini_tool_use.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/evaluate_langchain_chains.ipynb b/gemini/evaluation/evaluate_langchain_chains.ipynb index d7f66535054..5b9a2dac7a6 100644 --- a/gemini/evaluation/evaluate_langchain_chains.ipynb +++ b/gemini/evaluation/evaluate_langchain_chains.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { 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 a482c30eebf..a3be634bd86 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 @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/evaluate_multimodal_task_image.ipynb b/gemini/evaluation/evaluate_multimodal_task_image.ipynb index f2923eadf8f..c7db2b28ba6 100644 --- a/gemini/evaluation/evaluate_multimodal_task_image.ipynb +++ b/gemini/evaluation/evaluate_multimodal_task_image.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/evaluate_rag_gen_ai_evaluation_service_sdk.ipynb b/gemini/evaluation/evaluate_rag_gen_ai_evaluation_service_sdk.ipynb index 4e9237b399e..2c6c7d3eb69 100644 --- a/gemini/evaluation/evaluate_rag_gen_ai_evaluation_service_sdk.ipynb +++ b/gemini/evaluation/evaluate_rag_gen_ai_evaluation_service_sdk.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/evaluating_prompts_at_scale_with_gemini_batch_prediction_api.ipynb b/gemini/evaluation/evaluating_prompts_at_scale_with_gemini_batch_prediction_api.ipynb index a93cf1fe9fb..31bc5939d02 100644 --- a/gemini/evaluation/evaluating_prompts_at_scale_with_gemini_batch_prediction_api.ipynb +++ b/gemini/evaluation/evaluating_prompts_at_scale_with_gemini_batch_prediction_api.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/intro_to_gen_ai_evaluation_service_sdk.ipynb b/gemini/evaluation/intro_to_gen_ai_evaluation_service_sdk.ipynb index df9748e262e..9015ed1118f 100644 --- a/gemini/evaluation/intro_to_gen_ai_evaluation_service_sdk.ipynb +++ b/gemini/evaluation/intro_to_gen_ai_evaluation_service_sdk.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/legacy/evaluate_gemini_with_autosxs.ipynb b/gemini/evaluation/legacy/evaluate_gemini_with_autosxs.ipynb index 9524f16195d..6a854ce722c 100644 --- a/gemini/evaluation/legacy/evaluate_gemini_with_autosxs.ipynb +++ b/gemini/evaluation/legacy/evaluate_gemini_with_autosxs.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { @@ -424,10 +448,10 @@ "source": [ "import pprint\n", "\n", - "import pandas as pd\n", + "from IPython.display import HTML, display\n", "from google.cloud import aiplatform\n", "from google.protobuf.json_format import MessageToDict\n", - "from IPython.display import HTML, display" + "import pandas as pd" ] }, { diff --git a/gemini/evaluation/legacy/evaluate_gemini_with_autosxs_custom_task.ipynb b/gemini/evaluation/legacy/evaluate_gemini_with_autosxs_custom_task.ipynb index 8f07d358c33..3a931798552 100644 --- a/gemini/evaluation/legacy/evaluate_gemini_with_autosxs_custom_task.ipynb +++ b/gemini/evaluation/legacy/evaluate_gemini_with_autosxs_custom_task.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/legacy/get_started_with_genai_model_eval_service.ipynb b/gemini/evaluation/legacy/get_started_with_genai_model_eval_service.ipynb index 24f812ea186..d216fc1daf1 100644 --- a/gemini/evaluation/legacy/get_started_with_genai_model_eval_service.ipynb +++ b/gemini/evaluation/legacy/get_started_with_genai_model_eval_service.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/legacy/metrics_based_gemini_evaluation.ipynb b/gemini/evaluation/legacy/metrics_based_gemini_evaluation.ipynb index 667e30f0d16..e8eb7534ed4 100644 --- a/gemini/evaluation/legacy/metrics_based_gemini_evaluation.ipynb +++ b/gemini/evaluation/legacy/metrics_based_gemini_evaluation.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/migration_guide_preview_to_GA_sdk.ipynb b/gemini/evaluation/migration_guide_preview_to_GA_sdk.ipynb index 4870655a3a7..f8b825185e3 100644 --- a/gemini/evaluation/migration_guide_preview_to_GA_sdk.ipynb +++ b/gemini/evaluation/migration_guide_preview_to_GA_sdk.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/evaluation/prompt_engineering_gen_ai_evaluation_service_sdk.ipynb b/gemini/evaluation/prompt_engineering_gen_ai_evaluation_service_sdk.ipynb index 0d8a5eb969c..7521909ef0b 100644 --- a/gemini/evaluation/prompt_engineering_gen_ai_evaluation_service_sdk.ipynb +++ b/gemini/evaluation/prompt_engineering_gen_ai_evaluation_service_sdk.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/function-calling/forced_function_calling.ipynb b/gemini/function-calling/forced_function_calling.ipynb index 1d3b83c1ac5..31f5be9087f 100644 --- a/gemini/function-calling/forced_function_calling.ipynb +++ b/gemini/function-calling/forced_function_calling.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/function-calling/function_calling_data_structures.ipynb b/gemini/function-calling/function_calling_data_structures.ipynb index b9b2484e0b9..18514dce464 100644 --- a/gemini/function-calling/function_calling_data_structures.ipynb +++ b/gemini/function-calling/function_calling_data_structures.ipynb @@ -1,816 +1,827 @@ { - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "ijGzTHJJUCPY" - }, - "outputs": [], - "source": [ - "# Copyright 2024 Google LLC\n", - "#\n", - "# 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": "VEqbX8OhE8y9" - }, - "source": [ - "# Working with Data Structures and Schemas in Gemini Function Calling\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - "
\n", - " \n", - " \"Google
Open in Colab\n", - "
\n", - "
\n", - " \n", - " \"Google
Open in Colab Enterprise\n", - "
\n", - "
\n", - " \n", - " \"Vertex
Open in Workbench\n", - "
\n", - "
\n", - " \n", - " \"GitHub
View on GitHub\n", - "
\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ZNJC1SkrsJY3" - }, - "source": [ - "| | |\n", - "|-|-|\n", - "|Author(s) | [Kristopher Overholt](https://github.com/koverholt) |" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "CkHPv2myT2cx" - }, - "source": [ - "## Overview\n", - "\n", - "Gemini is a family of generative AI models developed by Google DeepMind that is designed for multimodal use cases. The Gemini API gives you access to the Gemini Pro and Gemini Pro Vision models.\n", - "\n", - "[Function Calling](https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/function-calling) in Gemini lets you create a description of a function in your code, then pass that description to a language model in a request. The response from the model includes the name of a function that matches the description and the arguments to call it with.\n", - "\n", - "In this tutorial, you'll learn how to work with various data structures within Gemini Function Calling, including:\n", - " \n", - "- Single parameter\n", - "- Multiple parameters\n", - "- Lists of parameters\n", - "- Nested parameters and data structures" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "r11Gu7qNgx1p" - }, - "source": [ - "## Getting Started\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "No17Cw5hgx12" - }, - "source": [ - "### Install Vertex AI SDK and other required packages" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "id": "tFy3H3aPgx12" - }, - "outputs": [], - "source": [ - "%pip install --upgrade --user --quiet google-cloud-aiplatform" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "R5Xep4W9lq-Z" - }, - "source": [ - "### Restart runtime\n", - "\n", - "To use the newly installed packages in this Jupyter runtime, you must restart the runtime. You can do this by running the cell below, which restarts the current kernel.\n", - "\n", - "The restart might take a minute or longer. After it's restarted, continue to the next step." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "id": "XRvKdaPDTznN" - }, - "outputs": [], - "source": [ - "import IPython\n", - "\n", - "app = IPython.Application.instance()\n", - "app.kernel.do_shutdown(True)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "SbmM4z7FOBpM" - }, - "source": [ - "
\n", - "⚠️ The kernel is going to restart. Please wait until it is finished before continuing to the next step. ⚠️\n", - "
\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "dmWOrTJ3gx13" - }, - "source": [ - "### Authenticate your notebook environment (Colab only)\n", - "\n", - "If you are running this notebook on Google Colab, run the cell below to authenticate your environment." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "id": "NyKGtVQjgx13" - }, - "outputs": [], - "source": [ - "import sys\n", - "\n", - "if \"google.colab\" in sys.modules:\n", - " from google.colab import auth\n", - "\n", - " auth.authenticate_user()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "DF4l8DTdWgPY" - }, - "source": [ - "### Set Google Cloud project information and initialize Vertex AI SDK\n", - "\n", - "To get started using Vertex AI, you must have an existing Google Cloud project and [enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n", - "\n", - "Learn more about [setting up a project and a development environment](https://cloud.google.com/vertex-ai/docs/start/cloud-environment)." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "id": "Nqwi-5ufWp_B" - }, - "outputs": [], - "source": [ - "PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n", - "LOCATION = \"us-central1\" # @param {type:\"string\"}\n", - "\n", - "import vertexai\n", - "\n", - "vertexai.init(project=PROJECT_ID, location=LOCATION)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "jXHfaVS66_01" - }, - "source": [ - "## Code Examples\n", - "\n", - "### Import libraries" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "id": "lslYAvw37JGQ" - }, - "outputs": [], - "source": [ - "from vertexai.generative_models import (\n", - " FunctionDeclaration,\n", - " GenerationConfig,\n", - " GenerativeModel,\n", - " Tool,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "Bfy0nopcsJY5" - }, - "source": [ - "### Initialize model\n" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "id": "hvQy2EObsJY5" - }, - "outputs": [], - "source": [ - "model = GenerativeModel(\n", - " \"gemini-1.5-pro\",\n", - " generation_config=GenerationConfig(temperature=0),\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "j3KHAr6BsJY6" - }, - "source": [ - "### Example: Single parameter\n", - "\n", - "Let's say that you want to extract a location from a prompt to help a user navigate to their desired destination.\n", - "\n", - "You can build out a simple schema for a function that takes a single parameter as an input:" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": { - "id": "ElbXcrGWsJY6" - }, - "outputs": [], - "source": [ - "get_destination = FunctionDeclaration(\n", - " name=\"get_destination\",\n", - " description=\"Get directions to a destination\",\n", - " parameters={\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"destination\": {\n", - " \"type\": \"string\",\n", - " \"description\": \"Destination that the user wants to go to\",\n", - " },\n", - " },\n", - " },\n", - ")\n", - "\n", - "destination_tool = Tool(\n", - " function_declarations=[get_destination],\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "T_u_cPW7sJY6" - }, - "source": [ - "Now you can send a prompt with a destination, and the model will return structured data with a single key/value pair:" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": { - "id": "aD4UJ6BcsJY6" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "[name: \"get_destination\"\n", - " args {\n", - " fields {\n", - " key: \"destination\"\n", - " value {\n", - " string_value: \"Paris\"\n", - " }\n", - " }\n", - " }]" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "prompt = \"I'd like to travel to Paris\"\n", - "\n", - "response = model.generate_content(\n", - " prompt,\n", - " tools=[destination_tool],\n", - ")\n", - "\n", - "response.candidates[0].function_calls" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "Q7jimk65sJY7" - }, - "source": [ - "### Example: Multiple parameters\n", - "\n", - "What if you want the function call to return more than one parameter?\n", - "\n", - "You can build out a simple schema for a function that takes multiple parameters as an input:" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": { - "id": "OTaA258isJY7" - }, - "outputs": [], - "source": [ - "get_destination_params = FunctionDeclaration(\n", - " name=\"get_destination_params\",\n", - " description=\"Get directions to a destination\",\n", - " parameters={\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"destination\": {\n", - " \"type\": \"string\",\n", - " \"description\": \"Destination that the user wants to go to\",\n", - " },\n", - " \"mode_of_transportation\": {\n", - " \"type\": \"string\",\n", - " \"description\": \"Mode of transportation to use\",\n", - " },\n", - " \"departure_time\": {\n", - " \"type\": \"string\",\n", - " \"description\": \"Time that the user will leave for the destination\",\n", - " },\n", - " },\n", - " },\n", - ")\n", - "\n", - "destination_tool = Tool(\n", - " function_declarations=[get_destination_params],\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "xS-qg3udsJY7" - }, - "source": [ - "Now you can send a prompt with a destination, and the model will return structured data with a single key/value pair:" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": { - "id": "2gm8YuoesJY7" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "[name: \"get_destination_params\"\n", - " args {\n", - " fields {\n", - " key: \"mode_of_transportation\"\n", - " value {\n", - " string_value: \"train\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"destination\"\n", - " value {\n", - " string_value: \"Paris\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"departure_time\"\n", - " value {\n", - " string_value: \"9:00 am\"\n", - " }\n", - " }\n", - " }]" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "prompt = \"I'd like to travel to Paris by train and leave at 9:00 am\"\n", - "\n", - "response = model.generate_content(\n", - " prompt,\n", - " tools=[destination_tool],\n", - ")\n", - "\n", - "response.candidates[0].function_calls" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "y-ZP3TKrsJY7" - }, - "source": [ - "### Example: Lists of parameters\n", - "\n", - "What if you want the function call to return an array or list of parameters within an object?\n", - "\n", - "For example, you might want to call an API to get the geocoded coordinates of several different locations within a single prompt.\n", - "\n", - "In that case, you can build out a schema for a function that takes an array as an input:" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": { - "id": "jGMeCeftsJY7" - }, - "outputs": [], - "source": [ - "get_multiple_location_coordinates = FunctionDeclaration(\n", - " name=\"get_location_coordinates\",\n", - " description=\"Get coordinates of multiple locations\",\n", - " parameters={\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"locations\": {\n", - " \"type\": \"array\",\n", - " \"description\": \"A list of locations\",\n", - " \"items\": {\n", - " \"description\": \"Components of the location\",\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"point_of_interest\": {\n", - " \"type\": \"string\",\n", - " \"description\": \"Name or type of point of interest\",\n", - " },\n", - " \"city\": {\"type\": \"string\", \"description\": \"City\"},\n", - " \"country\": {\"type\": \"string\", \"description\": \"Country\"},\n", - " },\n", - " \"required\": [\n", - " \"point_of_interest\",\n", - " \"city\",\n", - " \"country\",\n", - " ],\n", - " },\n", - " }\n", - " },\n", - " },\n", - ")\n", - "\n", - "geocoding_tool = Tool(\n", - " function_declarations=[get_multiple_location_coordinates],\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "p2X7KXuYsJY8" - }, - "source": [ - "Now we'll send a prompt with a few different locations and points of interest:" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "id": "8YtBm7-XsJY8" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "[name: \"get_location_coordinates\"\n", - " args {\n", - " fields {\n", - " key: \"locations\"\n", - " value {\n", - " list_value {\n", - " values {\n", - " struct_value {\n", - " fields {\n", - " key: \"point_of_interest\"\n", - " value {\n", - " string_value: \"Eiffel Tower\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"country\"\n", - " value {\n", - " string_value: \"France\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"city\"\n", - " value {\n", - " string_value: \"Paris\"\n", - " }\n", - " }\n", - " }\n", - " }\n", - " values {\n", - " struct_value {\n", - " fields {\n", - " key: \"point_of_interest\"\n", - " value {\n", - " string_value: \"Statue of Liberty\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"country\"\n", - " value {\n", - " string_value: \"USA\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"city\"\n", - " value {\n", - " string_value: \"New York\"\n", - " }\n", - " }\n", - " }\n", - " }\n", - " values {\n", - " struct_value {\n", - " fields {\n", - " key: \"point_of_interest\"\n", - " value {\n", - " string_value: \"Great Barrier Reef\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"country\"\n", - " value {\n", - " string_value: \"Australia\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"city\"\n", - " value {\n", - " string_value: \"Port Douglas\"\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }]" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ijGzTHJJUCPY" + }, + "outputs": [], + "source": [ + "# Copyright 2024 Google LLC\n", + "#\n", + "# 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": "VEqbX8OhE8y9" + }, + "source": [ + "# Working with Data Structures and Schemas in Gemini Function Calling\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \"Google
Open in Colab\n", + "
\n", + "
\n", + " \n", + " \"Google
Open in Colab Enterprise\n", + "
\n", + "
\n", + " \n", + " \"Vertex
Open in Workbench\n", + "
\n", + "
\n", + " \n", + " \"GitHub
View on GitHub\n", + "
\n", + "
\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZNJC1SkrsJY3" + }, + "source": [ + "| | |\n", + "|-|-|\n", + "|Author(s) | [Kristopher Overholt](https://github.com/koverholt) |" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "CkHPv2myT2cx" + }, + "source": [ + "## Overview\n", + "\n", + "Gemini is a family of generative AI models developed by Google DeepMind that is designed for multimodal use cases. The Gemini API gives you access to the Gemini Pro and Gemini Pro Vision models.\n", + "\n", + "[Function Calling](https://cloud.google.com/vertex-ai/docs/generative-ai/multimodal/function-calling) in Gemini lets you create a description of a function in your code, then pass that description to a language model in a request. The response from the model includes the name of a function that matches the description and the arguments to call it with.\n", + "\n", + "In this tutorial, you'll learn how to work with various data structures within Gemini Function Calling, including:\n", + " \n", + "- Single parameter\n", + "- Multiple parameters\n", + "- Lists of parameters\n", + "- Nested parameters and data structures" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "r11Gu7qNgx1p" + }, + "source": [ + "## Getting Started\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "No17Cw5hgx12" + }, + "source": [ + "### Install Vertex AI SDK and other required packages" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "tFy3H3aPgx12" + }, + "outputs": [], + "source": [ + "%pip install --upgrade --user --quiet google-cloud-aiplatform" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "R5Xep4W9lq-Z" + }, + "source": [ + "### Restart runtime\n", + "\n", + "To use the newly installed packages in this Jupyter runtime, you must restart the runtime. You can do this by running the cell below, which restarts the current kernel.\n", + "\n", + "The restart might take a minute or longer. After it's restarted, continue to the next step." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "XRvKdaPDTznN" + }, + "outputs": [], + "source": [ + "import IPython\n", + "\n", + "app = IPython.Application.instance()\n", + "app.kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SbmM4z7FOBpM" + }, + "source": [ + "
\n", + "⚠️ The kernel is going to restart. Please wait until it is finished before continuing to the next step. ⚠️\n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dmWOrTJ3gx13" + }, + "source": [ + "### Authenticate your notebook environment (Colab only)\n", + "\n", + "If you are running this notebook on Google Colab, run the cell below to authenticate your environment." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "NyKGtVQjgx13" + }, + "outputs": [], + "source": [ + "import sys\n", + "\n", + "if \"google.colab\" in sys.modules:\n", + " from google.colab import auth\n", + "\n", + " auth.authenticate_user()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DF4l8DTdWgPY" + }, + "source": [ + "### Set Google Cloud project information and initialize Vertex AI SDK\n", + "\n", + "To get started using Vertex AI, you must have an existing Google Cloud project and [enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n", + "\n", + "Learn more about [setting up a project and a development environment](https://cloud.google.com/vertex-ai/docs/start/cloud-environment)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "Nqwi-5ufWp_B" + }, + "outputs": [], + "source": [ + "PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n", + "LOCATION = \"us-central1\" # @param {type:\"string\"}\n", + "\n", + "import vertexai\n", + "\n", + "vertexai.init(project=PROJECT_ID, location=LOCATION)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jXHfaVS66_01" + }, + "source": [ + "## Code Examples\n", + "\n", + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "lslYAvw37JGQ" + }, + "outputs": [], + "source": [ + "from vertexai.generative_models import (\n", + " FunctionDeclaration,\n", + " GenerationConfig,\n", + " GenerativeModel,\n", + " Tool,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Bfy0nopcsJY5" + }, + "source": [ + "### Initialize model\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "hvQy2EObsJY5" + }, + "outputs": [], + "source": [ + "model = GenerativeModel(\n", + " \"gemini-1.5-pro\",\n", + " generation_config=GenerationConfig(temperature=0),\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "j3KHAr6BsJY6" + }, + "source": [ + "### Example: Single parameter\n", + "\n", + "Let's say that you want to extract a location from a prompt to help a user navigate to their desired destination.\n", + "\n", + "You can build out a simple schema for a function that takes a single parameter as an input:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "id": "ElbXcrGWsJY6" + }, + "outputs": [], + "source": [ + "get_destination = FunctionDeclaration(\n", + " name=\"get_destination\",\n", + " description=\"Get directions to a destination\",\n", + " parameters={\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"destination\": {\n", + " \"type\": \"string\",\n", + " \"description\": \"Destination that the user wants to go to\",\n", + " },\n", + " },\n", + " },\n", + ")\n", + "\n", + "destination_tool = Tool(\n", + " function_declarations=[get_destination],\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "T_u_cPW7sJY6" + }, + "source": [ + "Now you can send a prompt with a destination, and the model will return structured data with a single key/value pair:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "aD4UJ6BcsJY6" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[name: \"get_destination\"\n", + " args {\n", + " fields {\n", + " key: \"destination\"\n", + " value {\n", + " string_value: \"Paris\"\n", + " }\n", + " }\n", + " }]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prompt = \"I'd like to travel to Paris\"\n", + "\n", + "response = model.generate_content(\n", + " prompt,\n", + " tools=[destination_tool],\n", + ")\n", + "\n", + "response.candidates[0].function_calls" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Q7jimk65sJY7" + }, + "source": [ + "### Example: Multiple parameters\n", + "\n", + "What if you want the function call to return more than one parameter?\n", + "\n", + "You can build out a simple schema for a function that takes multiple parameters as an input:" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "OTaA258isJY7" + }, + "outputs": [], + "source": [ + "get_destination_params = FunctionDeclaration(\n", + " name=\"get_destination_params\",\n", + " description=\"Get directions to a destination\",\n", + " parameters={\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"destination\": {\n", + " \"type\": \"string\",\n", + " \"description\": \"Destination that the user wants to go to\",\n", + " },\n", + " \"mode_of_transportation\": {\n", + " \"type\": \"string\",\n", + " \"description\": \"Mode of transportation to use\",\n", + " },\n", + " \"departure_time\": {\n", + " \"type\": \"string\",\n", + " \"description\": \"Time that the user will leave for the destination\",\n", + " },\n", + " },\n", + " },\n", + ")\n", + "\n", + "destination_tool = Tool(\n", + " function_declarations=[get_destination_params],\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xS-qg3udsJY7" + }, + "source": [ + "Now you can send a prompt with a destination, and the model will return structured data with a single key/value pair:" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "2gm8YuoesJY7" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[name: \"get_destination_params\"\n", + " args {\n", + " fields {\n", + " key: \"mode_of_transportation\"\n", + " value {\n", + " string_value: \"train\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"destination\"\n", + " value {\n", + " string_value: \"Paris\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"departure_time\"\n", + " value {\n", + " string_value: \"9:00 am\"\n", + " }\n", + " }\n", + " }]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prompt = \"I'd like to travel to Paris by train and leave at 9:00 am\"\n", + "\n", + "response = model.generate_content(\n", + " prompt,\n", + " tools=[destination_tool],\n", + ")\n", + "\n", + "response.candidates[0].function_calls" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "y-ZP3TKrsJY7" + }, + "source": [ + "### Example: Lists of parameters\n", + "\n", + "What if you want the function call to return an array or list of parameters within an object?\n", + "\n", + "For example, you might want to call an API to get the geocoded coordinates of several different locations within a single prompt.\n", + "\n", + "In that case, you can build out a schema for a function that takes an array as an input:" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "jGMeCeftsJY7" + }, + "outputs": [], + "source": [ + "get_multiple_location_coordinates = FunctionDeclaration(\n", + " name=\"get_location_coordinates\",\n", + " description=\"Get coordinates of multiple locations\",\n", + " parameters={\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"locations\": {\n", + " \"type\": \"array\",\n", + " \"description\": \"A list of locations\",\n", + " \"items\": {\n", + " \"description\": \"Components of the location\",\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"point_of_interest\": {\n", + " \"type\": \"string\",\n", + " \"description\": \"Name or type of point of interest\",\n", + " },\n", + " \"city\": {\"type\": \"string\", \"description\": \"City\"},\n", + " \"country\": {\"type\": \"string\", \"description\": \"Country\"},\n", + " },\n", + " \"required\": [\n", + " \"point_of_interest\",\n", + " \"city\",\n", + " \"country\",\n", + " ],\n", + " },\n", + " }\n", + " },\n", + " },\n", + ")\n", + "\n", + "geocoding_tool = Tool(\n", + " function_declarations=[get_multiple_location_coordinates],\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "p2X7KXuYsJY8" + }, + "source": [ + "Now we'll send a prompt with a few different locations and points of interest:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "8YtBm7-XsJY8" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[name: \"get_location_coordinates\"\n", + " args {\n", + " fields {\n", + " key: \"locations\"\n", + " value {\n", + " list_value {\n", + " values {\n", + " struct_value {\n", + " fields {\n", + " key: \"point_of_interest\"\n", + " value {\n", + " string_value: \"Eiffel Tower\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"country\"\n", + " value {\n", + " string_value: \"France\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"city\"\n", + " value {\n", + " string_value: \"Paris\"\n", + " }\n", + " }\n", + " }\n", + " }\n", + " values {\n", + " struct_value {\n", + " fields {\n", + " key: \"point_of_interest\"\n", + " value {\n", + " string_value: \"Statue of Liberty\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"country\"\n", + " value {\n", + " string_value: \"USA\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"city\"\n", + " value {\n", + " string_value: \"New York\"\n", + " }\n", + " }\n", + " }\n", + " }\n", + " values {\n", + " struct_value {\n", + " fields {\n", + " key: \"point_of_interest\"\n", + " value {\n", + " string_value: \"Great Barrier Reef\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"country\"\n", + " value {\n", + " string_value: \"Australia\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"city\"\n", + " value {\n", + " string_value: \"Port Douglas\"\n", + " }\n", + " }\n", + " }\n", + " }\n", + " }\n", + " }\n", + " }\n", + " }]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prompt = \"\"\"\n", + " I'd like to get the coordinates for\n", + " the Eiffel tower in Paris,\n", + " the statue of liberty in New York,\n", + " and Port Douglas near the Great Barrier Reef.\n", + "\"\"\"\n", + "\n", + "response = model.generate_content(\n", + " prompt,\n", + " tools=[geocoding_tool],\n", + ")\n", + "\n", + "response.candidates[0].function_calls" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "D8giW_8OsJY8" + }, + "source": [ + "Note that the generative model populated values for all of the parameters for a given location since all three parameters are required." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jEHIc8x6sJY8" + }, + "source": [ + "### Example: Nested parameters and data structures\n", + "\n", + "What if you want the function call to include nested parameters or other complex data structures?\n", + "\n", + "You might want to send a command to create a product listing based on a few sentences that include the product details.\n", + "\n", + "In that case, you can build out a schema for a function that takes nested data structures as an input:" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "id": "27PuX0-fsJY8" + }, + "outputs": [], + "source": [ + "create_product_listing = FunctionDeclaration(\n", + " name=\"create_product_listing\",\n", + " description=\"Create a product listing using the details provided by the user\",\n", + " parameters={\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"product\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"name\": {\"type\": \"string\"},\n", + " \"brand\": {\"type\": \"string\"},\n", + " \"price\": {\"type\": \"number\"},\n", + " \"category\": {\"type\": \"string\"},\n", + " \"description\": {\"type\": \"string\"},\n", + " \"colors\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"color\": {\"type\": \"number\"},\n", + " },\n", + " },\n", + " },\n", + " }\n", + " },\n", + " },\n", + ")\n", + "\n", + "product_listing_tool = Tool(\n", + " function_declarations=[create_product_listing],\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "k8sKF69fsJY8" + }, + "source": [ + "Now we'll send a prompt with a few different locations and attributes:" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "id": "Pt-i-srosJY8" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[name: \"create_product_listing\"\n", + " args {\n", + " fields {\n", + " key: \"product\"\n", + " value {\n", + " list_value {\n", + " values {\n", + " struct_value {\n", + " fields {\n", + " key: \"price\"\n", + " value {\n", + " string_value: \"$149.99\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"name\"\n", + " value {\n", + " string_value: \"Noise-Canceling Headphones\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"description\"\n", + " value {\n", + " string_value: \"Create a distraction-free environment.\"\n", + " }\n", + " }\n", + " fields {\n", + " key: \"available_colors\"\n", + " value {\n", + " list_value {\n", + " values {\n", + " string_value: \"black\"\n", + " }\n", + " values {\n", + " string_value: \"white\"\n", + " }\n", + " values {\n", + " string_value: \"red\"\n", + " }\n", + " }\n", + " }\n", + " }\n", + " }\n", + " }\n", + " }\n", + " }\n", + " }\n", + " }]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prompt = \"\"\"Create a listing for noise-canceling headphones for $149.99.\n", + "These headphones create a distraction-free environment.\n", + "Available colors include black, white, and red.\"\"\"\n", + "\n", + "response = model.generate_content(\n", + " prompt,\n", + " tools=[product_listing_tool],\n", + ")\n", + "\n", + "response.candidates[0].function_calls" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "GpDvGrmtsJY8" + }, + "source": [ + "And you're done! You successfully generated various types of data structures, including a single parameter, multiple parameters, a list of parameters, and nested parameters. Try another notebook to continue exploring other functionality in the Gemini API!" + ] } - ], - "source": [ - "prompt = \"\"\"\n", - " I'd like to get the coordinates for\n", - " the Eiffel tower in Paris,\n", - " the statue of liberty in New York,\n", - " and Port Douglas near the Great Barrier Reef.\n", - "\"\"\"\n", - "\n", - "response = model.generate_content(\n", - " prompt,\n", - " tools=[geocoding_tool],\n", - ")\n", - "\n", - "response.candidates[0].function_calls" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "D8giW_8OsJY8" - }, - "source": [ - "Note that the generative model populated values for all of the parameters for a given location since all three parameters are required." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "jEHIc8x6sJY8" - }, - "source": [ - "### Example: Nested parameters and data structures\n", - "\n", - "What if you want the function call to include nested parameters or other complex data structures?\n", - "\n", - "You might want to send a command to create a product listing based on a few sentences that include the product details.\n", - "\n", - "In that case, you can build out a schema for a function that takes nested data structures as an input:" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": { - "id": "27PuX0-fsJY8" - }, - "outputs": [], - "source": [ - "create_product_listing = FunctionDeclaration(\n", - " name=\"create_product_listing\",\n", - " description=\"Create a product listing using the details provided by the user\",\n", - " parameters={\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"product\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"name\": {\"type\": \"string\"},\n", - " \"brand\": {\"type\": \"string\"},\n", - " \"price\": {\"type\": \"number\"},\n", - " \"category\": {\"type\": \"string\"},\n", - " \"description\": {\"type\": \"string\"},\n", - " \"colors\": {\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"color\": {\"type\": \"number\"},\n", - " },\n", - " },\n", - " },\n", - " }\n", - " },\n", - " },\n", - ")\n", - "\n", - "product_listing_tool = Tool(\n", - " function_declarations=[create_product_listing],\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "k8sKF69fsJY8" - }, - "source": [ - "Now we'll send a prompt with a few different locations and attributes:" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": { - "id": "Pt-i-srosJY8" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "[name: \"create_product_listing\"\n", - " args {\n", - " fields {\n", - " key: \"product\"\n", - " value {\n", - " list_value {\n", - " values {\n", - " struct_value {\n", - " fields {\n", - " key: \"price\"\n", - " value {\n", - " string_value: \"$149.99\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"name\"\n", - " value {\n", - " string_value: \"Noise-Canceling Headphones\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"description\"\n", - " value {\n", - " string_value: \"Create a distraction-free environment.\"\n", - " }\n", - " }\n", - " fields {\n", - " key: \"available_colors\"\n", - " value {\n", - " list_value {\n", - " values {\n", - " string_value: \"black\"\n", - " }\n", - " values {\n", - " string_value: \"white\"\n", - " }\n", - " values {\n", - " string_value: \"red\"\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }]" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" + ], + "metadata": { + "colab": { + "name": "function_calling_data_structures.ipynb", + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" } - ], - "source": [ - "prompt = \"\"\"Create a listing for noise-canceling headphones for $149.99.\n", - "These headphones create a distraction-free environment.\n", - "Available colors include black, white, and red.\"\"\"\n", - "\n", - "response = model.generate_content(\n", - " prompt,\n", - " tools=[product_listing_tool],\n", - ")\n", - "\n", - "response.candidates[0].function_calls" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "GpDvGrmtsJY8" - }, - "source": [ - "And you're done! You successfully generated various types of data structures, including a single parameter, multiple parameters, a list of parameters, and nested parameters. Try another notebook to continue exploring other functionality in the Gemini API!" - ] - } - ], - "metadata": { - "colab": { - "name": "function_calling_data_structures.ipynb", - "toc_visible": true - }, - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.6" - } - }, - "nbformat": 4, - "nbformat_minor": 4 + "nbformat": 4, + "nbformat_minor": 0 } diff --git a/gemini/function-calling/intro_diy_react_agent.ipynb b/gemini/function-calling/intro_diy_react_agent.ipynb index b021bece36e..f60a4a93144 100644 --- a/gemini/function-calling/intro_diy_react_agent.ipynb +++ b/gemini/function-calling/intro_diy_react_agent.ipynb @@ -53,7 +53,31 @@ " Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/function-calling/intro_function_calling.ipynb b/gemini/function-calling/intro_function_calling.ipynb index 1626c2cb1c5..2f57f03801c 100644 --- a/gemini/function-calling/intro_function_calling.ipynb +++ b/gemini/function-calling/intro_function_calling.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/function-calling/multimodal_function_calling.ipynb b/gemini/function-calling/multimodal_function_calling.ipynb index 316c2e7cc45..82b28269450 100644 --- a/gemini/function-calling/multimodal_function_calling.ipynb +++ b/gemini/function-calling/multimodal_function_calling.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/function-calling/parallel_function_calling.ipynb b/gemini/function-calling/parallel_function_calling.ipynb index 9272095d26d..87438881bf2 100644 --- a/gemini/function-calling/parallel_function_calling.ipynb +++ b/gemini/function-calling/parallel_function_calling.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/function-calling/use_case_company_news_and_insights.ipynb b/gemini/function-calling/use_case_company_news_and_insights.ipynb index c32ef8a7e46..936f491a1b4 100644 --- a/gemini/function-calling/use_case_company_news_and_insights.ipynb +++ b/gemini/function-calling/use_case_company_news_and_insights.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/getting-started/intro_gemini_1_5_flash.ipynb b/gemini/getting-started/intro_gemini_1_5_flash.ipynb index d0b23d0816e..e1614f50843 100644 --- a/gemini/getting-started/intro_gemini_1_5_flash.ipynb +++ b/gemini/getting-started/intro_gemini_1_5_flash.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/getting-started/intro_gemini_1_5_pro.ipynb b/gemini/getting-started/intro_gemini_1_5_pro.ipynb index 14ba6e53f1a..1293b5a3d80 100644 --- a/gemini/getting-started/intro_gemini_1_5_pro.ipynb +++ b/gemini/getting-started/intro_gemini_1_5_pro.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/getting-started/intro_gemini_chat.ipynb b/gemini/getting-started/intro_gemini_chat.ipynb index 6ae2bcad2cc..939f4cea51d 100644 --- a/gemini/getting-started/intro_gemini_chat.ipynb +++ b/gemini/getting-started/intro_gemini_chat.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/getting-started/intro_gemini_curl.ipynb b/gemini/getting-started/intro_gemini_curl.ipynb index 2f40ffacf7e..ee98427c536 100644 --- a/gemini/getting-started/intro_gemini_curl.ipynb +++ b/gemini/getting-started/intro_gemini_curl.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/getting-started/intro_gemini_pro_python.ipynb b/gemini/getting-started/intro_gemini_pro_python.ipynb index e49e0da3f2c..adb32b37685 100644 --- a/gemini/getting-started/intro_gemini_pro_python.ipynb +++ b/gemini/getting-started/intro_gemini_pro_python.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/getting-started/intro_gemini_pro_vision_python.ipynb b/gemini/getting-started/intro_gemini_pro_vision_python.ipynb index 0d1b179c05f..b8ced9ed496 100644 --- a/gemini/getting-started/intro_gemini_pro_vision_python.ipynb +++ b/gemini/getting-started/intro_gemini_pro_vision_python.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/getting-started/intro_gemini_python.ipynb b/gemini/getting-started/intro_gemini_python.ipynb index e9ca7cbb8c2..0397787a957 100644 --- a/gemini/getting-started/intro_gemini_python.ipynb +++ b/gemini/getting-started/intro_gemini_python.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/grounding/intro-grounding-gemini.ipynb b/gemini/grounding/intro-grounding-gemini.ipynb index b8d085682e5..8b8f31cf32b 100644 --- a/gemini/grounding/intro-grounding-gemini.ipynb +++ b/gemini/grounding/intro-grounding-gemini.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/long-context/intro_long_context.ipynb b/gemini/long-context/intro_long_context.ipynb index e93f835a9a2..e0aeb25d62d 100644 --- a/gemini/long-context/intro_long_context.ipynb +++ b/gemini/long-context/intro_long_context.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/orchestration/autogen_gemini.ipynb b/gemini/orchestration/autogen_gemini.ipynb index 1ed5f46ee85..c3de25a50ba 100644 --- a/gemini/orchestration/autogen_gemini.ipynb +++ b/gemini/orchestration/autogen_gemini.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/orchestration/intro_langchain_gemini.ipynb b/gemini/orchestration/intro_langchain_gemini.ipynb index 5ad72cdfa80..77bf5571938 100644 --- a/gemini/orchestration/intro_langchain_gemini.ipynb +++ b/gemini/orchestration/intro_langchain_gemini.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/orchestration/intro_langgraph_gemini.ipynb b/gemini/orchestration/intro_langgraph_gemini.ipynb index 8520986fcd7..3c8bb406da1 100644 --- a/gemini/orchestration/intro_langgraph_gemini.ipynb +++ b/gemini/orchestration/intro_langgraph_gemini.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/orchestration/langgraph_gemini_podcast.ipynb b/gemini/orchestration/langgraph_gemini_podcast.ipynb index dc4289441b5..3f0f436d8e9 100644 --- a/gemini/orchestration/langgraph_gemini_podcast.ipynb +++ b/gemini/orchestration/langgraph_gemini_podcast.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/orchestration/llamaindex_workflows.ipynb b/gemini/orchestration/llamaindex_workflows.ipynb index eff81896d54..3ffb5a2eeea 100644 --- a/gemini/orchestration/llamaindex_workflows.ipynb +++ b/gemini/orchestration/llamaindex_workflows.ipynb @@ -29,7 +29,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/prompts/examples/chain_of_thought_react.ipynb b/gemini/prompts/examples/chain_of_thought_react.ipynb index 0458840ac29..a312f7ee2e4 100644 --- a/gemini/prompts/examples/chain_of_thought_react.ipynb +++ b/gemini/prompts/examples/chain_of_thought_react.ipynb @@ -59,7 +59,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/prompts/examples/ideation.ipynb b/gemini/prompts/examples/ideation.ipynb index a0b6fe48940..16d71ba00ce 100644 --- a/gemini/prompts/examples/ideation.ipynb +++ b/gemini/prompts/examples/ideation.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/prompts/examples/question_answering.ipynb b/gemini/prompts/examples/question_answering.ipynb index f9d18c47358..0c2adab3671 100644 --- a/gemini/prompts/examples/question_answering.ipynb +++ b/gemini/prompts/examples/question_answering.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/prompts/examples/text_classification.ipynb b/gemini/prompts/examples/text_classification.ipynb index 1a9ccad99ec..ccc7c19c4eb 100644 --- a/gemini/prompts/examples/text_classification.ipynb +++ b/gemini/prompts/examples/text_classification.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/prompts/examples/text_extraction.ipynb b/gemini/prompts/examples/text_extraction.ipynb index c4b42d8f321..2d3a09e512b 100644 --- a/gemini/prompts/examples/text_extraction.ipynb +++ b/gemini/prompts/examples/text_extraction.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/prompts/examples/text_summarization.ipynb b/gemini/prompts/examples/text_summarization.ipynb index a4d1ebf86ee..389d77189fc 100644 --- a/gemini/prompts/examples/text_summarization.ipynb +++ b/gemini/prompts/examples/text_summarization.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/prompts/intro_prompt_design.ipynb b/gemini/prompts/intro_prompt_design.ipynb index a42a4323076..83ec7ae7587 100644 --- a/gemini/prompts/intro_prompt_design.ipynb +++ b/gemini/prompts/intro_prompt_design.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk.ipynb b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk.ipynb index 7cf6927405c..827b78a2aaa 100644 --- a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk.ipynb +++ b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk.ipynb @@ -53,6 +53,31 @@ " \n", " \n", "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n", + "\n", " " ] }, diff --git a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_custom_metric.ipynb b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_custom_metric.ipynb index 46b431c3b2e..bb48fe850db 100644 --- a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_custom_metric.ipynb +++ b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_custom_metric.ipynb @@ -53,6 +53,31 @@ " \n", " \n", "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n", + "\n", " " ] }, diff --git a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_tool_calling.ipynb b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_tool_calling.ipynb index 04f4d2843b3..6addb2e99ec 100644 --- a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_tool_calling.ipynb +++ b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_sdk_tool_calling.ipynb @@ -1,1471 +1,1477 @@ { - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "ur8xi4C7S06n" - }, - "outputs": [], - "source": [ - "# Copyright 2024 Google LLC\n", - "#\n", - "# 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": "JAPoU8Sm5E6e" - }, - "source": [ - "# Vertex Prompt Optimizer Notebook SDK (Preview) - Tool usage\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - "
\n", - " \n", - " \"Google
Open in Colab\n", - "
\n", - "
\n", - " \n", - " \"Google
Open in Colab Enterprise\n", - "
\n", - "
\n", - " \n", - " \"Vertex
Open in Vertex AI Workbench\n", - "
\n", - "
\n", - " \n", - " \"GitHub
View on GitHub\n", - "
\n", - "
\n", - " " - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "0ccc35a93b9f" - }, - "source": [ - "| | | |\n", - "|-|-|-|\n", - "| Author | [Ivan Nardini](https://github.com/inardini)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "tvgnzT1CKxrO" - }, - "source": [ - "## I. Overview\n", - "\n", - "When developing Generative AI (Gen AI) applications, prompt engineering poses challenges due to its time-consuming and error-prone nature. Significant effort is involved when crafting and inputting prompts to achieve successful task completion. With the frequent release of foundational models, you face the added burden of migrating working prompts from one model version to another.\n", - "\n", - "Vertex AI prompt optimizer alleviates these challenges by providing an intelligent prompt optimization tool. With this tool you can both translate and optimize system instructions in the prompts and best demonstrations (examples) for prompt templates, which lets you shape LLM responses from any source model to a target Google model.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "4HKyj5KwYePX" - }, - "source": [ - "### Objective\n", - "\n", - "This notebook demonstrates how to leverage Vertex AI prompt optimizer to optimize for tool usage with a Gemini model. The goal is to use Vertex AI prompt optimizer to find a new prompt template which improves the model's ability to predict valid tool (function) calls given user's request.\n", - "\n", - "This tutorial uses the following Google Cloud services and resources:\n", - "\n", - "- Generative AI on Vertex AI\n", - "- Vertex AI prompt optimizer\n", - "- Vertex AI Gen AI evaluation\n", - "- Vertex AI Custom job\n", - "\n", - "The steps performed include:\n", - "\n", - "1. Define the prompt template you want to optimize.\n", - "2. Prepare the prompt optimization dataset.\n", - "3. Configure tool function settings and validate them.\n", - "4. Set optimization mode and steps.\n", - "5. Run the automatic prompt optimization job.\n", - "6. Collect the best prompt template and eval metric.\n", - "7. Validate the best prompt template." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "08d289fa873f" - }, - "source": [ - "### Dataset\n", - "\n", - "The dataset is a question-answering dataset generated by a simple AI financial assistant that provides information about the top 25 Tech companies.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "aed92deeb4a0" - }, - "source": [ - "### Costs\n", - "\n", - "This tutorial uses billable components of Google Cloud:\n", - "\n", - "* Vertex AI\n", - "* Cloud Storage\n", - "\n", - "Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "61RBz8LLbxCR" - }, - "source": [ - "## II. Before you start" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "No17Cw5hgx12" - }, - "source": [ - "### Install Vertex AI SDK for Python and other required packages\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "tFy3H3aPgx12" - }, - "outputs": [], - "source": [ - "%pip install --upgrade --quiet 'google-cloud-aiplatform[evaluation]'\n", - "%pip install --upgrade --quiet 'plotly' 'asyncio' 'tqdm' 'tenacity' 'etils' 'importlib_resources' 'fsspec' 'gcsfs' 'nbformat>=4.2.0' 'jsonschema'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "e55e2195ce2d" - }, - "outputs": [], - "source": [ - "! mkdir -p ./tutorial/utils && wget https://raw.githubusercontent.com/GoogleCloudPlatform/generative-ai/main/gemini/prompts/prompt_optimizer/vapo_lib.py -P ./tutorial/utils" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "R5Xep4W9lq-Z" - }, - "source": [ - "### Restart runtime (Colab only)\n", - "\n", - "To use the newly installed packages, you must restart the runtime on Google Colab." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "XRvKdaPDTznN" - }, - "outputs": [], - "source": [ - "import sys\n", - "\n", - "if \"google.colab\" in sys.modules:\n", - " import IPython\n", - "\n", - " app = IPython.Application.instance()\n", - " app.kernel.do_shutdown(True)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "SbmM4z7FOBpM" - }, - "source": [ - "
\n", - "⚠️ The kernel is going to restart. Wait until it's finished before continuing to the next step. ⚠️\n", - "
\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "dmWOrTJ3gx13" - }, - "source": [ - "### Authenticate your notebook environment (Colab only)\n", - "\n", - "Authenticate your environment on Google Colab.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "NyKGtVQjgx13" - }, - "outputs": [], - "source": [ - "# import sys\n", - "\n", - "# if \"google.colab\" in sys.modules:\n", - "# from google.colab import auth\n", - "\n", - "# auth.authenticate_user()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "DF4l8DTdWgPY" - }, - "source": [ - "### Set Google Cloud project information\n", - "\n", - "To get started using Vertex AI, you must have an existing Google Cloud project and [enable the following APIs](https://console.cloud.google.com/flows/enableapi?apiid=cloudresourcemanager.googleapis.com,aiplatform.googleapis.com,cloudfunctions.googleapis.com,run.googleapis.com).\n", - "\n", - "Learn more about [setting up a project and a development environment](https://cloud.google.com/vertex-ai/docs/start/cloud-environment)." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "WReHDGG5g0XY" - }, - "source": [ - "#### Set your project ID and project number" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "oM1iC_MfAts1" - }, - "outputs": [], - "source": [ - "PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n", - "\n", - "# Set the project id\n", - "! gcloud config set project {PROJECT_ID}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "oZpm-sL8f1z_" - }, - "outputs": [], - "source": [ - "PROJECT_NUMBER = !gcloud projects describe {PROJECT_ID} --format=\"get(projectNumber)\"[0]\n", - "PROJECT_NUMBER = PROJECT_NUMBER[0]" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "region" - }, - "source": [ - "#### Region\n", - "\n", - "You can also change the `REGION` variable used by Vertex AI. Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "I6FmBV2_0fBP" - }, - "outputs": [], - "source": [ - "REGION = \"us-central1\" # @param {type: \"string\"}" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "zgPO1eR3CYjk" - }, - "source": [ - "#### Create a Cloud Storage bucket\n", - "\n", - "Create a storage bucket to store intermediate artifacts such as datasets." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "MzGDU7TWdts_" - }, - "outputs": [], - "source": [ - "BUCKET_NAME = \"your-bucket-name-{PROJECT_ID}-unique\" # @param {type:\"string\"}\n", - "\n", - "BUCKET_URI = f\"gs://{BUCKET_NAME}\" # @param {type:\"string\"}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "NIq7R4HZCfIc" - }, - "outputs": [], - "source": [ - "! gsutil mb -l {REGION} -p {PROJECT_ID} {BUCKET_URI}" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "set_service_account" - }, - "source": [ - "#### Service Account and permissions\n", - "\n", - "Vertex AI Prompt optimizer requires a service account with the following permissions:\n", - "\n", - "- `Vertex AI User` to call Vertex LLM API\n", - "- `Storage Object Admin` to read and write to your GCS bucket.\n", - "\n", - "[Check out the documentation](https://cloud.google.com/iam/docs/manage-access-service-accounts#iam-view-access-sa-gcloud) to learn how to grant those permissions to a single service account.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "fNRKI99_QtGR" - }, - "source": [ - "> If you run following commands using Vertex AI Workbench, please directly run in the terminal.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "ssUJJqXJJHgC" - }, - "outputs": [], - "source": [ - "SERVICE_ACCOUNT = f\"{PROJECT_NUMBER}-compute@developer.gserviceaccount.com\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "wqOHg5aid6HP" - }, - "outputs": [], - "source": [ - "for role in ['aiplatform.user', 'storage.objectAdmin']:\n", - "\n", - " ! gcloud projects add-iam-policy-binding {PROJECT_ID} \\\n", - " --member=serviceAccount:{SERVICE_ACCOUNT} \\\n", - " --role=roles/{role} --condition=None" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "Ek1-iTbPjzdJ" - }, - "source": [ - "### Set workspace\n", - "\n", - "Set a workspace to store prompt optimization results on Cloud Storage bucket." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "joJPc3FmX1fk" - }, - "outputs": [], - "source": [ - "from etils import epath\n", - "\n", - "WORKSPACE_URI = epath.Path(BUCKET_URI) / \"optimization\"\n", - "INPUT_DATA_URI = epath.Path(WORKSPACE_URI) / \"data\"\n", - "\n", - "WORKSPACE_URI.mkdir(parents=True, exist_ok=True)\n", - "INPUT_DATA_URI.mkdir(parents=True, exist_ok=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "960505627ddf" - }, - "source": [ - "### Import libraries" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "PyQmSRbKA8r-" - }, - "outputs": [], - "source": [ - "# Tutorial\n", - "from argparse import Namespace\n", - "import json\n", - "\n", - "# General\n", - "import logging\n", - "from typing import Any\n", - "import warnings\n", - "\n", - "from IPython.display import HTML, display\n", - "from google.cloud import aiplatform\n", - "import pandas as pd\n", - "from sklearn.model_selection import train_test_split\n", - "from tutorial.utils import vapo_lib" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "820DIvw1o8tB" - }, - "source": [ - "### Libraries settings" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "HKc4ZdUBo_SM" - }, - "outputs": [], - "source": [ - "warnings.filterwarnings(\"ignore\")\n", - "logging.getLogger(\"urllib3.connectionpool\").setLevel(logging.ERROR)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "gxc7q4r-DFH4" - }, - "source": [ - "### Define constants" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "0Y5t67f3DHNm" - }, - "outputs": [], - "source": [ - "INPUT_DATA_FILE_URI = (\n", - " \"gs://github-repo/prompts/prompt_optimizer/qa_tool_calls_dataset.jsonl\"\n", - ")\n", - "\n", - "INPUT_OPTIMIZATION_DATA_URI = epath.Path(WORKSPACE_URI) / \"prompt_optimization_data\"\n", - "INPUT_OPTIMIZATION_DATA_FILE_URI = str(\n", - " INPUT_DATA_URI / \"prompt_optimization_dataset.jsonl\"\n", - ")\n", - "OUTPUT_OPTIMIZATION_DATA_URI = epath.Path(WORKSPACE_URI) / \"optimization_jobs\"\n", - "APD_CONTAINER_URI = (\n", - " \"us-docker.pkg.dev/vertex-ai-restricted/builtin-algorithm/apd:preview_v1_0\"\n", - ")\n", - "CONFIG_FILE_URI = str(WORKSPACE_URI / \"config\" / \"config.json\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "eVVkBruaULtp" - }, - "source": [ - "### Set helpers" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "Q_D--hDZUQPx" - }, - "outputs": [], - "source": [ - "def get_company_information_api(content: dict[str, Any]) -> str:\n", - " \"A function to simulate an API call to collect company information.\"\n", - "\n", - " company_overviews = {\n", - " \"AAPL\": \"Apple maintains a robust financial position with substantial cash reserves and consistent profitability, fueled by its strong brand and loyal customer base. However, growth is slowing and the company faces competition.\",\n", - " \"ADBE\": \"Adobe financials are robust, driven by its successful transition to a subscription-based model for its creative and document cloud software. Profitability and revenue growth are strong.\",\n", - " \"AMD\": \"AMD exhibits strong financial performance, gaining market share in the CPU and GPU markets. Revenue growth and profitability are healthy, driven by strong product offerings.\",\n", - " \"AMZN\": \"Amazon financials are mixed, with its e-commerce business facing margin pressure while its cloud computing division (AWS) delivers strong profitability and growth. Its overall revenue remains high but profitability is a concern.\",\n", - " \"ASML\": \"ASML boasts a strong financial position due to its monopoly in the extreme ultraviolet lithography market, essential for advanced semiconductor manufacturing. High profitability and growth are key strengths.\",\n", - " \"AVGO\": \"Broadcom maintains healthy financials, driven by its semiconductor and infrastructure software solutions. Acquisitions have played a role in its growth strategy, with consistent profitability and cash flow.\",\n", - " \"BABA\": \"Alibaba financials are substantial but facing challenges from regulatory scrutiny in China and increased competition. E-commerce revenue remains strong but growth is slowing.\",\n", - " \"BKNG\": \"Booking Holdings financials are closely tied to the travel industry. Revenue growth is recovering post-pandemic but profitability can fluctuate based on global travel trends.\",\n", - " \"CRM\": \"Salesforce shows robust revenue growth from its cloud-based CRM solutions. Profitability is improving but competition remains strong.\",\n", - " \"CSCO\": \"Cisco financials show moderate growth, transitioning from hardware to software and services. Profitability is stable but the company faces competition in the networking market.\",\n", - " \"GOOGL\": \"Alphabet exhibits strong financials driven by advertising revenue, though facing regulatory scrutiny. Diversification into other ventures provides growth opportunities but profitability varies.\",\n", - " \"IBM\": \"IBM financials are in a state of transformation, shifting focus to hybrid cloud and AI. Revenue growth is modest, with profitability impacted by legacy businesses.\",\n", - " \"INTU\": \"Intuit showcases healthy financials, benefiting from its strong position in tax and financial management software. Revenue growth and profitability are consistent, fueled by recurring subscription revenue.\",\n", - " \"META\": \"Meta Platforms financial performance is tied closely to advertising revenue, facing headwinds from competition and changing privacy regulations. Investments in the metaverse represent a long-term, high-risk bet.\",\n", - " \"MSFT\": \"Microsoft demonstrates healthy financials, benefiting from diversified revenue streams including cloud computing (Azure), software, and hardware. The company exhibits consistent growth and profitability.\",\n", - " \"NFLX\": \"Netflix exhibits strong revenue but faces challenges in maintaining subscriber growth and managing content costs. Profitability varies, and competition in the streaming market is intense.\",\n", - " \"NOW\": \"ServiceNow demonstrates strong financials, fueled by its cloud-based workflow automation platform. Revenue growth and profitability are high, reflecting increased enterprise adoption.\",\n", - " \"NVDA\": \"NVIDIA boasts strong financials, driven by its dominance in the GPU market for gaming, AI, and data centers. High revenue growth and profitability are key strengths.\",\n", - " \"ORCL\": \"Oracle financials are in transition, shifting towards cloud-based services. Revenue growth is moderate, and profitability remains stable. Legacy businesses still contribute significantly.\",\n", - " \"QCOM\": \"QUALCOMM financials show strong performance driven by its leadership in mobile chipsets and licensing. Profitability is high, and growth is tied to the mobile market and 5G adoption.\",\n", - " \"SAP\": \"SAP demonstrates steady financials with its enterprise software solutions. Transition to the cloud is ongoing and impacting revenue growth and profitability.\",\n", - " \"SMSN\": \"Samsung financials are diverse, reflecting its presence in various sectors including mobile phones, consumer electronics, and semiconductors. Profitability varies across divisions but the company holds significant cash reserves.\",\n", - " \"TCEHY\": \"Tencent financials are driven by its dominant position in the Chinese gaming and social media market. Revenue growth is strong but regulatory risks in China impact its performance.\",\n", - " \"TSLA\": \"Tesla financials show strong revenue growth driven by electric vehicle demand, but profitability remains volatile due to production and investment costs. The company high valuation reflects market optimism for future growth.\",\n", - " \"TSM\": \"TSMC, a dominant player in semiconductor manufacturing, showcases robust financials fueled by high demand for its advanced chips. Profitability is strong and the company enjoys a technologically advanced position.\",\n", - " }\n", - " return company_overviews.get(content[\"ticker\"], \"No company overwiew found\")\n", - "\n", - "\n", - "def get_stock_price_api(content: dict[str, Any]) -> str:\n", - " \"A function to simulate an API call to collect most recent stock price for a given company.\"\n", - " stock_prices = {\n", - " \"AAPL\": 225,\n", - " \"ADBE\": 503,\n", - " \"AMD\": 134,\n", - " \"AMZN\": 202,\n", - " \"ASML\": 658,\n", - " \"AVGO\": 164,\n", - " \"BABA\": 88,\n", - " \"BKNG\": 4000,\n", - " \"CRM\": 325,\n", - " \"CSCO\": 57,\n", - " \"GOOGL\": 173,\n", - " \"IBM\": 201,\n", - " \"INTU\": 607,\n", - " \"META\": 553,\n", - " \"MSFT\": 415,\n", - " \"NFLX\": 823,\n", - " \"NOW\": 1000,\n", - " \"NVDA\": 141,\n", - " \"ORCL\": 183,\n", - " \"QCOM\": 160,\n", - " \"SAP\": 228,\n", - " \"SMSN\": 38,\n", - " \"TCEHY\": 51,\n", - " \"TSLA\": 302,\n", - " \"TSM\": 186,\n", - " }\n", - " return stock_prices.get(content[\"ticker\"], \"No stock price found\")\n", - "\n", - "\n", - "def get_company_news_api(content: dict[str, Any]) -> str:\n", - " \"A function to simulate an API call to collect recent news for a given company.\"\n", - " news_data = {\n", - " \"AAPL\": \"Apple unveils new iPhone, market reaction muted amid concerns about slowing growth.\",\n", - " \"ADBE\": \"Adobe integrates AI features into Creative Suite, attracting creative professionals.\",\n", - " \"AMD\": \"AMD gains market share in server CPUs, competing with Intel.\",\n", - " \"AMZN\": \"Amazon stock dips after reporting lower-than-expected Q3 profits due to increased shipping costs.\",\n", - " \"ASML\": \"ASML benefits from high demand for advanced chip manufacturing equipment.\",\n", - " \"AVGO\": \"Broadcom announces new acquisition in the semiconductor space.\",\n", - " \"BABA\": \"Alibaba stock faces uncertainty amid ongoing regulatory scrutiny in China.\",\n", - " \"BKNG\": \"Booking Holdings stock recovers as travel demand rebounds post-pandemic.\",\n", - " \"CRM\": \"Salesforce launches new AI-powered CRM tools for enterprise customers.\",\n", - " \"CSCO\": \"Cisco stock rises after positive earnings report, focus on networking solutions.\",\n", - " \"GOOGL\": \"Alphabet announces new AI-powered search features, aiming to compete with Microsoft.\",\n", - " \"IBM\": \"IBM focuses on hybrid cloud solutions, showing steady growth in enterprise segment.\",\n", - " \"INTU\": \"Intuit stock dips after announcing price increases for its tax software.\",\n", - " \"META\": \"Meta shares rise after positive user growth figures in emerging markets.\",\n", - " \"MSFT\": \"Microsoft expands AI integration across its product suite, boosting investor confidence.\",\n", - " \"NFLX\": \"Netflix subscriber growth slows, competition heats up in streaming landscape.\",\n", - " \"NOW\": \"ServiceNow sees strong growth in its cloud-based workflow automation platform.\",\n", - " \"NVDA\": \"Nvidia stock jumps on strong earnings forecast, driven by AI demand.\",\n", - " \"ORCL\": \"Oracle cloud revenue continues strong growth, exceeding market expectations.\",\n", - " \"QCOM\": \"Qualcomm expands its 5G modem business, partnering with major smartphone manufacturers.\",\n", - " \"SAP\": \"SAP cloud transition continues, but faces challenges in attracting new clients.\",\n", - " \"SMSN\": \"Samsung unveils new foldable phones, looking to gain market share.\",\n", - " \"TCEHY\": \"Tencent faces regulatory pressure in China, impacting investor sentiment.\",\n", - " \"TSLA\": \"Tesla stock volatile after price cuts and production increases announced.\",\n", - " \"TSM\": \"TSMC reports record chip demand but warns of potential supply chain disruptions.\",\n", - " }\n", - " return news_data.get(content[\"ticker\"], \"No news available\")\n", - "\n", - "\n", - "def get_company_sentiment_api(content: dict[str, Any]) -> str:\n", - " \"A function to simulate an API call to collect market company sentiment for a given company.\"\n", - "\n", - " company_sentiment = {\n", - " \"AAPL\": \"Neutral\",\n", - " \"ADBE\": \"Neutral\",\n", - " \"AMD\": \"Neutral\",\n", - " \"AMZN\": \"Neutral\",\n", - " \"ASML\": \"Bearish/Undervalued\",\n", - " \"AVGO\": \"Neutral\",\n", - " \"BABA\": \"Neutral\",\n", - " \"BKNG\": \"Neutral\",\n", - " \"CRM\": \"Neutral\",\n", - " \"CSCO\": \"Neutral\",\n", - " \"GOOGL\": \"Neutral\",\n", - " \"IBM\": \"Neutral\",\n", - " \"INTU\": \"Mixed/Bullish\",\n", - " \"META\": \"Neutral\",\n", - " \"MSFT\": \"Neutral\",\n", - " \"NFLX\": \"Neutral\",\n", - " \"NOW\": \"Bullish/Overvalued\",\n", - " \"NVDA\": \"Neutral\",\n", - " \"ORCL\": \"Neutral\",\n", - " \"QCOM\": \"Neutral\",\n", - " \"SAP\": \"Neutral\",\n", - " \"SMSN\": \"Neutral\",\n", - " \"TCEHY\": \"Neutral\",\n", - " \"TSLA\": \"Slightly Overvalued\",\n", - " \"TSM\": \"Neutral\",\n", - " }\n", - " return company_sentiment.get(content[\"ticker\"], \"No sentiment available\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "init_aip:mbsdk,all" - }, - "source": [ - "### Initialize Vertex AI SDK for Python\n", - "\n", - "Initialize the Vertex AI SDK for Python for your project." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "bQMc2Uwf0fBQ" - }, - "outputs": [], - "source": [ - "aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "EdvJRUWRNGHE" - }, - "source": [ - "## III. Automated prompt design with Vertex AI prompt optimizer" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "mmTotjRAJplw" - }, - "source": [ - "### Load the dataset\n", - "\n", - "Load the AI financial assistant's question-answer dataset from a Google Cloud Storage bucket. The dataset contains the following columns:\n", - "\n", - "* **question:** User's query regarding about company.\n", - "* **tool_names:** Specifies tool names used to answer the question.\n", - "* **tool_call:** Details the input parameters passed to the specified tools.\n", - "* **tool_call_response:** Raw output from the tool.\n", - "* **answer:** A refined and human-readable response grounded in the tool's output, answering the user's question." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "LA7aG08wJtVm" - }, - "outputs": [], - "source": [ - "prompt_optimization_df = pd.read_json(INPUT_DATA_FILE_URI, lines=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "1xn-pz3v5HVK" - }, - "outputs": [], - "source": [ - "prompt_optimization_df.head()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "E2l7JwuDcPqX" - }, - "source": [ - "Print an example of the cooking question-answer dataset. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "b8zgOTZVa6xa" - }, - "outputs": [], - "source": [ - "vapo_lib.print_df_rows(prompt_optimization_df, n=1)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "Rp1n1aMACzSW" - }, - "source": [ - "### Optimize the prompt template with Vertex AI prompt optimizer with custom metric\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "h1650lf3X8xW" - }, - "source": [ - "#### Prepare the prompt template you want to optimize\n", - "\n", - "A prompt consists of two key parts:\n", - "\n", - "* **System Instruction Template** which is a fixed part of the prompt that control or alter the model's behavior across all queries for a given task.\n", - "\n", - "* **Prompt Template** which is a dynamic part of the prompt that changes based on the task. Prompt template includes examples, context, task and more. To learn more, see [components of a prompt](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/prompt-design-strategies#components-of-a-prompt) in the official documentation.\n", - "\n", - "In this scenario, you use Vertex AI prompt optimizer to optimize a simple system instruction template.\n", - "\n", - "And you use some examples in the remaining prompt template for evaluating different instruction templates along the optimization process." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "L_vLpXX2HDe1" - }, - "source": [ - "> **Note**: Having the `target` placeholder in the prompt template is optional. It represents the prompt's ground truth response in your prompt optimization dataset that you aim to optimize for your templates. If you don't have the prompt's ground truth response, remember to set the `source_model` parameter to your prompt optimizer configuration (see below) instead of adding ground truth responses. Vertex AI prompt optimizer would run your sample prompts on the source model to generate the ground truth responses for you." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "Db8rHNC6DmtY" - }, - "outputs": [], - "source": [ - "SYSTEM_INSTRUCTION_TEMPLATE = \"\"\"\n", - "Answer the question using correct tools.\n", - "\"\"\"\n", - "\n", - "PROMPT_TEMPLATE = \"\"\"\n", - "Some examples of correct tools associated to a question are:\n", - "Question: {question}\n", - "Target tools: {target}\n", - "\"\"\"" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "a1TCgXsrXztm" - }, - "source": [ - "#### Prepare the prompt optimization dataset\n", - "\n", - "To use Vertex AI prompt optimizer, you'll need a CSV or JSONL file with labeled examples. These examples should follow a specific naming convention. For details see [Optimize prompts](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/prompt-optimizer).\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "SYV-fansHMM_" - }, - "source": [ - "> **Note**: For effective **prompt optimization**, provide a dataset of examples where your model is poor in performance when using current system instruction template. For reliable results, use 50-100 distinct samples.\n", - "\n", - "> In case of **prompt migration**, consider using the source model to label examples that the target model struggles with, helping to identify areas for improvement." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "LBWLrWKil6jK" - }, - "outputs": [], - "source": [ - "train_prompt_optimization_df, test_prompt_optimization_df = train_test_split(\n", - " prompt_optimization_df, test_size=0.3, random_state=8\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "vTIl_v9Ig1F-" - }, - "outputs": [], - "source": [ - "prepared_train_prompt_optimization_df = train_prompt_optimization_df.copy()\n", - "\n", - "# Prepare target column\n", - "prepared_train_prompt_optimization_df[\"target\"] = (\n", - " prepared_train_prompt_optimization_df.apply(vapo_lib.create_target_column, axis=1)\n", - ")\n", - "\n", - "# Remove uneccessary columns\n", - "prepared_train_prompt_optimization_df = prepared_train_prompt_optimization_df.drop(\n", - " columns=[\"tool_names\", \"tool_arguments\", \"tool_call_response\", \"answer\"]\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ZbTqB2o5ZslT" - }, - "source": [ - "Print some examples of the prompt optimization dataset. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "_DUFEAb82eEi" - }, - "outputs": [], - "source": [ - "prepared_train_prompt_optimization_df.head()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "nF3XY_d_yB-K" - }, - "source": [ - "#### Upload samples to bucket\n", - "\n", - "Once you prepare your prompt optimization dataset, you can upload them on Cloud Storage bucket." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "155paLgGUXOm" - }, - "outputs": [], - "source": [ - "prepared_train_prompt_optimization_df.to_json(\n", - " INPUT_OPTIMIZATION_DATA_FILE_URI, orient=\"records\", lines=True\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "82VNGt07_erb" - }, - "source": [ - "#### Configure tool settings and validate them\n", - "\n", - "To optimize prompts for using external tools with the Vertex AI SDK, define the tools' functionalities using the `FunctionDeclaration` class. This class uses an OpenAPI-compatible schema to structure the tool definitions. Your system prompt should be designed to effectively leverage these defined functions. See the [Introduction to function calling](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling) for more information. \n", - "\n", - "Example function definitions for a financial assistant are provided below.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "_gEJ5Dd9rsOX" - }, - "outputs": [], - "source": [ - "get_company_information = FunctionDeclaration(\n", - " name=\"get_company_information\",\n", - " description=\"Retrieves financial performance to provide an overview for a company.\",\n", - " parameters={\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"ticker\": {\n", - " \"type\": \"string\",\n", - " \"description\": \"Stock ticker for a given company\",\n", - " }\n", - " },\n", - " \"required\": [\"ticker\"],\n", - " },\n", - ")\n", - "\n", - "get_stock_price = FunctionDeclaration(\n", - " name=\"get_stock_price\",\n", - " description=\"Only returns the current stock price (in dollars) for a company.\",\n", - " parameters={\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"ticker\": {\n", - " \"type\": \"integer\",\n", - " \"description\": \"Stock ticker for a company\",\n", - " }\n", - " },\n", - " \"required\": [\"ticker\"],\n", - " },\n", - ")\n", - "\n", - "get_company_news = FunctionDeclaration(\n", - " name=\"get_company_news\",\n", - " description=\"Get the latest news headlines for a given company.\",\n", - " parameters={\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"ticker\": {\n", - " \"type\": \"string\",\n", - " \"description\": \"Stock ticker for a company.\",\n", - " }\n", - " },\n", - " \"required\": [\"ticker\"],\n", - " },\n", - ")\n", - "\n", - "get_company_sentiment = FunctionDeclaration(\n", - " name=\"get_company_sentiment\",\n", - " description=\"Returns the overall market sentiment for a company.\",\n", - " parameters={\n", - " \"type\": \"object\",\n", - " \"properties\": {\n", - " \"ticker\": {\n", - " \"type\": \"string\",\n", - " \"description\": \"Stock ticker for a company\",\n", - " },\n", - " },\n", - " \"required\": [\"ticker\"],\n", - " },\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "52T9TTwu4LbW" - }, - "source": [ - "After implementing your functions, wrap each one as a `Tool` object. This allows the Gemini model to discover and execute these functions. `ToolConfig` provides additional parameters to control how the model interacts with the tools and chooses which function to call. \n", - "\n", - "Further information can be found in the [Introduction to function calling](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling).\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "bq9M_-jt4KoB" - }, - "outputs": [], - "source": [ - "tools = Tool(\n", - " function_declarations=[\n", - " get_company_information,\n", - " get_stock_price,\n", - " get_company_news,\n", - " get_company_sentiment,\n", - " ]\n", - ")\n", - "\n", - "tool_config = ToolConfig(\n", - " function_calling_config=ToolConfig.FunctionCallingConfig(\n", - " mode=ToolConfig.FunctionCallingConfig.Mode.ANY,\n", - " allowed_function_names=[\n", - " \"get_company_information\",\n", - " \"get_stock_price\",\n", - " \"get_company_news\",\n", - " \"get_company_sentiment\",\n", - " ],\n", - " )\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "4nMEMYU6sNUA" - }, - "source": [ - "To use Vertex AI Prompt Optimizer for tool calling optimization, provide `FunctionDeclaration` and `ToolConfig` as JSON structures (see example below). Vertex AI Prompt Optimizer uses those structures along the optimization process.\n", - "\n", - "Tool Calls json:\n", - "```\n", - "{\"tools\": [{\"function_declarations\": [{\"name\": \"function_1\", \"description\": \"My function 1\", \"parameters\": {\"type\": \"OBJECT\", \"properties\": {\"argument_1\": {\"type\": \"STRING\", \"description\": \"My argument 1\"}}, \"required\": [\"argument_1\"], \"property_ordering\": [\"argument_1\"]}}, ...]}]}\n", - "```\n", - "Function Calling Configuration json:\n", - "```\n", - "{\"function_calling_config\": {\"mode\": \"your_mode\", \"allowed_function_names\": [\"tool_name_1\", ...]}}\n", - "```\n", - "\n", - "Below you have some helper functions to get those structures and validate them.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "jxHLX921xdHJ" - }, - "outputs": [], - "source": [ - "vapo_tools = json.dumps({\"tools\": [vapo_lib.replace_type_key(tools.to_dict())]})\n", - "\n", - "vapo_tool_config = json.dumps(vapo_lib.tool_config_to_dict(tool_config))\n", - "\n", - "vapo_lib.validate_tools(vapo_tools)\n", - "vapo_lib.validate_tool_config(vapo_tool_config)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "F5RD0l2xX-FI" - }, - "source": [ - "#### Configure optimization settings\n", - "\n", - "Vertex AI prompt optimizer lets you control the optimization process by specifying what to optimize (instructions only, demonstrations only, or both), providing a system instruction and prompt template, and selecting the target model. You can optionally refine the optimization with some advanced settings like its duration and the number of optimization iterations it runs, which models the Vertex AI prompt optimizer uses, and other parameters to control the structure and content of prompts. Below you have some common and recommended default configurations.\n", - "\n", - "In this scenario, you set two additional parameters:\n", - "\n", - "* `tools` parameter to pass tool definitions\n", - "\n", - "* `tool_config` parameter to pass tool configuration\n", - "\n", - "For more advanced control, you can learn and explore more about all the parameters and how to best use them in the [detailed documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/prompt-optimizer).\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "sFHutXhgeqRx" - }, - "outputs": [], - "source": [ - "PROMPT_OPTIMIZATION_JOB = \"auto-prompt-design-job-\" + vapo_lib.get_id()\n", - "OUTPUT_OPTIMIZATION_RUN_URI = str(\n", - " OUTPUT_OPTIMIZATION_DATA_URI / PROMPT_OPTIMIZATION_JOB\n", - ")\n", - "\n", - "args = Namespace(\n", - " # Basic configuration\n", - " system_instruction=SYSTEM_INSTRUCTION_TEMPLATE, # System instructions for the target model. String.\n", - " prompt_template=PROMPT_TEMPLATE, # Template for prompts, String.\n", - " target_model=\"gemini-1.5-flash-001\", # Target model for optimization. String. Supported models: \"gemini-1.5-flash-002\", \"gemini-1.5-pro-002\", \"gemini-1.5-flash-001\", \"gemini-1.5-pro-001\", \"gemini-1.0-pro-001\", \"gemini-1.0-pro-002\", \"gemini-1.0-ultra-001\", \"text-bison@001\", \"text-bison@002\", \"text-bison32k@002\", \"text-unicorn@001\"\n", - " optimization_mode=\"instruction\", # Optimization mode. String. Supported modes: \"instruction\", \"demonstration\", \"instruction_and_demo\"\n", - " tools=vapo_tools,\n", - " tool_config=vapo_tool_config,\n", - " eval_metrics_types=[\n", - " \"tool_name_match\",\n", - " \"tool_parameter_key_match\",\n", - " \"tool_parameter_kv_match\",\n", - " ], # List of evaluation metrics. List of strings. Supported metrics: \"bleu\", \"coherence\", \"exact_match\", \"fluidity\", \"fulfillment\", \"groundedness\", \"rouge_1\", \"rouge_2\", \"rouge_l\", \"rouge_l_sum\", \"safety\", \"question_answering_correctness\", \"question_answering_helpfulness\", \"question_answering_quality\", \"question_answering_relevance\", \"summarization_helpfulness\", \"summarization_quality\", \"summarization_verbosity\", \"tool_name_match\", \"tool_parameter_key_match\", \"tool_parameter_kv_match\"\n", - " eval_metrics_weights=[\n", - " 0.4,\n", - " 0.3,\n", - " 0.3,\n", - " ], # Weights for evaluation metrics. List of floats. Length must match eval_metrics_types. Should sum to 1.\n", - " aggregation_type=\"weighted_sum\", # Aggregation type for evaluation metrics. String. Supported aggregation types: \"weighted_sum\", \"weighted_average\"\n", - " input_data_path=INPUT_OPTIMIZATION_DATA_FILE_URI, # Cloud Storage URI to input optimization data. String.\n", - " output_path=OUTPUT_OPTIMIZATION_RUN_URI, # Cloud Storage URI to save optimization results. String.\n", - " project=PROJECT_ID, # Google Cloud project ID. String.\n", - " # (Optional) Advanced configuration\n", - " num_steps=10, # Number of iterations in instruction optimization mode. Integer between 10 and 20.\n", - " num_template_eval_per_step=2, # Number of system instructions generated and evaluated in instruction and instruction_and_demo mode. Integer between 1 and 4.\n", - " num_demo_set_candidates=10, # Number of demonstrations evaluated in instruction and instruction_and_demo mode. Integer between 10 and 30.\n", - " demo_set_size=3, # Number of demonstrations generated per prompt. Integer between 3 and 6.\n", - " target_model_location=\"us-central1\", # Location of the target model. String. Default us-central1.\n", - " optimizer_model=\"gemini-1.5-pro-001\", # Optimization model. String. Supported models: \"gemini-1.5-flash-002\", \"gemini-1.5-pro-002\", \"gemini-1.5-flash-001\", \"gemini-1.5-pro-001\", \"gemini-1.0-pro-001\", \"gemini-1.0-pro-002\", \"gemini-1.0-ultra-001\", \"text-bison@001\", \"text-bison@002\", \"text-bison32k@002\", \"text-unicorn@001\"\n", - " optimizer_model_location=\"us-central1\", # Location of the optimization model. String. Default us-central1.\n", - " eval_model=\"gemini-1.5-pro-001\", # Evaluation model. String. Supported models: \"gemini-1.5-flash-002\", \"gemini-1.5-pro-002\", \"gemini-1.5-flash-001\", \"gemini-1.5-pro-001\", \"gemini-1.0-pro-001\", \"gemini-1.0-pro-002\", \"gemini-1.0-ultra-001\", \"text-bison@001\", \"text-bison@002\", \"text-bison32k@002\", \"text-unicorn@001\"\n", - " eval_model_location=\"us-central1\", # Location of the evaluation model. String. Default us-central1.\n", - " source_model=\"\", # Google model that the system instructions and prompts were previously used with. String. Not needed if you provide target column.\n", - " source_model_location=\"\", # Location of the source model. String. Default us-central1. Not needed if you provide target column.\n", - " target_model_qps=1, # The queries per second (QPS) sent to the target model. Integer greater or equal than 1 depending on your quota.\n", - " optimizer_model_qps=1, # The queries per second (QPS) sent to the optimization model. Integer greater or equal than 1 depending on your quota.\n", - " eval_qps=1, # The queries per second (QPS) sent to the eval model. Integer greater or equal than 1 depending on your quota.\n", - " source_model_qps=\"\", # The queries per second (QPS) sent to the source model. Integer greater or equal than 1 depending on your quota.\n", - " response_mime_type=\"text/plain\", # MIME response type that the target model uses. String. Supported response: text/plain, application/json.\n", - " response_schema=\"\", # Response schema that the target model uses to generate answers. String.\n", - " language=\"English\", # Language of the system instructions. String. Supported languages: \"English\", \"French\", \"German\", \"Hebrew\", \"Hindi\", \"Japanese\", \"Korean\", \"Portuguese\", \"Simplified Chinese\", \"Spanish\", \"Traditional Chinese\"\n", - " placeholder_to_content=json.loads(\n", - " \"{}\"\n", - " ), # Placeholder to replace any parameter in the system instruction. Dict.\n", - " data_limit=50, # Amount of data used for validation. Integer between 5 and 100.\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "Jd_uzQYQx6L7" - }, - "source": [ - "#### Upload Vertex AI prompt optimizer Cloud Storage\n", - "\n", - "After you define Vertex AI prompt optimizer configuration, you upload them on Cloud Storage bucket.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "iqiv8ApR_SAM" - }, - "outputs": [], - "source": [ - "args = vars(args)\n", - "\n", - "with epath.Path(CONFIG_FILE_URI).open(\"w\") as config_file:\n", - " json.dump(args, config_file)\n", - "config_file.close()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "spqgBT8hYAle" - }, - "source": [ - "#### Run the automatic prompt optimization job\n", - "\n", - "Now you are ready to run your first Vertex AI prompt optimizer job using the Vertex AI SDK for Python." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "RlNQ_UrFH9ne" - }, - "source": [ - "> This prompt optimization job requires ~ 40 minutes to run.\n", - "\n", - "> Be sure you have provisioned enough queries per minute (QPM) quota implementing the recommended QPM for each model. If you configure the Vertex AI prompt optimizer with a QPM that is higher than the QPM than you have access to, the job might fail. [Check out](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/prompt-optimizer#before-you-begin) the documentation to know more.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "GtPnvKIpUQ3q" - }, - "outputs": [], - "source": [ - "WORKER_POOL_SPECS = [\n", - " {\n", - " \"machine_spec\": {\n", - " \"machine_type\": \"n1-standard-4\",\n", - " },\n", - " \"replica_count\": 1,\n", - " \"container_spec\": {\n", - " \"image_uri\": APD_CONTAINER_URI,\n", - " \"args\": [\"--config=\" + CONFIG_FILE_URI],\n", - " },\n", - " }\n", - "]\n", - "\n", - "custom_job = aiplatform.CustomJob(\n", - " display_name=PROMPT_OPTIMIZATION_JOB,\n", - " worker_pool_specs=WORKER_POOL_SPECS,\n", - ")\n", - "\n", - "custom_job.submit(service_account=SERVICE_ACCOUNT)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "3YwwKBhtJ4ut" - }, - "source": [ - "### Collect and display the optimization results\n", - "\n", - "Vertex AI prompt optimizer returns both optimized templates and evaluation results for either instruction, or demostrations, or both depending on the optimization mode you define as JSONL files on Cloud Storage bucket. Those results help you understand the optimization process.\n", - "\n", - "In this case, you want to collect the optimized templates and evaluation results for the system instruction.\n", - "\n", - "Below you use a helper function to display those results." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "-6ohF0LJIhvU" - }, - "outputs": [], - "source": [ - "results_ui = vapo_lib.ResultsUI(OUTPUT_OPTIMIZATION_RUN_URI)\n", - "results_df_html = \"\"\"\n", - "\n", - "\"\"\"\n", - "\n", - "display(HTML(results_df_html))\n", - "display(results_ui.get_container())" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "TrMrbcA5Gzep" - }, - "source": [ - "### Evaluate the quality of generated responses with the optimized instruction\n", - "\n", - "Finally, you evaluate generated responses with the optimized instruction qualitatively.\n", - "\n", - "If you want to know how to evaluate the new generated responses quantitatively, check out the [`vertex_ai_prompt_optimizer_sdk` notebook](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/gemini/prompts/prompt_optimizer) in the official repository.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "DJK4KD0VkSuz" - }, - "source": [ - "#### Generate new responses using the optimized system instruction.\n", - "\n", - "Set the optimized system instruction template you get from Vertex AI prompt optimizer job." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "BVamCk10KYHu" - }, - "outputs": [], - "source": [ - "OPTIMIZED_SYSTEM_INSTRUCTION_TEMPLATE = \"To provide the most accurate response to the given question, determine and employ the most suitable tools.\" # @param {type:\"string\"}" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "1U79bZ_KTM6T" - }, - "source": [ - "Prepare optimized prompts using the optimized system instruction template." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "XfouWkLPkSu1" - }, - "outputs": [], - "source": [ - "OPTIMIZED_PROMPT_TEMPLATE = (\n", - " OPTIMIZED_SYSTEM_INSTRUCTION_TEMPLATE + \"\\nQuestion: \\n{question}\" + \"\\nAnswer:\"\n", - ")\n", - "\n", - "optimized_prompts = [\n", - " OPTIMIZED_PROMPT_TEMPLATE.format(question=q)\n", - " for q in zip(\n", - " test_prompt_optimization_df[\"question\"].to_list(),\n", - " )\n", - "]" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "sofPH74kT165" - }, - "source": [ - "Leverage Gemini API on Vertex AI to send parallel generation requests.\n", - "\n", - "In this scenario, you have to define a function map which allows you to handle function calling in parallel. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "aZfPgrmZ0jub" - }, - "outputs": [], - "source": [ - "function_map = {\n", - " \"get_company_information\": get_company_information_api,\n", - " \"get_stock_price\": get_stock_price_api,\n", - " \"get_company_news\": get_company_news_api,\n", - " \"get_company_sentiment\": get_company_sentiment_api,\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "NM5-8FzpkSu1" - }, - "outputs": [], - "source": [ - "gemini_llm = vapo_lib.init_new_model(model_name=\"gemini-1.5-flash-001\")\n", - "\n", - "gemini_predictions = [\n", - " vapo_lib.async_generate(p, gemini_llm, function_map, tools, tool_config)\n", - " for p in optimized_prompts\n", - "]\n", - "\n", - "gemini_predictions_col = await tqdm_asyncio.gather(*gemini_predictions)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "0BA9wRQnsHg0" - }, - "source": [ - "#### Evaluate new responses" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "SEVi8m4gUMqP" - }, - "source": [ - "Prepare the test dataset and inspect new responses." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "8khmj0oATV7O" - }, - "outputs": [], - "source": [ - "test_prompt_optimization_df[\"optimized_prompt_with_vapo\"] = optimized_prompts\n", - "test_prompt_optimization_df[\"gemini_answer_with_vapo\"] = gemini_predictions_col" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "0s2pAKq4TaiJ" - }, - "outputs": [], - "source": [ - "vapo_lib.print_df_rows(test_prompt_optimization_df, n=1)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "2a4e033321ad" - }, - "source": [ - "## IV. Clean up" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "WRY_3wh1GVNm" - }, - "outputs": [], - "source": [ - "delete_bucket = False\n", - "delete_job = False\n", - "delete_tutorial = False\n", - "\n", - "if delete_bucket:\n", - " ! gsutil rm -r {BUCKET_URI}\n", - "\n", - "if delete_job:\n", - " custom_job.delete()\n", - "\n", - "if delete_tutorial:\n", - " import shutil\n", - "\n", - " shutil.rmtree(str(TUTORIAL_PATH))" - ] - } - ], - "metadata": { - "colab": { - "name": "vertex_ai_prompt_optimizer_sdk_tool_calling.ipynb", - "toc_visible": true - }, - "environment": { - "kernel": "python3", - "name": "tf2-gpu.2-15.m125", - "type": "gcloud", - "uri": "us-docker.pkg.dev/deeplearning-platform-release/gcr.io/tf2-gpu.2-15:m125" - }, - "kernelspec": { - "display_name": "Python 3 (Local)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.15" - } - }, - "nbformat": 4, - "nbformat_minor": 4 + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ur8xi4C7S06n" + }, + "outputs": [], + "source": [ + "# Copyright 2024 Google LLC\n", + "#\n", + "# 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": "JAPoU8Sm5E6e" + }, + "source": [ + "# Vertex Prompt Optimizer Notebook SDK (Preview) - Tool usage\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \"Google
Open in Colab\n", + "
\n", + "
\n", + " \n", + " \"Google
Open in Colab Enterprise\n", + "
\n", + "
\n", + " \n", + " \"Vertex
Open in Vertex AI Workbench\n", + "
\n", + "
\n", + " \n", + " \"GitHub
View on GitHub\n", + "
\n", + "
\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n", + "\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0ccc35a93b9f" + }, + "source": [ + "| | | |\n", + "|-|-|-|\n", + "| Author | [Ivan Nardini](https://github.com/inardini)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tvgnzT1CKxrO" + }, + "source": [ + "## I. Overview\n", + "\n", + "When developing Generative AI (Gen AI) applications, prompt engineering poses challenges due to its time-consuming and error-prone nature. Significant effort is involved when crafting and inputting prompts to achieve successful task completion. With the frequent release of foundational models, you face the added burden of migrating working prompts from one model version to another.\n", + "\n", + "Vertex AI prompt optimizer alleviates these challenges by providing an intelligent prompt optimization tool. With this tool you can both translate and optimize system instructions in the prompts and best demonstrations (examples) for prompt templates, which lets you shape LLM responses from any source model to a target Google model.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4HKyj5KwYePX" + }, + "source": [ + "### Objective\n", + "\n", + "This notebook demonstrates how to leverage Vertex AI prompt optimizer to optimize for tool usage with a Gemini model. The goal is to use Vertex AI prompt optimizer to find a new prompt template which improves the model's ability to predict valid tool (function) calls given user's request.\n", + "\n", + "This tutorial uses the following Google Cloud services and resources:\n", + "\n", + "- Generative AI on Vertex AI\n", + "- Vertex AI prompt optimizer\n", + "- Vertex AI Gen AI evaluation\n", + "- Vertex AI Custom job\n", + "\n", + "The steps performed include:\n", + "\n", + "1. Define the prompt template you want to optimize.\n", + "2. Prepare the prompt optimization dataset.\n", + "3. Configure tool function settings and validate them.\n", + "4. Set optimization mode and steps.\n", + "5. Run the automatic prompt optimization job.\n", + "6. Collect the best prompt template and eval metric.\n", + "7. Validate the best prompt template." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "08d289fa873f" + }, + "source": [ + "### Dataset\n", + "\n", + "The dataset is a question-answering dataset generated by a simple AI financial assistant that provides information about the top 25 Tech companies.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "aed92deeb4a0" + }, + "source": [ + "### Costs\n", + "\n", + "This tutorial uses billable components of Google Cloud:\n", + "\n", + "* Vertex AI\n", + "* Cloud Storage\n", + "\n", + "Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "61RBz8LLbxCR" + }, + "source": [ + "## II. Before you start" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "No17Cw5hgx12" + }, + "source": [ + "### Install Vertex AI SDK for Python and other required packages\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "tFy3H3aPgx12" + }, + "outputs": [], + "source": [ + "%pip install --upgrade --quiet 'google-cloud-aiplatform[evaluation]'\n", + "%pip install --upgrade --quiet 'plotly' 'asyncio' 'tqdm' 'tenacity' 'etils' 'importlib_resources' 'fsspec' 'gcsfs' 'nbformat>=4.2.0' 'jsonschema'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "e55e2195ce2d" + }, + "outputs": [], + "source": [ + "! mkdir -p ./tutorial/utils && wget https://raw.githubusercontent.com/GoogleCloudPlatform/generative-ai/main/gemini/prompts/prompt_optimizer/vapo_lib.py -P ./tutorial/utils" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "R5Xep4W9lq-Z" + }, + "source": [ + "### Restart runtime (Colab only)\n", + "\n", + "To use the newly installed packages, you must restart the runtime on Google Colab." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "XRvKdaPDTznN" + }, + "outputs": [], + "source": [ + "import sys\n", + "\n", + "if \"google.colab\" in sys.modules:\n", + " import IPython\n", + "\n", + " app = IPython.Application.instance()\n", + " app.kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SbmM4z7FOBpM" + }, + "source": [ + "
\n", + "⚠️ The kernel is going to restart. Wait until it's finished before continuing to the next step. ⚠️\n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dmWOrTJ3gx13" + }, + "source": [ + "### Authenticate your notebook environment (Colab only)\n", + "\n", + "Authenticate your environment on Google Colab.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "NyKGtVQjgx13" + }, + "outputs": [], + "source": [ + "# import sys\n", + "\n", + "# if \"google.colab\" in sys.modules:\n", + "# from google.colab import auth\n", + "\n", + "# auth.authenticate_user()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DF4l8DTdWgPY" + }, + "source": [ + "### Set Google Cloud project information\n", + "\n", + "To get started using Vertex AI, you must have an existing Google Cloud project and [enable the following APIs](https://console.cloud.google.com/flows/enableapi?apiid=cloudresourcemanager.googleapis.com,aiplatform.googleapis.com,cloudfunctions.googleapis.com,run.googleapis.com).\n", + "\n", + "Learn more about [setting up a project and a development environment](https://cloud.google.com/vertex-ai/docs/start/cloud-environment)." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WReHDGG5g0XY" + }, + "source": [ + "#### Set your project ID and project number" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "oM1iC_MfAts1" + }, + "outputs": [], + "source": [ + "PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n", + "\n", + "# Set the project id\n", + "! gcloud config set project {PROJECT_ID}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "oZpm-sL8f1z_" + }, + "outputs": [], + "source": [ + "PROJECT_NUMBER = !gcloud projects describe {PROJECT_ID} --format=\"get(projectNumber)\"[0]\n", + "PROJECT_NUMBER = PROJECT_NUMBER[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "region" + }, + "source": [ + "#### Region\n", + "\n", + "You can also change the `REGION` variable used by Vertex AI. Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "I6FmBV2_0fBP" + }, + "outputs": [], + "source": [ + "REGION = \"us-central1\" # @param {type: \"string\"}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "zgPO1eR3CYjk" + }, + "source": [ + "#### Create a Cloud Storage bucket\n", + "\n", + "Create a storage bucket to store intermediate artifacts such as datasets." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "MzGDU7TWdts_" + }, + "outputs": [], + "source": [ + "BUCKET_NAME = \"your-bucket-name-{PROJECT_ID}-unique\" # @param {type:\"string\"}\n", + "\n", + "BUCKET_URI = f\"gs://{BUCKET_NAME}\" # @param {type:\"string\"}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "NIq7R4HZCfIc" + }, + "outputs": [], + "source": [ + "! gsutil mb -l {REGION} -p {PROJECT_ID} {BUCKET_URI}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "set_service_account" + }, + "source": [ + "#### Service Account and permissions\n", + "\n", + "Vertex AI Prompt optimizer requires a service account with the following permissions:\n", + "\n", + "- `Vertex AI User` to call Vertex LLM API\n", + "- `Storage Object Admin` to read and write to your GCS bucket.\n", + "\n", + "[Check out the documentation](https://cloud.google.com/iam/docs/manage-access-service-accounts#iam-view-access-sa-gcloud) to learn how to grant those permissions to a single service account.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fNRKI99_QtGR" + }, + "source": [ + "> If you run following commands using Vertex AI Workbench, please directly run in the terminal.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ssUJJqXJJHgC" + }, + "outputs": [], + "source": [ + "SERVICE_ACCOUNT = f\"{PROJECT_NUMBER}-compute@developer.gserviceaccount.com\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "wqOHg5aid6HP" + }, + "outputs": [], + "source": [ + "for role in ['aiplatform.user', 'storage.objectAdmin']:\n", + "\n", + " ! gcloud projects add-iam-policy-binding {PROJECT_ID} \\\n", + " --member=serviceAccount:{SERVICE_ACCOUNT} \\\n", + " --role=roles/{role} --condition=None" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Ek1-iTbPjzdJ" + }, + "source": [ + "### Set workspace\n", + "\n", + "Set a workspace to store prompt optimization results on Cloud Storage bucket." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "joJPc3FmX1fk" + }, + "outputs": [], + "source": [ + "from etils import epath\n", + "\n", + "WORKSPACE_URI = epath.Path(BUCKET_URI) / \"optimization\"\n", + "INPUT_DATA_URI = epath.Path(WORKSPACE_URI) / \"data\"\n", + "\n", + "WORKSPACE_URI.mkdir(parents=True, exist_ok=True)\n", + "INPUT_DATA_URI.mkdir(parents=True, exist_ok=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "960505627ddf" + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "PyQmSRbKA8r-" + }, + "outputs": [], + "source": [ + "# Tutorial\n", + "from argparse import Namespace\n", + "import json\n", + "\n", + "# General\n", + "import logging\n", + "from typing import Any\n", + "import warnings\n", + "\n", + "from IPython.display import HTML, display\n", + "from google.cloud import aiplatform\n", + "import pandas as pd\n", + "from sklearn.model_selection import train_test_split\n", + "from tutorial.utils import vapo_lib" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "820DIvw1o8tB" + }, + "source": [ + "### Libraries settings" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "HKc4ZdUBo_SM" + }, + "outputs": [], + "source": [ + "warnings.filterwarnings(\"ignore\")\n", + "logging.getLogger(\"urllib3.connectionpool\").setLevel(logging.ERROR)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gxc7q4r-DFH4" + }, + "source": [ + "### Define constants" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "0Y5t67f3DHNm" + }, + "outputs": [], + "source": [ + "INPUT_DATA_FILE_URI = (\n", + " \"gs://github-repo/prompts/prompt_optimizer/qa_tool_calls_dataset.jsonl\"\n", + ")\n", + "\n", + "INPUT_OPTIMIZATION_DATA_URI = epath.Path(WORKSPACE_URI) / \"prompt_optimization_data\"\n", + "INPUT_OPTIMIZATION_DATA_FILE_URI = str(\n", + " INPUT_DATA_URI / \"prompt_optimization_dataset.jsonl\"\n", + ")\n", + "OUTPUT_OPTIMIZATION_DATA_URI = epath.Path(WORKSPACE_URI) / \"optimization_jobs\"\n", + "APD_CONTAINER_URI = (\n", + " \"us-docker.pkg.dev/vertex-ai-restricted/builtin-algorithm/apd:preview_v1_0\"\n", + ")\n", + "CONFIG_FILE_URI = str(WORKSPACE_URI / \"config\" / \"config.json\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "eVVkBruaULtp" + }, + "source": [ + "### Set helpers" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Q_D--hDZUQPx" + }, + "outputs": [], + "source": [ + "def get_company_information_api(content: dict[str, Any]) -> str:\n", + " \"A function to simulate an API call to collect company information.\"\n", + "\n", + " company_overviews = {\n", + " \"AAPL\": \"Apple maintains a robust financial position with substantial cash reserves and consistent profitability, fueled by its strong brand and loyal customer base. However, growth is slowing and the company faces competition.\",\n", + " \"ADBE\": \"Adobe financials are robust, driven by its successful transition to a subscription-based model for its creative and document cloud software. Profitability and revenue growth are strong.\",\n", + " \"AMD\": \"AMD exhibits strong financial performance, gaining market share in the CPU and GPU markets. Revenue growth and profitability are healthy, driven by strong product offerings.\",\n", + " \"AMZN\": \"Amazon financials are mixed, with its e-commerce business facing margin pressure while its cloud computing division (AWS) delivers strong profitability and growth. Its overall revenue remains high but profitability is a concern.\",\n", + " \"ASML\": \"ASML boasts a strong financial position due to its monopoly in the extreme ultraviolet lithography market, essential for advanced semiconductor manufacturing. High profitability and growth are key strengths.\",\n", + " \"AVGO\": \"Broadcom maintains healthy financials, driven by its semiconductor and infrastructure software solutions. Acquisitions have played a role in its growth strategy, with consistent profitability and cash flow.\",\n", + " \"BABA\": \"Alibaba financials are substantial but facing challenges from regulatory scrutiny in China and increased competition. E-commerce revenue remains strong but growth is slowing.\",\n", + " \"BKNG\": \"Booking Holdings financials are closely tied to the travel industry. Revenue growth is recovering post-pandemic but profitability can fluctuate based on global travel trends.\",\n", + " \"CRM\": \"Salesforce shows robust revenue growth from its cloud-based CRM solutions. Profitability is improving but competition remains strong.\",\n", + " \"CSCO\": \"Cisco financials show moderate growth, transitioning from hardware to software and services. Profitability is stable but the company faces competition in the networking market.\",\n", + " \"GOOGL\": \"Alphabet exhibits strong financials driven by advertising revenue, though facing regulatory scrutiny. Diversification into other ventures provides growth opportunities but profitability varies.\",\n", + " \"IBM\": \"IBM financials are in a state of transformation, shifting focus to hybrid cloud and AI. Revenue growth is modest, with profitability impacted by legacy businesses.\",\n", + " \"INTU\": \"Intuit showcases healthy financials, benefiting from its strong position in tax and financial management software. Revenue growth and profitability are consistent, fueled by recurring subscription revenue.\",\n", + " \"META\": \"Meta Platforms financial performance is tied closely to advertising revenue, facing headwinds from competition and changing privacy regulations. Investments in the metaverse represent a long-term, high-risk bet.\",\n", + " \"MSFT\": \"Microsoft demonstrates healthy financials, benefiting from diversified revenue streams including cloud computing (Azure), software, and hardware. The company exhibits consistent growth and profitability.\",\n", + " \"NFLX\": \"Netflix exhibits strong revenue but faces challenges in maintaining subscriber growth and managing content costs. Profitability varies, and competition in the streaming market is intense.\",\n", + " \"NOW\": \"ServiceNow demonstrates strong financials, fueled by its cloud-based workflow automation platform. Revenue growth and profitability are high, reflecting increased enterprise adoption.\",\n", + " \"NVDA\": \"NVIDIA boasts strong financials, driven by its dominance in the GPU market for gaming, AI, and data centers. High revenue growth and profitability are key strengths.\",\n", + " \"ORCL\": \"Oracle financials are in transition, shifting towards cloud-based services. Revenue growth is moderate, and profitability remains stable. Legacy businesses still contribute significantly.\",\n", + " \"QCOM\": \"QUALCOMM financials show strong performance driven by its leadership in mobile chipsets and licensing. Profitability is high, and growth is tied to the mobile market and 5G adoption.\",\n", + " \"SAP\": \"SAP demonstrates steady financials with its enterprise software solutions. Transition to the cloud is ongoing and impacting revenue growth and profitability.\",\n", + " \"SMSN\": \"Samsung financials are diverse, reflecting its presence in various sectors including mobile phones, consumer electronics, and semiconductors. Profitability varies across divisions but the company holds significant cash reserves.\",\n", + " \"TCEHY\": \"Tencent financials are driven by its dominant position in the Chinese gaming and social media market. Revenue growth is strong but regulatory risks in China impact its performance.\",\n", + " \"TSLA\": \"Tesla financials show strong revenue growth driven by electric vehicle demand, but profitability remains volatile due to production and investment costs. The company high valuation reflects market optimism for future growth.\",\n", + " \"TSM\": \"TSMC, a dominant player in semiconductor manufacturing, showcases robust financials fueled by high demand for its advanced chips. Profitability is strong and the company enjoys a technologically advanced position.\",\n", + " }\n", + " return company_overviews.get(content[\"ticker\"], \"No company overwiew found\")\n", + "\n", + "\n", + "def get_stock_price_api(content: dict[str, Any]) -> str:\n", + " \"A function to simulate an API call to collect most recent stock price for a given company.\"\n", + " stock_prices = {\n", + " \"AAPL\": 225,\n", + " \"ADBE\": 503,\n", + " \"AMD\": 134,\n", + " \"AMZN\": 202,\n", + " \"ASML\": 658,\n", + " \"AVGO\": 164,\n", + " \"BABA\": 88,\n", + " \"BKNG\": 4000,\n", + " \"CRM\": 325,\n", + " \"CSCO\": 57,\n", + " \"GOOGL\": 173,\n", + " \"IBM\": 201,\n", + " \"INTU\": 607,\n", + " \"META\": 553,\n", + " \"MSFT\": 415,\n", + " \"NFLX\": 823,\n", + " \"NOW\": 1000,\n", + " \"NVDA\": 141,\n", + " \"ORCL\": 183,\n", + " \"QCOM\": 160,\n", + " \"SAP\": 228,\n", + " \"SMSN\": 38,\n", + " \"TCEHY\": 51,\n", + " \"TSLA\": 302,\n", + " \"TSM\": 186,\n", + " }\n", + " return stock_prices.get(content[\"ticker\"], \"No stock price found\")\n", + "\n", + "\n", + "def get_company_news_api(content: dict[str, Any]) -> str:\n", + " \"A function to simulate an API call to collect recent news for a given company.\"\n", + " news_data = {\n", + " \"AAPL\": \"Apple unveils new iPhone, market reaction muted amid concerns about slowing growth.\",\n", + " \"ADBE\": \"Adobe integrates AI features into Creative Suite, attracting creative professionals.\",\n", + " \"AMD\": \"AMD gains market share in server CPUs, competing with Intel.\",\n", + " \"AMZN\": \"Amazon stock dips after reporting lower-than-expected Q3 profits due to increased shipping costs.\",\n", + " \"ASML\": \"ASML benefits from high demand for advanced chip manufacturing equipment.\",\n", + " \"AVGO\": \"Broadcom announces new acquisition in the semiconductor space.\",\n", + " \"BABA\": \"Alibaba stock faces uncertainty amid ongoing regulatory scrutiny in China.\",\n", + " \"BKNG\": \"Booking Holdings stock recovers as travel demand rebounds post-pandemic.\",\n", + " \"CRM\": \"Salesforce launches new AI-powered CRM tools for enterprise customers.\",\n", + " \"CSCO\": \"Cisco stock rises after positive earnings report, focus on networking solutions.\",\n", + " \"GOOGL\": \"Alphabet announces new AI-powered search features, aiming to compete with Microsoft.\",\n", + " \"IBM\": \"IBM focuses on hybrid cloud solutions, showing steady growth in enterprise segment.\",\n", + " \"INTU\": \"Intuit stock dips after announcing price increases for its tax software.\",\n", + " \"META\": \"Meta shares rise after positive user growth figures in emerging markets.\",\n", + " \"MSFT\": \"Microsoft expands AI integration across its product suite, boosting investor confidence.\",\n", + " \"NFLX\": \"Netflix subscriber growth slows, competition heats up in streaming landscape.\",\n", + " \"NOW\": \"ServiceNow sees strong growth in its cloud-based workflow automation platform.\",\n", + " \"NVDA\": \"Nvidia stock jumps on strong earnings forecast, driven by AI demand.\",\n", + " \"ORCL\": \"Oracle cloud revenue continues strong growth, exceeding market expectations.\",\n", + " \"QCOM\": \"Qualcomm expands its 5G modem business, partnering with major smartphone manufacturers.\",\n", + " \"SAP\": \"SAP cloud transition continues, but faces challenges in attracting new clients.\",\n", + " \"SMSN\": \"Samsung unveils new foldable phones, looking to gain market share.\",\n", + " \"TCEHY\": \"Tencent faces regulatory pressure in China, impacting investor sentiment.\",\n", + " \"TSLA\": \"Tesla stock volatile after price cuts and production increases announced.\",\n", + " \"TSM\": \"TSMC reports record chip demand but warns of potential supply chain disruptions.\",\n", + " }\n", + " return news_data.get(content[\"ticker\"], \"No news available\")\n", + "\n", + "\n", + "def get_company_sentiment_api(content: dict[str, Any]) -> str:\n", + " \"A function to simulate an API call to collect market company sentiment for a given company.\"\n", + "\n", + " company_sentiment = {\n", + " \"AAPL\": \"Neutral\",\n", + " \"ADBE\": \"Neutral\",\n", + " \"AMD\": \"Neutral\",\n", + " \"AMZN\": \"Neutral\",\n", + " \"ASML\": \"Bearish/Undervalued\",\n", + " \"AVGO\": \"Neutral\",\n", + " \"BABA\": \"Neutral\",\n", + " \"BKNG\": \"Neutral\",\n", + " \"CRM\": \"Neutral\",\n", + " \"CSCO\": \"Neutral\",\n", + " \"GOOGL\": \"Neutral\",\n", + " \"IBM\": \"Neutral\",\n", + " \"INTU\": \"Mixed/Bullish\",\n", + " \"META\": \"Neutral\",\n", + " \"MSFT\": \"Neutral\",\n", + " \"NFLX\": \"Neutral\",\n", + " \"NOW\": \"Bullish/Overvalued\",\n", + " \"NVDA\": \"Neutral\",\n", + " \"ORCL\": \"Neutral\",\n", + " \"QCOM\": \"Neutral\",\n", + " \"SAP\": \"Neutral\",\n", + " \"SMSN\": \"Neutral\",\n", + " \"TCEHY\": \"Neutral\",\n", + " \"TSLA\": \"Slightly Overvalued\",\n", + " \"TSM\": \"Neutral\",\n", + " }\n", + " return company_sentiment.get(content[\"ticker\"], \"No sentiment available\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "init_aip:mbsdk,all" + }, + "source": [ + "### Initialize Vertex AI SDK for Python\n", + "\n", + "Initialize the Vertex AI SDK for Python for your project." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "bQMc2Uwf0fBQ" + }, + "outputs": [], + "source": [ + "aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EdvJRUWRNGHE" + }, + "source": [ + "## III. Automated prompt design with Vertex AI prompt optimizer" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "mmTotjRAJplw" + }, + "source": [ + "### Load the dataset\n", + "\n", + "Load the AI financial assistant's question-answer dataset from a Google Cloud Storage bucket. The dataset contains the following columns:\n", + "\n", + "* **question:** User's query regarding about company.\n", + "* **tool_names:** Specifies tool names used to answer the question.\n", + "* **tool_call:** Details the input parameters passed to the specified tools.\n", + "* **tool_call_response:** Raw output from the tool.\n", + "* **answer:** A refined and human-readable response grounded in the tool's output, answering the user's question." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "LA7aG08wJtVm" + }, + "outputs": [], + "source": [ + "prompt_optimization_df = pd.read_json(INPUT_DATA_FILE_URI, lines=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "1xn-pz3v5HVK" + }, + "outputs": [], + "source": [ + "prompt_optimization_df.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "E2l7JwuDcPqX" + }, + "source": [ + "Print an example of the cooking question-answer dataset. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "b8zgOTZVa6xa" + }, + "outputs": [], + "source": [ + "vapo_lib.print_df_rows(prompt_optimization_df, n=1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Rp1n1aMACzSW" + }, + "source": [ + "### Optimize the prompt template with Vertex AI prompt optimizer with custom metric\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "h1650lf3X8xW" + }, + "source": [ + "#### Prepare the prompt template you want to optimize\n", + "\n", + "A prompt consists of two key parts:\n", + "\n", + "* **System Instruction Template** which is a fixed part of the prompt that control or alter the model's behavior across all queries for a given task.\n", + "\n", + "* **Prompt Template** which is a dynamic part of the prompt that changes based on the task. Prompt template includes examples, context, task and more. To learn more, see [components of a prompt](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/prompt-design-strategies#components-of-a-prompt) in the official documentation.\n", + "\n", + "In this scenario, you use Vertex AI prompt optimizer to optimize a simple system instruction template.\n", + "\n", + "And you use some examples in the remaining prompt template for evaluating different instruction templates along the optimization process." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "L_vLpXX2HDe1" + }, + "source": [ + "> **Note**: Having the `target` placeholder in the prompt template is optional. It represents the prompt's ground truth response in your prompt optimization dataset that you aim to optimize for your templates. If you don't have the prompt's ground truth response, remember to set the `source_model` parameter to your prompt optimizer configuration (see below) instead of adding ground truth responses. Vertex AI prompt optimizer would run your sample prompts on the source model to generate the ground truth responses for you." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Db8rHNC6DmtY" + }, + "outputs": [], + "source": [ + "SYSTEM_INSTRUCTION_TEMPLATE = \"\"\"\n", + "Answer the question using correct tools.\n", + "\"\"\"\n", + "\n", + "PROMPT_TEMPLATE = \"\"\"\n", + "Some examples of correct tools associated to a question are:\n", + "Question: {question}\n", + "Target tools: {target}\n", + "\"\"\"" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "a1TCgXsrXztm" + }, + "source": [ + "#### Prepare the prompt optimization dataset\n", + "\n", + "To use Vertex AI prompt optimizer, you'll need a CSV or JSONL file with labeled examples. These examples should follow a specific naming convention. For details see [Optimize prompts](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/prompt-optimizer).\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SYV-fansHMM_" + }, + "source": [ + "> **Note**: For effective **prompt optimization**, provide a dataset of examples where your model is poor in performance when using current system instruction template. For reliable results, use 50-100 distinct samples.\n", + "\n", + "> In case of **prompt migration**, consider using the source model to label examples that the target model struggles with, helping to identify areas for improvement." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "LBWLrWKil6jK" + }, + "outputs": [], + "source": [ + "train_prompt_optimization_df, test_prompt_optimization_df = train_test_split(\n", + " prompt_optimization_df, test_size=0.3, random_state=8\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "vTIl_v9Ig1F-" + }, + "outputs": [], + "source": [ + "prepared_train_prompt_optimization_df = train_prompt_optimization_df.copy()\n", + "\n", + "# Prepare target column\n", + "prepared_train_prompt_optimization_df[\"target\"] = (\n", + " prepared_train_prompt_optimization_df.apply(vapo_lib.create_target_column, axis=1)\n", + ")\n", + "\n", + "# Remove uneccessary columns\n", + "prepared_train_prompt_optimization_df = prepared_train_prompt_optimization_df.drop(\n", + " columns=[\"tool_names\", \"tool_arguments\", \"tool_call_response\", \"answer\"]\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZbTqB2o5ZslT" + }, + "source": [ + "Print some examples of the prompt optimization dataset. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "_DUFEAb82eEi" + }, + "outputs": [], + "source": [ + "prepared_train_prompt_optimization_df.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nF3XY_d_yB-K" + }, + "source": [ + "#### Upload samples to bucket\n", + "\n", + "Once you prepare your prompt optimization dataset, you can upload them on Cloud Storage bucket." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "155paLgGUXOm" + }, + "outputs": [], + "source": [ + "prepared_train_prompt_optimization_df.to_json(\n", + " INPUT_OPTIMIZATION_DATA_FILE_URI, orient=\"records\", lines=True\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "82VNGt07_erb" + }, + "source": [ + "#### Configure tool settings and validate them\n", + "\n", + "To optimize prompts for using external tools with the Vertex AI SDK, define the tools' functionalities using the `FunctionDeclaration` class. This class uses an OpenAPI-compatible schema to structure the tool definitions. Your system prompt should be designed to effectively leverage these defined functions. See the [Introduction to function calling](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling) for more information. \n", + "\n", + "Example function definitions for a financial assistant are provided below.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "_gEJ5Dd9rsOX" + }, + "outputs": [], + "source": [ + "get_company_information = FunctionDeclaration(\n", + " name=\"get_company_information\",\n", + " description=\"Retrieves financial performance to provide an overview for a company.\",\n", + " parameters={\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"ticker\": {\n", + " \"type\": \"string\",\n", + " \"description\": \"Stock ticker for a given company\",\n", + " }\n", + " },\n", + " \"required\": [\"ticker\"],\n", + " },\n", + ")\n", + "\n", + "get_stock_price = FunctionDeclaration(\n", + " name=\"get_stock_price\",\n", + " description=\"Only returns the current stock price (in dollars) for a company.\",\n", + " parameters={\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"ticker\": {\n", + " \"type\": \"integer\",\n", + " \"description\": \"Stock ticker for a company\",\n", + " }\n", + " },\n", + " \"required\": [\"ticker\"],\n", + " },\n", + ")\n", + "\n", + "get_company_news = FunctionDeclaration(\n", + " name=\"get_company_news\",\n", + " description=\"Get the latest news headlines for a given company.\",\n", + " parameters={\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"ticker\": {\n", + " \"type\": \"string\",\n", + " \"description\": \"Stock ticker for a company.\",\n", + " }\n", + " },\n", + " \"required\": [\"ticker\"],\n", + " },\n", + ")\n", + "\n", + "get_company_sentiment = FunctionDeclaration(\n", + " name=\"get_company_sentiment\",\n", + " description=\"Returns the overall market sentiment for a company.\",\n", + " parameters={\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"ticker\": {\n", + " \"type\": \"string\",\n", + " \"description\": \"Stock ticker for a company\",\n", + " },\n", + " },\n", + " \"required\": [\"ticker\"],\n", + " },\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "52T9TTwu4LbW" + }, + "source": [ + "After implementing your functions, wrap each one as a `Tool` object. This allows the Gemini model to discover and execute these functions. `ToolConfig` provides additional parameters to control how the model interacts with the tools and chooses which function to call. \n", + "\n", + "Further information can be found in the [Introduction to function calling](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling).\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "bq9M_-jt4KoB" + }, + "outputs": [], + "source": [ + "tools = Tool(\n", + " function_declarations=[\n", + " get_company_information,\n", + " get_stock_price,\n", + " get_company_news,\n", + " get_company_sentiment,\n", + " ]\n", + ")\n", + "\n", + "tool_config = ToolConfig(\n", + " function_calling_config=ToolConfig.FunctionCallingConfig(\n", + " mode=ToolConfig.FunctionCallingConfig.Mode.ANY,\n", + " allowed_function_names=[\n", + " \"get_company_information\",\n", + " \"get_stock_price\",\n", + " \"get_company_news\",\n", + " \"get_company_sentiment\",\n", + " ],\n", + " )\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4nMEMYU6sNUA" + }, + "source": [ + "To use Vertex AI Prompt Optimizer for tool calling optimization, provide `FunctionDeclaration` and `ToolConfig` as JSON structures (see example below). Vertex AI Prompt Optimizer uses those structures along the optimization process.\n", + "\n", + "Tool Calls json:\n", + "```\n", + "{\"tools\": [{\"function_declarations\": [{\"name\": \"function_1\", \"description\": \"My function 1\", \"parameters\": {\"type\": \"OBJECT\", \"properties\": {\"argument_1\": {\"type\": \"STRING\", \"description\": \"My argument 1\"}}, \"required\": [\"argument_1\"], \"property_ordering\": [\"argument_1\"]}}, ...]}]}\n", + "```\n", + "Function Calling Configuration json:\n", + "```\n", + "{\"function_calling_config\": {\"mode\": \"your_mode\", \"allowed_function_names\": [\"tool_name_1\", ...]}}\n", + "```\n", + "\n", + "Below you have some helper functions to get those structures and validate them.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "jxHLX921xdHJ" + }, + "outputs": [], + "source": [ + "vapo_tools = json.dumps({\"tools\": [vapo_lib.replace_type_key(tools.to_dict())]})\n", + "\n", + "vapo_tool_config = json.dumps(vapo_lib.tool_config_to_dict(tool_config))\n", + "\n", + "vapo_lib.validate_tools(vapo_tools)\n", + "vapo_lib.validate_tool_config(vapo_tool_config)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "F5RD0l2xX-FI" + }, + "source": [ + "#### Configure optimization settings\n", + "\n", + "Vertex AI prompt optimizer lets you control the optimization process by specifying what to optimize (instructions only, demonstrations only, or both), providing a system instruction and prompt template, and selecting the target model. You can optionally refine the optimization with some advanced settings like its duration and the number of optimization iterations it runs, which models the Vertex AI prompt optimizer uses, and other parameters to control the structure and content of prompts. Below you have some common and recommended default configurations.\n", + "\n", + "In this scenario, you set two additional parameters:\n", + "\n", + "* `tools` parameter to pass tool definitions\n", + "\n", + "* `tool_config` parameter to pass tool configuration\n", + "\n", + "For more advanced control, you can learn and explore more about all the parameters and how to best use them in the [detailed documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/prompt-optimizer).\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "sFHutXhgeqRx" + }, + "outputs": [], + "source": [ + "PROMPT_OPTIMIZATION_JOB = \"auto-prompt-design-job-\" + vapo_lib.get_id()\n", + "OUTPUT_OPTIMIZATION_RUN_URI = str(\n", + " OUTPUT_OPTIMIZATION_DATA_URI / PROMPT_OPTIMIZATION_JOB\n", + ")\n", + "\n", + "args = Namespace(\n", + " # Basic configuration\n", + " system_instruction=SYSTEM_INSTRUCTION_TEMPLATE, # System instructions for the target model. String.\n", + " prompt_template=PROMPT_TEMPLATE, # Template for prompts, String.\n", + " target_model=\"gemini-1.5-flash-001\", # Target model for optimization. String. Supported models: \"gemini-1.5-flash-002\", \"gemini-1.5-pro-002\", \"gemini-1.5-flash-001\", \"gemini-1.5-pro-001\", \"gemini-1.0-pro-001\", \"gemini-1.0-pro-002\", \"gemini-1.0-ultra-001\", \"text-bison@001\", \"text-bison@002\", \"text-bison32k@002\", \"text-unicorn@001\"\n", + " optimization_mode=\"instruction\", # Optimization mode. String. Supported modes: \"instruction\", \"demonstration\", \"instruction_and_demo\"\n", + " tools=vapo_tools,\n", + " tool_config=vapo_tool_config,\n", + " eval_metrics_types=[\n", + " \"tool_name_match\",\n", + " \"tool_parameter_key_match\",\n", + " \"tool_parameter_kv_match\",\n", + " ], # List of evaluation metrics. List of strings. Supported metrics: \"bleu\", \"coherence\", \"exact_match\", \"fluidity\", \"fulfillment\", \"groundedness\", \"rouge_1\", \"rouge_2\", \"rouge_l\", \"rouge_l_sum\", \"safety\", \"question_answering_correctness\", \"question_answering_helpfulness\", \"question_answering_quality\", \"question_answering_relevance\", \"summarization_helpfulness\", \"summarization_quality\", \"summarization_verbosity\", \"tool_name_match\", \"tool_parameter_key_match\", \"tool_parameter_kv_match\"\n", + " eval_metrics_weights=[\n", + " 0.4,\n", + " 0.3,\n", + " 0.3,\n", + " ], # Weights for evaluation metrics. List of floats. Length must match eval_metrics_types. Should sum to 1.\n", + " aggregation_type=\"weighted_sum\", # Aggregation type for evaluation metrics. String. Supported aggregation types: \"weighted_sum\", \"weighted_average\"\n", + " input_data_path=INPUT_OPTIMIZATION_DATA_FILE_URI, # Cloud Storage URI to input optimization data. String.\n", + " output_path=OUTPUT_OPTIMIZATION_RUN_URI, # Cloud Storage URI to save optimization results. String.\n", + " project=PROJECT_ID, # Google Cloud project ID. String.\n", + " # (Optional) Advanced configuration\n", + " num_steps=10, # Number of iterations in instruction optimization mode. Integer between 10 and 20.\n", + " num_template_eval_per_step=2, # Number of system instructions generated and evaluated in instruction and instruction_and_demo mode. Integer between 1 and 4.\n", + " num_demo_set_candidates=10, # Number of demonstrations evaluated in instruction and instruction_and_demo mode. Integer between 10 and 30.\n", + " demo_set_size=3, # Number of demonstrations generated per prompt. Integer between 3 and 6.\n", + " target_model_location=\"us-central1\", # Location of the target model. String. Default us-central1.\n", + " optimizer_model=\"gemini-1.5-pro-001\", # Optimization model. String. Supported models: \"gemini-1.5-flash-002\", \"gemini-1.5-pro-002\", \"gemini-1.5-flash-001\", \"gemini-1.5-pro-001\", \"gemini-1.0-pro-001\", \"gemini-1.0-pro-002\", \"gemini-1.0-ultra-001\", \"text-bison@001\", \"text-bison@002\", \"text-bison32k@002\", \"text-unicorn@001\"\n", + " optimizer_model_location=\"us-central1\", # Location of the optimization model. String. Default us-central1.\n", + " eval_model=\"gemini-1.5-pro-001\", # Evaluation model. String. Supported models: \"gemini-1.5-flash-002\", \"gemini-1.5-pro-002\", \"gemini-1.5-flash-001\", \"gemini-1.5-pro-001\", \"gemini-1.0-pro-001\", \"gemini-1.0-pro-002\", \"gemini-1.0-ultra-001\", \"text-bison@001\", \"text-bison@002\", \"text-bison32k@002\", \"text-unicorn@001\"\n", + " eval_model_location=\"us-central1\", # Location of the evaluation model. String. Default us-central1.\n", + " source_model=\"\", # Google model that the system instructions and prompts were previously used with. String. Not needed if you provide target column.\n", + " source_model_location=\"\", # Location of the source model. String. Default us-central1. Not needed if you provide target column.\n", + " target_model_qps=1, # The queries per second (QPS) sent to the target model. Integer greater or equal than 1 depending on your quota.\n", + " optimizer_model_qps=1, # The queries per second (QPS) sent to the optimization model. Integer greater or equal than 1 depending on your quota.\n", + " eval_qps=1, # The queries per second (QPS) sent to the eval model. Integer greater or equal than 1 depending on your quota.\n", + " source_model_qps=\"\", # The queries per second (QPS) sent to the source model. Integer greater or equal than 1 depending on your quota.\n", + " response_mime_type=\"text/plain\", # MIME response type that the target model uses. String. Supported response: text/plain, application/json.\n", + " response_schema=\"\", # Response schema that the target model uses to generate answers. String.\n", + " language=\"English\", # Language of the system instructions. String. Supported languages: \"English\", \"French\", \"German\", \"Hebrew\", \"Hindi\", \"Japanese\", \"Korean\", \"Portuguese\", \"Simplified Chinese\", \"Spanish\", \"Traditional Chinese\"\n", + " placeholder_to_content=json.loads(\n", + " \"{}\"\n", + " ), # Placeholder to replace any parameter in the system instruction. Dict.\n", + " data_limit=50, # Amount of data used for validation. Integer between 5 and 100.\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Jd_uzQYQx6L7" + }, + "source": [ + "#### Upload Vertex AI prompt optimizer Cloud Storage\n", + "\n", + "After you define Vertex AI prompt optimizer configuration, you upload them on Cloud Storage bucket.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "iqiv8ApR_SAM" + }, + "outputs": [], + "source": [ + "args = vars(args)\n", + "\n", + "with epath.Path(CONFIG_FILE_URI).open(\"w\") as config_file:\n", + " json.dump(args, config_file)\n", + "config_file.close()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "spqgBT8hYAle" + }, + "source": [ + "#### Run the automatic prompt optimization job\n", + "\n", + "Now you are ready to run your first Vertex AI prompt optimizer job using the Vertex AI SDK for Python." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RlNQ_UrFH9ne" + }, + "source": [ + "> This prompt optimization job requires ~ 40 minutes to run.\n", + "\n", + "> Be sure you have provisioned enough queries per minute (QPM) quota implementing the recommended QPM for each model. If you configure the Vertex AI prompt optimizer with a QPM that is higher than the QPM than you have access to, the job might fail. [Check out](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/prompt-optimizer#before-you-begin) the documentation to know more.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "GtPnvKIpUQ3q" + }, + "outputs": [], + "source": [ + "WORKER_POOL_SPECS = [\n", + " {\n", + " \"machine_spec\": {\n", + " \"machine_type\": \"n1-standard-4\",\n", + " },\n", + " \"replica_count\": 1,\n", + " \"container_spec\": {\n", + " \"image_uri\": APD_CONTAINER_URI,\n", + " \"args\": [\"--config=\" + CONFIG_FILE_URI],\n", + " },\n", + " }\n", + "]\n", + "\n", + "custom_job = aiplatform.CustomJob(\n", + " display_name=PROMPT_OPTIMIZATION_JOB,\n", + " worker_pool_specs=WORKER_POOL_SPECS,\n", + ")\n", + "\n", + "custom_job.submit(service_account=SERVICE_ACCOUNT)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3YwwKBhtJ4ut" + }, + "source": [ + "### Collect and display the optimization results\n", + "\n", + "Vertex AI prompt optimizer returns both optimized templates and evaluation results for either instruction, or demostrations, or both depending on the optimization mode you define as JSONL files on Cloud Storage bucket. Those results help you understand the optimization process.\n", + "\n", + "In this case, you want to collect the optimized templates and evaluation results for the system instruction.\n", + "\n", + "Below you use a helper function to display those results." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "-6ohF0LJIhvU" + }, + "outputs": [], + "source": [ + "results_ui = vapo_lib.ResultsUI(OUTPUT_OPTIMIZATION_RUN_URI)\n", + "results_df_html = \"\"\"\n", + "\n", + "\"\"\"\n", + "\n", + "display(HTML(results_df_html))\n", + "display(results_ui.get_container())" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TrMrbcA5Gzep" + }, + "source": [ + "### Evaluate the quality of generated responses with the optimized instruction\n", + "\n", + "Finally, you evaluate generated responses with the optimized instruction qualitatively.\n", + "\n", + "If you want to know how to evaluate the new generated responses quantitatively, check out the [`vertex_ai_prompt_optimizer_sdk` notebook](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/gemini/prompts/prompt_optimizer) in the official repository.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DJK4KD0VkSuz" + }, + "source": [ + "#### Generate new responses using the optimized system instruction.\n", + "\n", + "Set the optimized system instruction template you get from Vertex AI prompt optimizer job." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "BVamCk10KYHu" + }, + "outputs": [], + "source": [ + "OPTIMIZED_SYSTEM_INSTRUCTION_TEMPLATE = \"To provide the most accurate response to the given question, determine and employ the most suitable tools.\" # @param {type:\"string\"}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1U79bZ_KTM6T" + }, + "source": [ + "Prepare optimized prompts using the optimized system instruction template." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "XfouWkLPkSu1" + }, + "outputs": [], + "source": [ + "OPTIMIZED_PROMPT_TEMPLATE = (\n", + " OPTIMIZED_SYSTEM_INSTRUCTION_TEMPLATE + \"\\nQuestion: \\n{question}\" + \"\\nAnswer:\"\n", + ")\n", + "\n", + "optimized_prompts = [\n", + " OPTIMIZED_PROMPT_TEMPLATE.format(question=q)\n", + " for q in zip(\n", + " test_prompt_optimization_df[\"question\"].to_list(),\n", + " )\n", + "]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sofPH74kT165" + }, + "source": [ + "Leverage Gemini API on Vertex AI to send parallel generation requests.\n", + "\n", + "In this scenario, you have to define a function map which allows you to handle function calling in parallel. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "aZfPgrmZ0jub" + }, + "outputs": [], + "source": [ + "function_map = {\n", + " \"get_company_information\": get_company_information_api,\n", + " \"get_stock_price\": get_stock_price_api,\n", + " \"get_company_news\": get_company_news_api,\n", + " \"get_company_sentiment\": get_company_sentiment_api,\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "NM5-8FzpkSu1" + }, + "outputs": [], + "source": [ + "gemini_llm = vapo_lib.init_new_model(model_name=\"gemini-1.5-flash-001\")\n", + "\n", + "gemini_predictions = [\n", + " vapo_lib.async_generate(p, gemini_llm, function_map, tools, tool_config)\n", + " for p in optimized_prompts\n", + "]\n", + "\n", + "gemini_predictions_col = await tqdm_asyncio.gather(*gemini_predictions)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0BA9wRQnsHg0" + }, + "source": [ + "#### Evaluate new responses" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SEVi8m4gUMqP" + }, + "source": [ + "Prepare the test dataset and inspect new responses." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "8khmj0oATV7O" + }, + "outputs": [], + "source": [ + "test_prompt_optimization_df[\"optimized_prompt_with_vapo\"] = optimized_prompts\n", + "test_prompt_optimization_df[\"gemini_answer_with_vapo\"] = gemini_predictions_col" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "0s2pAKq4TaiJ" + }, + "outputs": [], + "source": [ + "vapo_lib.print_df_rows(test_prompt_optimization_df, n=1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2a4e033321ad" + }, + "source": [ + "## IV. Clean up" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "WRY_3wh1GVNm" + }, + "outputs": [], + "source": [ + "delete_bucket = False\n", + "delete_job = False\n", + "delete_tutorial = False\n", + "\n", + "if delete_bucket:\n", + " ! gsutil rm -r {BUCKET_URI}\n", + "\n", + "if delete_job:\n", + " custom_job.delete()\n", + "\n", + "if delete_tutorial:\n", + " import shutil\n", + "\n", + " shutil.rmtree(str(TUTORIAL_PATH))" + ] + } + ], + "metadata": { + "colab": { + "name": "vertex_ai_prompt_optimizer_sdk_tool_calling.ipynb", + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 } diff --git a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_ui.ipynb b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_ui.ipynb index 290152b4681..e2cc9cce611 100644 --- a/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_ui.ipynb +++ b/gemini/prompts/prompt_optimizer/vertex_ai_prompt_optimizer_ui.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/qa-ops/building_DIY_multimodal_qa_system_with_mRAG.ipynb b/gemini/qa-ops/building_DIY_multimodal_qa_system_with_mRAG.ipynb index a51e8743677..75d8137066e 100644 --- a/gemini/qa-ops/building_DIY_multimodal_qa_system_with_mRAG.ipynb +++ b/gemini/qa-ops/building_DIY_multimodal_qa_system_with_mRAG.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/qa-ops/intro_Vertex_AI_embeddings.ipynb b/gemini/qa-ops/intro_Vertex_AI_embeddings.ipynb index 25f037dca51..075c1afda3a 100644 --- a/gemini/qa-ops/intro_Vertex_AI_embeddings.ipynb +++ b/gemini/qa-ops/intro_Vertex_AI_embeddings.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/rag-engine/intro_rag_engine.ipynb b/gemini/rag-engine/intro_rag_engine.ipynb index c3f42ffe072..797a7a165ac 100644 --- a/gemini/rag-engine/intro_rag_engine.ipynb +++ b/gemini/rag-engine/intro_rag_engine.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/rag-engine/rag_engine_evaluation.ipynb b/gemini/rag-engine/rag_engine_evaluation.ipynb index f875170647e..a17a081e96e 100644 --- a/gemini/rag-engine/rag_engine_evaluation.ipynb +++ b/gemini/rag-engine/rag_engine_evaluation.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/rag-engine/rag_engine_feature_store.ipynb b/gemini/rag-engine/rag_engine_feature_store.ipynb index 3f40b97f143..64760ee8174 100644 --- a/gemini/rag-engine/rag_engine_feature_store.ipynb +++ b/gemini/rag-engine/rag_engine_feature_store.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/rag-engine/rag_engine_pinecone.ipynb b/gemini/rag-engine/rag_engine_pinecone.ipynb index 1e55d707bb5..2919498aed4 100644 --- a/gemini/rag-engine/rag_engine_pinecone.ipynb +++ b/gemini/rag-engine/rag_engine_pinecone.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/rag-engine/rag_engine_vector_search.ipynb b/gemini/rag-engine/rag_engine_vector_search.ipynb index 11470942843..f1f77dc32c6 100644 --- a/gemini/rag-engine/rag_engine_vector_search.ipynb +++ b/gemini/rag-engine/rag_engine_vector_search.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/rag-engine/rag_engine_weaviate.ipynb b/gemini/rag-engine/rag_engine_weaviate.ipynb index 1862eaddbcd..686c92421c6 100644 --- a/gemini/rag-engine/rag_engine_weaviate.ipynb +++ b/gemini/rag-engine/rag_engine_weaviate.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/reasoning-engine/intro_reasoning_engine.ipynb b/gemini/reasoning-engine/intro_reasoning_engine.ipynb index ff622df7029..89ab462eda4 100644 --- a/gemini/reasoning-engine/intro_reasoning_engine.ipynb +++ b/gemini/reasoning-engine/intro_reasoning_engine.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/reasoning-engine/tracing_agents_in_reasoning_engine.ipynb b/gemini/reasoning-engine/tracing_agents_in_reasoning_engine.ipynb index e148f0893ca..12e77a367e3 100644 --- a/gemini/reasoning-engine/tracing_agents_in_reasoning_engine.ipynb +++ b/gemini/reasoning-engine/tracing_agents_in_reasoning_engine.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/reasoning-engine/tutorial_alloydb_rag_agent.ipynb b/gemini/reasoning-engine/tutorial_alloydb_rag_agent.ipynb index 02210f7e14c..8d921dd2e58 100644 --- a/gemini/reasoning-engine/tutorial_alloydb_rag_agent.ipynb +++ b/gemini/reasoning-engine/tutorial_alloydb_rag_agent.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/reasoning-engine/tutorial_cloud_sql_pg_rag_agent.ipynb b/gemini/reasoning-engine/tutorial_cloud_sql_pg_rag_agent.ipynb index c22c5acd3ed..25bc85510db 100644 --- a/gemini/reasoning-engine/tutorial_cloud_sql_pg_rag_agent.ipynb +++ b/gemini/reasoning-engine/tutorial_cloud_sql_pg_rag_agent.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/reasoning-engine/tutorial_google_maps_agent.ipynb b/gemini/reasoning-engine/tutorial_google_maps_agent.ipynb index 3c194bcf96c..4e7fa3472df 100644 --- a/gemini/reasoning-engine/tutorial_google_maps_agent.ipynb +++ b/gemini/reasoning-engine/tutorial_google_maps_agent.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/reasoning-engine/tutorial_langgraph.ipynb b/gemini/reasoning-engine/tutorial_langgraph.ipynb index 25da7a507d2..2646f4bf627 100644 --- a/gemini/reasoning-engine/tutorial_langgraph.ipynb +++ b/gemini/reasoning-engine/tutorial_langgraph.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/reasoning-engine/tutorial_langgraph_rag_agent.ipynb b/gemini/reasoning-engine/tutorial_langgraph_rag_agent.ipynb index 91d2c40db3b..b53f620d1f0 100644 --- a/gemini/reasoning-engine/tutorial_langgraph_rag_agent.ipynb +++ b/gemini/reasoning-engine/tutorial_langgraph_rag_agent.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/reasoning-engine/tutorial_vertex_ai_search_rag_agent.ipynb b/gemini/reasoning-engine/tutorial_vertex_ai_search_rag_agent.ipynb index 4f217130c6c..ee2b23c5c6f 100644 --- a/gemini/reasoning-engine/tutorial_vertex_ai_search_rag_agent.ipynb +++ b/gemini/reasoning-engine/tutorial_vertex_ai_search_rag_agent.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/responsible-ai/gemini_prompt_attacks_mitigation_examples.ipynb b/gemini/responsible-ai/gemini_prompt_attacks_mitigation_examples.ipynb index 157f6cde7fd..d8c8c4ed561 100644 --- a/gemini/responsible-ai/gemini_prompt_attacks_mitigation_examples.ipynb +++ b/gemini/responsible-ai/gemini_prompt_attacks_mitigation_examples.ipynb @@ -93,7 +93,31 @@ " Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/responsible-ai/gemini_safety_ratings.ipynb b/gemini/responsible-ai/gemini_safety_ratings.ipynb index 242c27ab610..16da466ecc2 100644 --- a/gemini/responsible-ai/gemini_safety_ratings.ipynb +++ b/gemini/responsible-ai/gemini_safety_ratings.ipynb @@ -53,7 +53,31 @@ " Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/responsible-ai/react_rag_attacks_mitigations_examples.ipynb b/gemini/responsible-ai/react_rag_attacks_mitigations_examples.ipynb index 93d6a3d370d..d29dc856130 100644 --- a/gemini/responsible-ai/react_rag_attacks_mitigations_examples.ipynb +++ b/gemini/responsible-ai/react_rag_attacks_mitigations_examples.ipynb @@ -73,7 +73,31 @@ " Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/sample-apps/e2e-gen-ai-app-starter-pack/notebooks/getting_started.ipynb b/gemini/sample-apps/e2e-gen-ai-app-starter-pack/notebooks/getting_started.ipynb index c94e80048d6..f7c2d8a5404 100644 --- a/gemini/sample-apps/e2e-gen-ai-app-starter-pack/notebooks/getting_started.ipynb +++ b/gemini/sample-apps/e2e-gen-ai-app-starter-pack/notebooks/getting_started.ipynb @@ -59,7 +59,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { @@ -530,6 +554,8 @@ "outputs": [], "source": [ "# 1. Define tools\n", + "\n", + "\n", "@tool\n", "def search(query: str):\n", " \"\"\"Simulates a web search. Use it get information on weather. E.g what is the weather like in a region\"\"\"\n", diff --git a/gemini/tuning/supervised_finetuning_using_gemini.ipynb b/gemini/tuning/supervised_finetuning_using_gemini.ipynb index 1973671385e..bfff45eb4d3 100644 --- a/gemini/tuning/supervised_finetuning_using_gemini.ipynb +++ b/gemini/tuning/supervised_finetuning_using_gemini.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/tuning/supervised_finetuning_using_gemini_on_image_data.ipynb b/gemini/tuning/supervised_finetuning_using_gemini_on_image_data.ipynb index 4e190e8bb80..ca01d01f5d6 100644 --- a/gemini/tuning/supervised_finetuning_using_gemini_on_image_data.ipynb +++ b/gemini/tuning/supervised_finetuning_using_gemini_on_image_data.ipynb @@ -54,7 +54,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/tuning/supervised_finetuning_using_gemini_qa.ipynb b/gemini/tuning/supervised_finetuning_using_gemini_qa.ipynb index 00703b601c1..07fc33992e7 100644 --- a/gemini/tuning/supervised_finetuning_using_gemini_qa.ipynb +++ b/gemini/tuning/supervised_finetuning_using_gemini_qa.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/tuning/vertexai_supervised_tuning_token_count_and_cost_estimation.ipynb b/gemini/tuning/vertexai_supervised_tuning_token_count_and_cost_estimation.ipynb index 33f48216b69..dde205bd94b 100644 --- a/gemini/tuning/vertexai_supervised_tuning_token_count_and_cost_estimation.ipynb +++ b/gemini/tuning/vertexai_supervised_tuning_token_count_and_cost_estimation.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb b/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb index 294a32d2ddc..acdddb84081 100644 --- a/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb +++ b/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/applying-llms-to-data/semantic-search-in-bigquery/stackoverflow_questions_semantic_search.ipynb b/gemini/use-cases/applying-llms-to-data/semantic-search-in-bigquery/stackoverflow_questions_semantic_search.ipynb index 5c5063a52bd..f8e4c2c4db8 100644 --- a/gemini/use-cases/applying-llms-to-data/semantic-search-in-bigquery/stackoverflow_questions_semantic_search.ipynb +++ b/gemini/use-cases/applying-llms-to-data/semantic-search-in-bigquery/stackoverflow_questions_semantic_search.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/code/analyze_codebase_with_gemini_1_5_pro.ipynb b/gemini/use-cases/code/analyze_codebase_with_gemini_1_5_pro.ipynb index a623ded2649..5548589132a 100644 --- a/gemini/use-cases/code/analyze_codebase_with_gemini_1_5_pro.ipynb +++ b/gemini/use-cases/code/analyze_codebase_with_gemini_1_5_pro.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/code/code_retrieval_augmented_generation.ipynb b/gemini/use-cases/code/code_retrieval_augmented_generation.ipynb index d9e2cea5f5b..3d399a93156 100644 --- a/gemini/use-cases/code/code_retrieval_augmented_generation.ipynb +++ b/gemini/use-cases/code/code_retrieval_augmented_generation.ipynb @@ -54,7 +54,31 @@ " \"Vertex
Open in Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/code/code_scanning_and_vulnerability_detection.ipynb b/gemini/use-cases/code/code_scanning_and_vulnerability_detection.ipynb index 6436698ccc7..82ab298f54a 100644 --- a/gemini/use-cases/code/code_scanning_and_vulnerability_detection.ipynb +++ b/gemini/use-cases/code/code_scanning_and_vulnerability_detection.ipynb @@ -40,7 +40,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { @@ -749,7 +773,49 @@ "outputs": [ { "data": { - "application/javascript": "\n async function download(id, filename, size) {\n if (!google.colab.kernel.accessAllowed) {\n return;\n }\n const div = document.createElement('div');\n const label = document.createElement('label');\n label.textContent = `Downloading \"${filename}\": `;\n div.appendChild(label);\n const progress = document.createElement('progress');\n progress.max = size;\n div.appendChild(progress);\n document.body.appendChild(div);\n\n const buffers = [];\n let downloaded = 0;\n\n const channel = await google.colab.kernel.comms.open(id);\n // Send a message to notify the kernel that we're ready.\n channel.send({})\n\n for await (const message of channel.messages) {\n // Send a message to notify the kernel that we're ready.\n channel.send({})\n if (message.buffers) {\n for (const buffer of message.buffers) {\n buffers.push(buffer);\n downloaded += buffer.byteLength;\n progress.value = downloaded;\n }\n }\n }\n const blob = new Blob(buffers, {type: 'application/binary'});\n const a = document.createElement('a');\n a.href = window.URL.createObjectURL(blob);\n a.download = filename;\n div.appendChild(a);\n a.click();\n div.remove();\n }\n ", + "application/javascript": [ + "\n", + " async function download(id, filename, size) {\n", + " if (!google.colab.kernel.accessAllowed) {\n", + " return;\n", + " }\n", + " const div = document.createElement('div');\n", + " const label = document.createElement('label');\n", + " label.textContent = `Downloading \"${filename}\": `;\n", + " div.appendChild(label);\n", + " const progress = document.createElement('progress');\n", + " progress.max = size;\n", + " div.appendChild(progress);\n", + " document.body.appendChild(div);\n", + "\n", + " const buffers = [];\n", + " let downloaded = 0;\n", + "\n", + " const channel = await google.colab.kernel.comms.open(id);\n", + " // Send a message to notify the kernel that we're ready.\n", + " channel.send({})\n", + "\n", + " for await (const message of channel.messages) {\n", + " // Send a message to notify the kernel that we're ready.\n", + " channel.send({})\n", + " if (message.buffers) {\n", + " for (const buffer of message.buffers) {\n", + " buffers.push(buffer);\n", + " downloaded += buffer.byteLength;\n", + " progress.value = downloaded;\n", + " }\n", + " }\n", + " }\n", + " const blob = new Blob(buffers, {type: 'application/binary'});\n", + " const a = document.createElement('a');\n", + " a.href = window.URL.createObjectURL(blob);\n", + " a.download = filename;\n", + " div.appendChild(a);\n", + " a.click();\n", + " div.remove();\n", + " }\n", + " " + ], "text/plain": [ "" ] @@ -759,7 +825,9 @@ }, { "data": { - "application/javascript": "download(\"download_aab82d58-53a1-40c6-be64-e5bb8ff671f5\", \"vulnerability_report_BULK.csv\", 9660)", + "application/javascript": [ + "download(\"download_aab82d58-53a1-40c6-be64-e5bb8ff671f5\", \"vulnerability_report_BULK.csv\", 9660)" + ], "text/plain": [ "" ] @@ -814,7 +882,49 @@ "outputs": [ { "data": { - "application/javascript": "\n async function download(id, filename, size) {\n if (!google.colab.kernel.accessAllowed) {\n return;\n }\n const div = document.createElement('div');\n const label = document.createElement('label');\n label.textContent = `Downloading \"${filename}\": `;\n div.appendChild(label);\n const progress = document.createElement('progress');\n progress.max = size;\n div.appendChild(progress);\n document.body.appendChild(div);\n\n const buffers = [];\n let downloaded = 0;\n\n const channel = await google.colab.kernel.comms.open(id);\n // Send a message to notify the kernel that we're ready.\n channel.send({})\n\n for await (const message of channel.messages) {\n // Send a message to notify the kernel that we're ready.\n channel.send({})\n if (message.buffers) {\n for (const buffer of message.buffers) {\n buffers.push(buffer);\n downloaded += buffer.byteLength;\n progress.value = downloaded;\n }\n }\n }\n const blob = new Blob(buffers, {type: 'application/binary'});\n const a = document.createElement('a');\n a.href = window.URL.createObjectURL(blob);\n a.download = filename;\n div.appendChild(a);\n a.click();\n div.remove();\n }\n ", + "application/javascript": [ + "\n", + " async function download(id, filename, size) {\n", + " if (!google.colab.kernel.accessAllowed) {\n", + " return;\n", + " }\n", + " const div = document.createElement('div');\n", + " const label = document.createElement('label');\n", + " label.textContent = `Downloading \"${filename}\": `;\n", + " div.appendChild(label);\n", + " const progress = document.createElement('progress');\n", + " progress.max = size;\n", + " div.appendChild(progress);\n", + " document.body.appendChild(div);\n", + "\n", + " const buffers = [];\n", + " let downloaded = 0;\n", + "\n", + " const channel = await google.colab.kernel.comms.open(id);\n", + " // Send a message to notify the kernel that we're ready.\n", + " channel.send({})\n", + "\n", + " for await (const message of channel.messages) {\n", + " // Send a message to notify the kernel that we're ready.\n", + " channel.send({})\n", + " if (message.buffers) {\n", + " for (const buffer of message.buffers) {\n", + " buffers.push(buffer);\n", + " downloaded += buffer.byteLength;\n", + " progress.value = downloaded;\n", + " }\n", + " }\n", + " }\n", + " const blob = new Blob(buffers, {type: 'application/binary'});\n", + " const a = document.createElement('a');\n", + " a.href = window.URL.createObjectURL(blob);\n", + " a.download = filename;\n", + " div.appendChild(a);\n", + " a.click();\n", + " div.remove();\n", + " }\n", + " " + ], "text/plain": [ "" ] @@ -824,7 +934,9 @@ }, { "data": { - "application/javascript": "download(\"download_7ee96007-491b-4a8f-b52a-6b7d5e63e4b7\", \"vulnerabilities.json\", 11541)", + "application/javascript": [ + "download(\"download_7ee96007-491b-4a8f-b52a-6b7d5e63e4b7\", \"vulnerabilities.json\", 11541)" + ], "text/plain": [ "" ] diff --git a/gemini/use-cases/data-augmentation/data_augmentation_for_text.ipynb b/gemini/use-cases/data-augmentation/data_augmentation_for_text.ipynb index 635937d3ae1..a093c454c86 100644 --- a/gemini/use-cases/data-augmentation/data_augmentation_for_text.ipynb +++ b/gemini/use-cases/data-augmentation/data_augmentation_for_text.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/data-generation/synthetic_data_generation_using_gemini.ipynb b/gemini/use-cases/data-generation/synthetic_data_generation_using_gemini.ipynb index c7f5974a3ff..e46fc58e810 100644 --- a/gemini/use-cases/data-generation/synthetic_data_generation_using_gemini.ipynb +++ b/gemini/use-cases/data-generation/synthetic_data_generation_using_gemini.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/document-processing/doc_parsing_with_llamaindex_and_llamaparse.ipynb b/gemini/use-cases/document-processing/doc_parsing_with_llamaindex_and_llamaparse.ipynb index 35dd63d99c0..2040ead1e40 100644 --- a/gemini/use-cases/document-processing/doc_parsing_with_llamaindex_and_llamaparse.ipynb +++ b/gemini/use-cases/document-processing/doc_parsing_with_llamaindex_and_llamaparse.ipynb @@ -28,7 +28,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/document-processing/document_processing.ipynb b/gemini/use-cases/document-processing/document_processing.ipynb index 319c57c7ae3..17283cd8a49 100644 --- a/gemini/use-cases/document-processing/document_processing.ipynb +++ b/gemini/use-cases/document-processing/document_processing.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/document-processing/sheet_music.ipynb b/gemini/use-cases/document-processing/sheet_music.ipynb index ee226a14062..471a2fc9df5 100644 --- a/gemini/use-cases/document-processing/sheet_music.ipynb +++ b/gemini/use-cases/document-processing/sheet_music.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/education/ai_quick_build_experience_backend.ipynb b/gemini/use-cases/education/ai_quick_build_experience_backend.ipynb index e4a87850e26..7668d6042dc 100644 --- a/gemini/use-cases/education/ai_quick_build_experience_backend.ipynb +++ b/gemini/use-cases/education/ai_quick_build_experience_backend.ipynb @@ -54,7 +54,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/education/use_cases_for_education.ipynb b/gemini/use-cases/education/use_cases_for_education.ipynb index 1d37abe5f23..c24cf2b30be 100644 --- a/gemini/use-cases/education/use_cases_for_education.ipynb +++ b/gemini/use-cases/education/use_cases_for_education.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/healthcare/react_gemini_healthcare_api.ipynb b/gemini/use-cases/healthcare/react_gemini_healthcare_api.ipynb index 2bc5a54edf3..3074dfc4a30 100644 --- a/gemini/use-cases/healthcare/react_gemini_healthcare_api.ipynb +++ b/gemini/use-cases/healthcare/react_gemini_healthcare_api.ipynb @@ -59,7 +59,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/intro_multimodal_use_cases.ipynb b/gemini/use-cases/intro_multimodal_use_cases.ipynb index 69f91b77e8f..7510c81dd70 100644 --- a/gemini/use-cases/intro_multimodal_use_cases.ipynb +++ b/gemini/use-cases/intro_multimodal_use_cases.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/marketing/creative_content_generation.ipynb b/gemini/use-cases/marketing/creative_content_generation.ipynb index bc5b8e11fdc..e0616eb5dbc 100644 --- a/gemini/use-cases/marketing/creative_content_generation.ipynb +++ b/gemini/use-cases/marketing/creative_content_generation.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/multimodal_use_cases_workshop.ipynb b/gemini/use-cases/multimodal_use_cases_workshop.ipynb index 08cd63ad89e..15c9d245630 100644 --- a/gemini/use-cases/multimodal_use_cases_workshop.ipynb +++ b/gemini/use-cases/multimodal_use_cases_workshop.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/retail/multimodal_retail_recommendations.ipynb b/gemini/use-cases/retail/multimodal_retail_recommendations.ipynb index 5ac9f9c4f16..8e7021a58a1 100644 --- a/gemini/use-cases/retail/multimodal_retail_recommendations.ipynb +++ b/gemini/use-cases/retail/multimodal_retail_recommendations.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/retail/product_attributes_extraction.ipynb b/gemini/use-cases/retail/product_attributes_extraction.ipynb index 94287f10626..f1a8a43b161 100644 --- a/gemini/use-cases/retail/product_attributes_extraction.ipynb +++ b/gemini/use-cases/retail/product_attributes_extraction.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retail/product_image_background_generation.ipynb b/gemini/use-cases/retail/product_image_background_generation.ipynb index 1ec5f13b7f3..4b8b957c8b2 100644 --- a/gemini/use-cases/retail/product_image_background_generation.ipynb +++ b/gemini/use-cases/retail/product_image_background_generation.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/retail/product_listing_generation.ipynb b/gemini/use-cases/retail/product_listing_generation.ipynb index dea55b8e039..b690554fbbb 100644 --- a/gemini/use-cases/retail/product_listing_generation.ipynb +++ b/gemini/use-cases/retail/product_listing_generation.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/Document_QnA_using_gemini_and_vector_search.ipynb b/gemini/use-cases/retrieval-augmented-generation/Document_QnA_using_gemini_and_vector_search.ipynb index e5a2db95212..affd8792e83 100644 --- a/gemini/use-cases/retrieval-augmented-generation/Document_QnA_using_gemini_and_vector_search.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/Document_QnA_using_gemini_and_vector_search.ipynb @@ -29,7 +29,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/NLP2SQL_using_dynamic_RAG.ipynb b/gemini/use-cases/retrieval-augmented-generation/NLP2SQL_using_dynamic_RAG.ipynb index 7d489cb754b..52ca582b183 100644 --- a/gemini/use-cases/retrieval-augmented-generation/NLP2SQL_using_dynamic_RAG.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/NLP2SQL_using_dynamic_RAG.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/RAG_Based_on_Sensitive_Data_Protection_using_Faker.ipynb b/gemini/use-cases/retrieval-augmented-generation/RAG_Based_on_Sensitive_Data_Protection_using_Faker.ipynb index 9c5b852caef..6a9247239ba 100644 --- a/gemini/use-cases/retrieval-augmented-generation/RAG_Based_on_Sensitive_Data_Protection_using_Faker.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/RAG_Based_on_Sensitive_Data_Protection_using_Faker.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/code_rag.ipynb b/gemini/use-cases/retrieval-augmented-generation/code_rag.ipynb index 16440cabe53..fa9ac51985c 100644 --- a/gemini/use-cases/retrieval-augmented-generation/code_rag.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/code_rag.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/intra_knowledge_qna.ipynb b/gemini/use-cases/retrieval-augmented-generation/intra_knowledge_qna.ipynb index e8eaeb96bd7..554042a2a0a 100644 --- a/gemini/use-cases/retrieval-augmented-generation/intra_knowledge_qna.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/intra_knowledge_qna.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/intro_multimodal_rag.ipynb b/gemini/use-cases/retrieval-augmented-generation/intro_multimodal_rag.ipynb index 043dfc560b2..36fbe482031 100644 --- a/gemini/use-cases/retrieval-augmented-generation/intro_multimodal_rag.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/intro_multimodal_rag.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/llamaindex_rag.ipynb b/gemini/use-cases/retrieval-augmented-generation/llamaindex_rag.ipynb index 510e6dddb8f..5aaa6aeda73 100644 --- a/gemini/use-cases/retrieval-augmented-generation/llamaindex_rag.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/llamaindex_rag.ipynb @@ -29,7 +29,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/multimodal_rag_langchain.ipynb b/gemini/use-cases/retrieval-augmented-generation/multimodal_rag_langchain.ipynb index 255fa648d3f..2244007bcf1 100644 --- a/gemini/use-cases/retrieval-augmented-generation/multimodal_rag_langchain.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/multimodal_rag_langchain.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/rag-evaluation/deepeval_with_gemini.ipynb b/gemini/use-cases/retrieval-augmented-generation/rag-evaluation/deepeval_with_gemini.ipynb index 81bc77482e2..51c304fbcd8 100644 --- a/gemini/use-cases/retrieval-augmented-generation/rag-evaluation/deepeval_with_gemini.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/rag-evaluation/deepeval_with_gemini.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/rag-evaluation/ragas_with_gemini.ipynb b/gemini/use-cases/retrieval-augmented-generation/rag-evaluation/ragas_with_gemini.ipynb index d3a90ac0b6a..432fefff7c9 100644 --- a/gemini/use-cases/retrieval-augmented-generation/rag-evaluation/ragas_with_gemini.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/rag-evaluation/ragas_with_gemini.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/rag_embeddings_and_index_with_alloydb.ipynb b/gemini/use-cases/retrieval-augmented-generation/rag_embeddings_and_index_with_alloydb.ipynb index 7320faf3612..d245424fb09 100644 --- a/gemini/use-cases/retrieval-augmented-generation/rag_embeddings_and_index_with_alloydb.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/rag_embeddings_and_index_with_alloydb.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/rag_qna_with_bq_and_featurestore.ipynb b/gemini/use-cases/retrieval-augmented-generation/rag_qna_with_bq_and_featurestore.ipynb index c1f633c9a3b..514382323d8 100644 --- a/gemini/use-cases/retrieval-augmented-generation/rag_qna_with_bq_and_featurestore.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/rag_qna_with_bq_and_featurestore.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/rag_vector_embedding_in_bigquery.ipynb b/gemini/use-cases/retrieval-augmented-generation/rag_vector_embedding_in_bigquery.ipynb index 9f001a30e26..0c1a2591611 100644 --- a/gemini/use-cases/retrieval-augmented-generation/rag_vector_embedding_in_bigquery.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/rag_vector_embedding_in_bigquery.ipynb @@ -66,7 +66,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/rag_with_bigquery.ipynb b/gemini/use-cases/retrieval-augmented-generation/rag_with_bigquery.ipynb index 463ee15e0db..b049ba20ed2 100644 --- a/gemini/use-cases/retrieval-augmented-generation/rag_with_bigquery.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/rag_with_bigquery.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/retail_warranty_claim_chatbot.ipynb b/gemini/use-cases/retrieval-augmented-generation/retail_warranty_claim_chatbot.ipynb index bce970047a4..3f935b11ce1 100644 --- a/gemini/use-cases/retrieval-augmented-generation/retail_warranty_claim_chatbot.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/retail_warranty_claim_chatbot.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/retrieval-augmented-generation/small_to_big_rag/small_to_big_rag.ipynb b/gemini/use-cases/retrieval-augmented-generation/small_to_big_rag/small_to_big_rag.ipynb index 2ee89742951..9490e7583d2 100644 --- a/gemini/use-cases/retrieval-augmented-generation/small_to_big_rag/small_to_big_rag.ipynb +++ b/gemini/use-cases/retrieval-augmented-generation/small_to_big_rag/small_to_big_rag.ipynb @@ -29,7 +29,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/gemini/use-cases/video-analysis/video_analysis.ipynb b/gemini/use-cases/video-analysis/video_analysis.ipynb index 21bf962d909..06130664ff3 100644 --- a/gemini/use-cases/video-analysis/video_analysis.ipynb +++ b/gemini/use-cases/video-analysis/video_analysis.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/gemini/use-cases/video-analysis/youtube_video_analysis.ipynb b/gemini/use-cases/video-analysis/youtube_video_analysis.ipynb index 515fda4102b..ddf7b9ba8e9 100644 --- a/gemini/use-cases/video-analysis/youtube_video_analysis.ipynb +++ b/gemini/use-cases/video-analysis/youtube_video_analysis.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/code/code_chat.ipynb b/language/code/code_chat.ipynb index e08587b3fa7..071b273a107 100644 --- a/language/code/code_chat.ipynb +++ b/language/code/code_chat.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/code/code_completion.ipynb b/language/code/code_completion.ipynb index 32c687879d1..a3cced7d3a6 100644 --- a/language/code/code_completion.ipynb +++ b/language/code/code_completion.ipynb @@ -48,7 +48,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/code/code_generation.ipynb b/language/code/code_generation.ipynb index 60bb7e833a9..39b4b134771 100644 --- a/language/code/code_generation.ipynb +++ b/language/code/code_generation.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/code/code_retrieval_augmented_generation.ipynb b/language/code/code_retrieval_augmented_generation.ipynb index 7604d63d5a3..9b13cc43825 100644 --- a/language/code/code_retrieval_augmented_generation.ipynb +++ b/language/code/code_retrieval_augmented_generation.ipynb @@ -54,7 +54,31 @@ " \"Vertex
Open in Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/getting-started/intro_palm_api.ipynb b/language/getting-started/intro_palm_api.ipynb index 540c67b6aef..46e8adc714d 100644 --- a/language/getting-started/intro_palm_api.ipynb +++ b/language/getting-started/intro_palm_api.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/grounding/intro-grounding.ipynb b/language/grounding/intro-grounding.ipynb index bc393e135f1..0fde5ed2b0f 100644 --- a/language/grounding/intro-grounding.ipynb +++ b/language/grounding/intro-grounding.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/migration/PaLM_to_gemini_codemigration.ipynb b/language/migration/PaLM_to_gemini_codemigration.ipynb index fc5cbd63a3a..8aab8f79627 100644 --- a/language/migration/PaLM_to_gemini_codemigration.ipynb +++ b/language/migration/PaLM_to_gemini_codemigration.ipynb @@ -53,7 +53,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/orchestration/langchain/intro_langchain_palm_api.ipynb b/language/orchestration/langchain/intro_langchain_palm_api.ipynb index 57e7b6e35d8..a38eb8c70e0 100644 --- a/language/orchestration/langchain/intro_langchain_palm_api.ipynb +++ b/language/orchestration/langchain/intro_langchain_palm_api.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/orchestration/langchain/langchain_bigquery_data_loader.ipynb b/language/orchestration/langchain/langchain_bigquery_data_loader.ipynb index b1b85ddd538..f036b7b882a 100644 --- a/language/orchestration/langchain/langchain_bigquery_data_loader.ipynb +++ b/language/orchestration/langchain/langchain_bigquery_data_loader.ipynb @@ -59,7 +59,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/prompts/examples/chain_of_thought_react.ipynb b/language/prompts/examples/chain_of_thought_react.ipynb index 64743e7260a..1a407252685 100644 --- a/language/prompts/examples/chain_of_thought_react.ipynb +++ b/language/prompts/examples/chain_of_thought_react.ipynb @@ -56,7 +56,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/prompts/examples/ideation.ipynb b/language/prompts/examples/ideation.ipynb index aeb65f4d783..0f3ae371dd9 100644 --- a/language/prompts/examples/ideation.ipynb +++ b/language/prompts/examples/ideation.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/prompts/examples/question_answering.ipynb b/language/prompts/examples/question_answering.ipynb index e172ca4b7b2..c6eaa77d8cd 100644 --- a/language/prompts/examples/question_answering.ipynb +++ b/language/prompts/examples/question_answering.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/prompts/examples/text_classification.ipynb b/language/prompts/examples/text_classification.ipynb index 9defe86d9e7..50b9fe22c5e 100644 --- a/language/prompts/examples/text_classification.ipynb +++ b/language/prompts/examples/text_classification.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/prompts/examples/text_extraction.ipynb b/language/prompts/examples/text_extraction.ipynb index a69ab83861d..b275871bcc6 100644 --- a/language/prompts/examples/text_extraction.ipynb +++ b/language/prompts/examples/text_extraction.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/prompts/examples/text_summarization.ipynb b/language/prompts/examples/text_summarization.ipynb index afc4519b88b..544c7e172ae 100644 --- a/language/prompts/examples/text_summarization.ipynb +++ b/language/prompts/examples/text_summarization.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/prompts/intro_prompt_design.ipynb b/language/prompts/intro_prompt_design.ipynb index fcc8e010626..790aa81b23e 100644 --- a/language/prompts/intro_prompt_design.ipynb +++ b/language/prompts/intro_prompt_design.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/translation/intro_translation.ipynb b/language/translation/intro_translation.ipynb index efaba39baac..1996ed1a7c4 100644 --- a/language/translation/intro_translation.ipynb +++ b/language/translation/intro_translation.ipynb @@ -47,7 +47,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/translation/translation_training_data_tsv_generator.ipynb b/language/translation/translation_training_data_tsv_generator.ipynb index 227d525fcf8..5759abd47f4 100644 --- a/language/translation/translation_training_data_tsv_generator.ipynb +++ b/language/translation/translation_training_data_tsv_generator.ipynb @@ -49,7 +49,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/tuning/distilling_step_by_step/distilling_step_by_step.ipynb b/language/tuning/distilling_step_by_step/distilling_step_by_step.ipynb index 35b69c30e72..73322d7f305 100644 --- a/language/tuning/distilling_step_by_step/distilling_step_by_step.ipynb +++ b/language/tuning/distilling_step_by_step/distilling_step_by_step.ipynb @@ -26,7 +26,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/tuning/tuning_text_bison.ipynb b/language/tuning/tuning_text_bison.ipynb index ecfee3626f6..c0989a699a5 100644 --- a/language/tuning/tuning_text_bison.ipynb +++ b/language/tuning/tuning_text_bison.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/applying-llms-to-data/bigquery_dataframes_llm_code_generation.ipynb b/language/use-cases/applying-llms-to-data/bigquery_dataframes_llm_code_generation.ipynb index 6cae25eda64..a69d79d3464 100644 --- a/language/use-cases/applying-llms-to-data/bigquery_dataframes_llm_code_generation.ipynb +++ b/language/use-cases/applying-llms-to-data/bigquery_dataframes_llm_code_generation.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/use-cases/applying-llms-to-data/bigquery_dataframes_ml_drug_name_generation.ipynb b/language/use-cases/applying-llms-to-data/bigquery_dataframes_ml_drug_name_generation.ipynb index 2dc39094791..68cc34c190b 100644 --- a/language/use-cases/applying-llms-to-data/bigquery_dataframes_ml_drug_name_generation.ipynb +++ b/language/use-cases/applying-llms-to-data/bigquery_dataframes_ml_drug_name_generation.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/use-cases/applying-llms-to-data/bigquery_ml_llm.ipynb b/language/use-cases/applying-llms-to-data/bigquery_ml_llm.ipynb index cc13799db5d..ed27174aad9 100644 --- a/language/use-cases/applying-llms-to-data/bigquery_ml_llm.ipynb +++ b/language/use-cases/applying-llms-to-data/bigquery_ml_llm.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/use-cases/chatbots/grocerybot_assistant.ipynb b/language/use-cases/chatbots/grocerybot_assistant.ipynb index 1d217d124be..43c6de1c2b5 100644 --- a/language/use-cases/chatbots/grocerybot_assistant.ipynb +++ b/language/use-cases/chatbots/grocerybot_assistant.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/description-generation/product_description_generator_attributes_to_text.ipynb b/language/use-cases/description-generation/product_description_generator_attributes_to_text.ipynb index d6cabe4c388..3fba4b5ae86 100644 --- a/language/use-cases/description-generation/product_description_generator_attributes_to_text.ipynb +++ b/language/use-cases/description-generation/product_description_generator_attributes_to_text.ipynb @@ -50,7 +50,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/description-generation/product_description_generator_image.ipynb b/language/use-cases/description-generation/product_description_generator_image.ipynb index c1b8f35b4d8..155e97eb00b 100644 --- a/language/use-cases/description-generation/product_description_generator_image.ipynb +++ b/language/use-cases/description-generation/product_description_generator_image.ipynb @@ -50,7 +50,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/document-qa/question_answering_documentai_vector_store_palm.ipynb b/language/use-cases/document-qa/question_answering_documentai_vector_store_palm.ipynb index 65508796f39..3b5af87aa2b 100644 --- a/language/use-cases/document-qa/question_answering_documentai_vector_store_palm.ipynb +++ b/language/use-cases/document-qa/question_answering_documentai_vector_store_palm.ipynb @@ -50,7 +50,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/document-qa/question_answering_documents.ipynb b/language/use-cases/document-qa/question_answering_documents.ipynb index 99aeaf02595..cc89303df40 100644 --- a/language/use-cases/document-qa/question_answering_documents.ipynb +++ b/language/use-cases/document-qa/question_answering_documents.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/document-qa/question_answering_documents_langchain.ipynb b/language/use-cases/document-qa/question_answering_documents_langchain.ipynb index 1458fdff7fb..dc29c182836 100644 --- a/language/use-cases/document-qa/question_answering_documents_langchain.ipynb +++ b/language/use-cases/document-qa/question_answering_documents_langchain.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/document-qa/question_answering_documents_langchain_matching_engine.ipynb b/language/use-cases/document-qa/question_answering_documents_langchain_matching_engine.ipynb index 7a968b54bf3..ac6c0b9e467 100644 --- a/language/use-cases/document-qa/question_answering_documents_langchain_matching_engine.ipynb +++ b/language/use-cases/document-qa/question_answering_documents_langchain_matching_engine.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/document-summarization/summarization_large_documents.ipynb b/language/use-cases/document-summarization/summarization_large_documents.ipynb index c201f5f38e3..9138507aabd 100644 --- a/language/use-cases/document-summarization/summarization_large_documents.ipynb +++ b/language/use-cases/document-summarization/summarization_large_documents.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/document-summarization/summarization_large_documents_langchain.ipynb b/language/use-cases/document-summarization/summarization_large_documents_langchain.ipynb index 29f21248623..25799b39797 100644 --- a/language/use-cases/document-summarization/summarization_large_documents_langchain.ipynb +++ b/language/use-cases/document-summarization/summarization_large_documents_langchain.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/document-summarization/summarization_with_documentai.ipynb b/language/use-cases/document-summarization/summarization_with_documentai.ipynb index f65dcf1613a..485934d766d 100644 --- a/language/use-cases/document-summarization/summarization_with_documentai.ipynb +++ b/language/use-cases/document-summarization/summarization_with_documentai.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/language/use-cases/marketing-image-overlay/marketing_image_overlay.ipynb b/language/use-cases/marketing-image-overlay/marketing_image_overlay.ipynb index 829a78a6230..773e0a12774 100644 --- a/language/use-cases/marketing-image-overlay/marketing_image_overlay.ipynb +++ b/language/use-cases/marketing-image-overlay/marketing_image_overlay.ipynb @@ -54,7 +54,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/use-cases/sensitive-data-detection/context_aware_sensitive_data_detection.ipynb b/language/use-cases/sensitive-data-detection/context_aware_sensitive_data_detection.ipynb index 21d552ad3d8..918e3c7b558 100644 --- a/language/use-cases/sensitive-data-detection/context_aware_sensitive_data_detection.ipynb +++ b/language/use-cases/sensitive-data-detection/context_aware_sensitive_data_detection.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/use-cases/sql-code-generation/sql_code_generation.ipynb b/language/use-cases/sql-code-generation/sql_code_generation.ipynb index d447d8ea742..5aa5ede07fe 100644 --- a/language/use-cases/sql-code-generation/sql_code_generation.ipynb +++ b/language/use-cases/sql-code-generation/sql_code_generation.ipynb @@ -59,7 +59,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/language/use-cases/sql-code-generation/sql_code_generation_langchain.ipynb b/language/use-cases/sql-code-generation/sql_code_generation_langchain.ipynb index 2179adcb3ee..5e926376a8e 100644 --- a/language/use-cases/sql-code-generation/sql_code_generation_langchain.ipynb +++ b/language/use-cases/sql-code-generation/sql_code_generation_langchain.ipynb @@ -59,7 +59,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/open-models/fine-tuning/vertex_ai_trl_fine_tuning_gemma.ipynb b/open-models/fine-tuning/vertex_ai_trl_fine_tuning_gemma.ipynb index 6f30539c5d0..fd83633c763 100644 --- a/open-models/fine-tuning/vertex_ai_trl_fine_tuning_gemma.ipynb +++ b/open-models/fine-tuning/vertex_ai_trl_fine_tuning_gemma.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/open-models/serving/cloud_run_ollama_gemma2_rag_qa.ipynb b/open-models/serving/cloud_run_ollama_gemma2_rag_qa.ipynb index fb684c374b7..0abe5a50f5f 100644 --- a/open-models/serving/cloud_run_ollama_gemma2_rag_qa.ipynb +++ b/open-models/serving/cloud_run_ollama_gemma2_rag_qa.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/open-models/serving/vertex_ai_text_generation_inference_gemma.ipynb b/open-models/serving/vertex_ai_text_generation_inference_gemma.ipynb index 35fca62a03d..65451bb1263 100644 --- a/open-models/serving/vertex_ai_text_generation_inference_gemma.ipynb +++ b/open-models/serving/vertex_ai_text_generation_inference_gemma.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/partner-models/claude/claude_multimodal_function_calling.ipynb b/partner-models/claude/claude_multimodal_function_calling.ipynb index 7a2b539679d..3d619cc713f 100644 --- a/partner-models/claude/claude_multimodal_function_calling.ipynb +++ b/partner-models/claude/claude_multimodal_function_calling.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/search/bulk-question-answering/bulk_question_answering.ipynb b/search/bulk-question-answering/bulk_question_answering.ipynb index 1276edadbe1..cfa5757b61b 100644 --- a/search/bulk-question-answering/bulk_question_answering.ipynb +++ b/search/bulk-question-answering/bulk_question_answering.ipynb @@ -27,7 +27,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/search/create_datastore_and_search.ipynb b/search/create_datastore_and_search.ipynb index 5ca793daa37..b2c492ba76d 100644 --- a/search/create_datastore_and_search.ipynb +++ b/search/create_datastore_and_search.ipynb @@ -1,511 +1,533 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "829cc6c6-f8c3-4fc6-942b-f698be5fa1a2" - }, - "source": [ - "# Create a Vertex AI Datastore and Search Engine\n", - "\n", - "\n", - "\n", - " \n", - " \n", - " \n", - "
\n", - " \n", - " \"Colab Run in Colab\n", - " \n", - " \n", - " \n", - " \"GitHub\n", - " View on GitHub\n", - " \n", - " \n", - " \n", - " \"Vertex\n", - " Open in Vertex AI Workbench\n", - " \n", - "
" - ] + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "829cc6c6-f8c3-4fc6-942b-f698be5fa1a2" + }, + "source": [ + "# Create a Vertex AI Datastore and Search Engine\n", + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \"Colab Run in Colab\n", + " \n", + " \n", + " \n", + " \"GitHub\n", + " View on GitHub\n", + " \n", + " \n", + " \n", + " \"Vertex\n", + " Open in Vertex AI Workbench\n", + " \n", + "
\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0460bdbe-05db-42f8-822c-82195de8329a" + }, + "source": [ + "---\n", + "\n", + "* Author(s): [Kara Greenfield](https://github.com/kgreenfield2)\n", + "* Created: 22 Nov 2023\n", + "* Updated: 31 Oct 2024\n", + "\n", + "---\n", + "\n", + "## Objective\n", + "\n", + "This notebook shows how to create and populate a Vertex AI Search Datastore, how to create a search app connected to that datastore, and how to submit queries through the search engine.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0b4b1050-7113-487e-aeaf-55690c831a1d" + }, + "source": [ + "Services used in the notebook:\n", + "\n", + "- ✅ Vertex AI Search for document search and retrieval" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "43828625-a130-449c-ba5f-6a948220f559" + }, + "source": [ + "## Install pre-requisites\n", + "\n", + "If running in Colab install the pre-requisites into the runtime. Otherwise it is assumed that the notebook is running in Vertex AI Workbench." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "8ea5db8a-dccc-4442-b5d7-7088d5ffb5ac" + }, + "outputs": [], + "source": [ + "%pip install --upgrade --user -q google-cloud-discoveryengine" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "10f9e321" + }, + "source": [ + "### Restart current runtime\n", + "\n", + "To use the newly installed packages in this Jupyter runtime, you must restart the runtime. You can do this by running the cell below, which will restart the current kernel." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "da755736" + }, + "outputs": [], + "source": [ + "# Restart kernel after installs so that your environment can access the new packages\n", + "\n", + "import IPython\n", + "\n", + "app = IPython.Application.instance()\n", + "app.kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "9c31dbe0" + }, + "source": [ + "
\n", + "⚠️ The kernel is going to restart. Please wait until it is finished before continuing to the next step. ⚠️\n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5f6a5de5-156e-4f14-99e6-3ab33e076c81" + }, + "source": [ + "## Authenticate\n", + "\n", + "If running in Colab authenticate with `google.colab.google.auth` otherwise assume that running on Vertex AI Workbench." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "df3b7309-c51c-44a0-a466-b0b2733e0c28" + }, + "outputs": [], + "source": [ + "import sys\n", + "\n", + "if \"google.colab\" in sys.modules:\n", + " from google.colab import auth\n", + "\n", + " auth.authenticate_user()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ae7a4925-145a-40f3-9fa1-3b69a42d488d" + }, + "source": [ + "## Configure notebook environment" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "389b9e51-1ce4-4bdf-80b5-fcdc1882f853" + }, + "outputs": [], + "source": [ + "from google.api_core.client_options import ClientOptions\n", + "from google.cloud import discoveryengine\n", + "\n", + "PROJECT_ID = \"YOUR_PROJECT_ID\" # @param {type:\"string\"}\n", + "LOCATION = \"global\"" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "HjoerqoksBdx" + }, + "source": [ + "Set [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "s-jH2yG1rtxn" + }, + "outputs": [], + "source": [ + "!gcloud auth application-default login --project {PROJECT_ID}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "07f1aecd-4633-4451-b5a7-1f26e4cb2631" + }, + "source": [ + "## Create and Populate a Datastore" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "9a1d0021-e299-49d4-a657-2e101ae49eb6" + }, + "outputs": [], + "source": [ + "def create_data_store(\n", + " project_id: str, location: str, data_store_name: str, data_store_id: str\n", + "):\n", + " # Create a client\n", + " client_options = (\n", + " ClientOptions(api_endpoint=f\"{location}-discoveryengine.googleapis.com\")\n", + " if location != \"global\"\n", + " else None\n", + " )\n", + " client = discoveryengine.DataStoreServiceClient(client_options=client_options)\n", + "\n", + " # Initialize request argument(s)\n", + " data_store = discoveryengine.DataStore(\n", + " display_name=data_store_name,\n", + " industry_vertical=discoveryengine.IndustryVertical.GENERIC,\n", + " content_config=discoveryengine.DataStore.ContentConfig.CONTENT_REQUIRED,\n", + " )\n", + "\n", + " operation = client.create_data_store(\n", + " request=discoveryengine.CreateDataStoreRequest(\n", + " parent=client.collection_path(project_id, location, \"default_collection\"),\n", + " data_store=data_store,\n", + " data_store_id=data_store_id,\n", + " )\n", + " )\n", + "\n", + " # Make the request\n", + " # The try block is necessary to prevent execution from halting due to an error being thrown when the datastore takes a while to instantiate\n", + " try:\n", + " response = operation.result(timeout=90)\n", + " except:\n", + " print(\"long-running operation error.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "8a4db726-8da1-4c76-8934-944aaf5f9b53" + }, + "outputs": [], + "source": [ + "# The datastore name can only contain lowercase letters, numbers, and hyphens\n", + "DATASTORE_NAME = \"alphabet-contracts\"\n", + "DATASTORE_ID = f\"{DATASTORE_NAME}-id\"\n", + "\n", + "create_data_store(PROJECT_ID, LOCATION, DATASTORE_NAME, DATASTORE_ID)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "03121270-5d2f-403b-81ea-c1d241357bd1" + }, + "outputs": [], + "source": [ + "def import_documents(\n", + " project_id: str,\n", + " location: str,\n", + " data_store_id: str,\n", + " gcs_uri: str,\n", + "):\n", + " # Create a client\n", + " client_options = (\n", + " ClientOptions(api_endpoint=f\"{location}-discoveryengine.googleapis.com\")\n", + " if location != \"global\"\n", + " else None\n", + " )\n", + " client = discoveryengine.DocumentServiceClient(client_options=client_options)\n", + "\n", + " # The full resource name of the search engine branch.\n", + " # e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}\n", + " parent = client.branch_path(\n", + " project=project_id,\n", + " location=location,\n", + " data_store=data_store_id,\n", + " branch=\"default_branch\",\n", + " )\n", + "\n", + " source_documents = [f\"{gcs_uri}/*\"]\n", + "\n", + " request = discoveryengine.ImportDocumentsRequest(\n", + " parent=parent,\n", + " gcs_source=discoveryengine.GcsSource(\n", + " input_uris=source_documents, data_schema=\"content\"\n", + " ),\n", + " # Options: `FULL`, `INCREMENTAL`\n", + " reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,\n", + " )\n", + "\n", + " # Make the request\n", + " operation = client.import_documents(request=request)\n", + "\n", + " response = operation.result()\n", + "\n", + " # Once the operation is complete,\n", + " # get information from operation metadata\n", + " metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)\n", + "\n", + " # Handle the response\n", + " return operation.operation.name" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "1ddfe66a-acb4-4fdb-b9ed-76a332bb0f0c" + }, + "outputs": [], + "source": [ + "source_documents_gs_uri = (\n", + " \"gs://cloud-samples-data/gen-app-builder/search/alphabet-investor-pdfs\"\n", + ")\n", + "\n", + "import_documents(PROJECT_ID, LOCATION, DATASTORE_ID, source_documents_gs_uri)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7a957202-b67e-47ca-84c3-b8a62cfbe405" + }, + "source": [ + "## Create a Search Engine\n", + "\n", + "This is used to set the `search_tier` to enterprise and to enable advanced LLM features.\n", + "\n", + "Enterprise tier is required to get extractive answers from a search query and advanced LLM features are required to summarize search results." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "0e39e9bb-f381-44f6-a45e-3322669a171f" + }, + "outputs": [], + "source": [ + "def create_engine(\n", + " project_id: str, location: str, engine_name: str, engine_id: str, data_store_id: str\n", + "):\n", + " # Create a client\n", + " client_options = (\n", + " ClientOptions(api_endpoint=f\"{location}-discoveryengine.googleapis.com\")\n", + " if location != \"global\"\n", + " else None\n", + " )\n", + " client = discoveryengine.EngineServiceClient(client_options=client_options)\n", + "\n", + " # Initialize request argument(s)\n", + " engine = discoveryengine.Engine(\n", + " display_name=engine_name,\n", + " solution_type=discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH,\n", + " industry_vertical=discoveryengine.IndustryVertical.GENERIC,\n", + " data_store_ids=[data_store_id],\n", + " search_engine_config=discoveryengine.Engine.SearchEngineConfig(\n", + " search_tier=discoveryengine.SearchTier.SEARCH_TIER_ENTERPRISE,\n", + " search_add_ons=[discoveryengine.SearchAddOn.SEARCH_ADD_ON_LLM],\n", + " ),\n", + " )\n", + "\n", + " request = discoveryengine.CreateEngineRequest(\n", + " parent=client.collection_path(project_id, location, \"default_collection\"),\n", + " engine=engine,\n", + " engine_id=engine.display_name,\n", + " )\n", + "\n", + " # Make the request\n", + " operation = client.create_engine(request=request)\n", + " response = operation.result(timeout=90)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "id": "4a853982-8c2e-402a-a808-5364bf932619" + }, + "outputs": [], + "source": [ + "ENGINE_NAME = DATASTORE_NAME\n", + "ENGINE_ID = DATASTORE_ID\n", + "create_engine(PROJECT_ID, LOCATION, ENGINE_NAME, ENGINE_ID, DATASTORE_ID)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "e9f4d978-9164-4de3-b01a-179051706313" + }, + "source": [ + "## Query your Search Engine\n", + "\n", + "Note: The Engine will take some time to be ready to query.\n", + "\n", + "If you recently created an engine and you receive an error similar to:\n", + "\n", + "`404 Engine {ENGINE_NAME} is not found`\n", + "\n", + "Then wait a few minutes and try your query again." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "id": "1c4dfb62-7846-43d0-9cba-fd8886ce5546" + }, + "outputs": [], + "source": [ + "def search_sample(\n", + " project_id: str,\n", + " location: str,\n", + " engine_id: str,\n", + " search_query: str,\n", + ") -> list[discoveryengine.SearchResponse]:\n", + " # For more information, refer to:\n", + " # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store\n", + " client_options = (\n", + " ClientOptions(api_endpoint=f\"{location}-discoveryengine.googleapis.com\")\n", + " if LOCATION != \"global\"\n", + " else None\n", + " )\n", + "\n", + " # Create a client\n", + " client = discoveryengine.SearchServiceClient(client_options=client_options)\n", + "\n", + " # The full resource name of the search engine serving config\n", + " # e.g. projects/{project_id}/locations/{location}/dataStores/{data_store_id}/servingConfigs/{serving_config_id}\n", + " serving_config = f\"projects/{project_id}/locations/{location}/collections/default_collection/engines/{engine_id}/servingConfigs/default_search\"\n", + "\n", + " # Optional: Configuration options for search\n", + " # Refer to the `ContentSearchSpec` reference for all supported fields:\n", + " # https://cloud.google.com/python/docs/reference/discoveryengine/latest/google.cloud.discoveryengine_v1.types.SearchRequest.ContentSearchSpec\n", + " content_search_spec = discoveryengine.SearchRequest.ContentSearchSpec(\n", + " # For information about snippets, refer to:\n", + " # https://cloud.google.com/generative-ai-app-builder/docs/snippets\n", + " snippet_spec=discoveryengine.SearchRequest.ContentSearchSpec.SnippetSpec(\n", + " return_snippet=True\n", + " ),\n", + " # For information about search summaries, refer to:\n", + " # https://cloud.google.com/generative-ai-app-builder/docs/get-search-summaries\n", + " summary_spec=discoveryengine.SearchRequest.ContentSearchSpec.SummarySpec(\n", + " summary_result_count=5,\n", + " include_citations=True,\n", + " ignore_adversarial_query=True,\n", + " ignore_non_summary_seeking_query=True,\n", + " ),\n", + " )\n", + "\n", + " # Refer to the `SearchRequest` reference for all supported fields:\n", + " # https://cloud.google.com/python/docs/reference/discoveryengine/latest/google.cloud.discoveryengine_v1.types.SearchRequest\n", + " request = discoveryengine.SearchRequest(\n", + " serving_config=serving_config,\n", + " query=search_query,\n", + " page_size=10,\n", + " content_search_spec=content_search_spec,\n", + " query_expansion_spec=discoveryengine.SearchRequest.QueryExpansionSpec(\n", + " condition=discoveryengine.SearchRequest.QueryExpansionSpec.Condition.AUTO,\n", + " ),\n", + " spell_correction_spec=discoveryengine.SearchRequest.SpellCorrectionSpec(\n", + " mode=discoveryengine.SearchRequest.SpellCorrectionSpec.Mode.AUTO\n", + " ),\n", + " )\n", + "\n", + " response = client.search(request)\n", + " return response" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "id": "ad41e18b-38d2-4f4c-98ae-df14eda900ae" + }, + "outputs": [], + "source": [ + "query = \"Who is the CEO of Google?\"\n", + "\n", + "response = search_sample(PROJECT_ID, LOCATION, ENGINE_ID, query)\n", + "print(response.summary.summary_text)" + ] + } + ], + "metadata": { + "colab": { + "name": "create_datastore_and_search.ipynb", + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + } }, - { - "cell_type": "markdown", - "metadata": { - "id": "0460bdbe-05db-42f8-822c-82195de8329a" - }, - "source": [ - "---\n", - "\n", - "* Author(s): [Kara Greenfield](https://github.com/kgreenfield2)\n", - "* Created: 22 Nov 2023\n", - "* Updated: 31 Oct 2024\n", - "\n", - "---\n", - "\n", - "## Objective\n", - "\n", - "This notebook shows how to create and populate a Vertex AI Search Datastore, how to create a search app connected to that datastore, and how to submit queries through the search engine.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "0b4b1050-7113-487e-aeaf-55690c831a1d" - }, - "source": [ - "Services used in the notebook:\n", - "\n", - "- ✅ Vertex AI Search for document search and retrieval" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "43828625-a130-449c-ba5f-6a948220f559" - }, - "source": [ - "## Install pre-requisites\n", - "\n", - "If running in Colab install the pre-requisites into the runtime. Otherwise it is assumed that the notebook is running in Vertex AI Workbench." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "id": "8ea5db8a-dccc-4442-b5d7-7088d5ffb5ac" - }, - "outputs": [], - "source": [ - "%pip install --upgrade --user -q google-cloud-discoveryengine" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "10f9e321" - }, - "source": [ - "### Restart current runtime\n", - "\n", - "To use the newly installed packages in this Jupyter runtime, you must restart the runtime. You can do this by running the cell below, which will restart the current kernel." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "da755736" - }, - "outputs": [], - "source": [ - "# Restart kernel after installs so that your environment can access the new packages\n", - "\n", - "import IPython\n", - "\n", - "app = IPython.Application.instance()\n", - "app.kernel.do_shutdown(True)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "9c31dbe0" - }, - "source": [ - "
\n", - "⚠️ The kernel is going to restart. Please wait until it is finished before continuing to the next step. ⚠️\n", - "
\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "5f6a5de5-156e-4f14-99e6-3ab33e076c81" - }, - "source": [ - "## Authenticate\n", - "\n", - "If running in Colab authenticate with `google.colab.google.auth` otherwise assume that running on Vertex AI Workbench." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "id": "df3b7309-c51c-44a0-a466-b0b2733e0c28" - }, - "outputs": [], - "source": [ - "import sys\n", - "\n", - "if \"google.colab\" in sys.modules:\n", - " from google.colab import auth\n", - "\n", - " auth.authenticate_user()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ae7a4925-145a-40f3-9fa1-3b69a42d488d" - }, - "source": [ - "## Configure notebook environment" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "id": "389b9e51-1ce4-4bdf-80b5-fcdc1882f853" - }, - "outputs": [], - "source": [ - "from google.api_core.client_options import ClientOptions\n", - "from google.cloud import discoveryengine\n", - "\n", - "PROJECT_ID = \"YOUR_PROJECT_ID\" # @param {type:\"string\"}\n", - "LOCATION = \"global\"" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "HjoerqoksBdx" - }, - "source": [ - "Set [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "s-jH2yG1rtxn" - }, - "outputs": [], - "source": [ - "!gcloud auth application-default login --project {PROJECT_ID}" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "07f1aecd-4633-4451-b5a7-1f26e4cb2631" - }, - "source": [ - "## Create and Populate a Datastore" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": { - "id": "9a1d0021-e299-49d4-a657-2e101ae49eb6" - }, - "outputs": [], - "source": [ - "def create_data_store(\n", - " project_id: str, location: str, data_store_name: str, data_store_id: str\n", - "):\n", - " # Create a client\n", - " client_options = (\n", - " ClientOptions(api_endpoint=f\"{location}-discoveryengine.googleapis.com\")\n", - " if location != \"global\"\n", - " else None\n", - " )\n", - " client = discoveryengine.DataStoreServiceClient(client_options=client_options)\n", - "\n", - " # Initialize request argument(s)\n", - " data_store = discoveryengine.DataStore(\n", - " display_name=data_store_name,\n", - " industry_vertical=discoveryengine.IndustryVertical.GENERIC,\n", - " content_config=discoveryengine.DataStore.ContentConfig.CONTENT_REQUIRED,\n", - " )\n", - "\n", - " operation = client.create_data_store(\n", - " request=discoveryengine.CreateDataStoreRequest(\n", - " parent=client.collection_path(\n", - " project_id, location, \"default_collection\"\n", - " ),\n", - " data_store=data_store,\n", - " data_store_id=data_store_id,\n", - " )\n", - " )\n", - "\n", - " # Make the request\n", - " # The try block is necessary to prevent execution from halting due to an error being thrown when the datastore takes a while to instantiate\n", - " try:\n", - " response = operation.result(timeout=90)\n", - " except:\n", - " print(\"long-running operation error.\")" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": { - "id": "8a4db726-8da1-4c76-8934-944aaf5f9b53" - }, - "outputs": [], - "source": [ - "# The datastore name can only contain lowercase letters, numbers, and hyphens\n", - "DATASTORE_NAME = \"alphabet-contracts\"\n", - "DATASTORE_ID = f\"{DATASTORE_NAME}-id\"\n", - "\n", - "create_data_store(PROJECT_ID, LOCATION, DATASTORE_NAME, DATASTORE_ID)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": { - "id": "03121270-5d2f-403b-81ea-c1d241357bd1" - }, - "outputs": [], - "source": [ - "def import_documents(\n", - " project_id: str,\n", - " location: str,\n", - " data_store_id: str,\n", - " gcs_uri: str,\n", - "):\n", - " # Create a client\n", - " client_options = (\n", - " ClientOptions(api_endpoint=f\"{location}-discoveryengine.googleapis.com\")\n", - " if location != \"global\"\n", - " else None\n", - " )\n", - " client = discoveryengine.DocumentServiceClient(client_options=client_options)\n", - "\n", - " # The full resource name of the search engine branch.\n", - " # e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}\n", - " parent = client.branch_path(\n", - " project=project_id,\n", - " location=location,\n", - " data_store=data_store_id,\n", - " branch=\"default_branch\",\n", - " )\n", - "\n", - " source_documents = [f\"{gcs_uri}/*\"]\n", - "\n", - " request = discoveryengine.ImportDocumentsRequest(\n", - " parent=parent,\n", - " gcs_source=discoveryengine.GcsSource(\n", - " input_uris=source_documents, data_schema=\"content\"\n", - " ),\n", - " # Options: `FULL`, `INCREMENTAL`\n", - " reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,\n", - " )\n", - "\n", - " # Make the request\n", - " operation = client.import_documents(request=request)\n", - "\n", - " response = operation.result()\n", - "\n", - " # Once the operation is complete,\n", - " # get information from operation metadata\n", - " metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)\n", - "\n", - " # Handle the response\n", - " return operation.operation.name" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": { - "id": "1ddfe66a-acb4-4fdb-b9ed-76a332bb0f0c" - }, - "outputs": [], - "source": [ - "source_documents_gs_uri = (\n", - " \"gs://cloud-samples-data/gen-app-builder/search/alphabet-investor-pdfs\"\n", - ")\n", - "\n", - "import_documents(PROJECT_ID, LOCATION, DATASTORE_ID, source_documents_gs_uri)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "7a957202-b67e-47ca-84c3-b8a62cfbe405" - }, - "source": [ - "## Create a Search Engine\n", - "\n", - "This is used to set the `search_tier` to enterprise and to enable advanced LLM features.\n", - "\n", - "Enterprise tier is required to get extractive answers from a search query and advanced LLM features are required to summarize search results." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "id": "0e39e9bb-f381-44f6-a45e-3322669a171f" - }, - "outputs": [], - "source": [ - "def create_engine(\n", - " project_id: str, location: str, engine_name: str, engine_id: str, data_store_id: str\n", - "):\n", - " # Create a client\n", - " client_options = (\n", - " ClientOptions(api_endpoint=f\"{location}-discoveryengine.googleapis.com\")\n", - " if location != \"global\"\n", - " else None\n", - " )\n", - " client = discoveryengine.EngineServiceClient(client_options=client_options)\n", - "\n", - " # Initialize request argument(s)\n", - " engine = discoveryengine.Engine(\n", - " display_name=engine_name,\n", - " solution_type=discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH,\n", - " industry_vertical=discoveryengine.IndustryVertical.GENERIC,\n", - " data_store_ids=[data_store_id],\n", - " search_engine_config=discoveryengine.Engine.SearchEngineConfig(\n", - " search_tier=discoveryengine.SearchTier.SEARCH_TIER_ENTERPRISE,\n", - " search_add_ons=[discoveryengine.SearchAddOn.SEARCH_ADD_ON_LLM],\n", - " ),\n", - " )\n", - "\n", - " request = discoveryengine.CreateEngineRequest(\n", - " parent=client.collection_path(project_id, location, \"default_collection\"),\n", - " engine=engine,\n", - " engine_id=engine.display_name,\n", - " )\n", - "\n", - " # Make the request\n", - " operation = client.create_engine(request=request)\n", - " response = operation.result(timeout=90)" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": { - "id": "4a853982-8c2e-402a-a808-5364bf932619" - }, - "outputs": [], - "source": [ - "ENGINE_NAME = DATASTORE_NAME\n", - "ENGINE_ID = DATASTORE_ID\n", - "create_engine(PROJECT_ID, LOCATION, ENGINE_NAME, ENGINE_ID, DATASTORE_ID)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "e9f4d978-9164-4de3-b01a-179051706313" - }, - "source": [ - "## Query your Search Engine\n", - "\n", - "Note: The Engine will take some time to be ready to query.\n", - "\n", - "If you recently created an engine and you receive an error similar to:\n", - "\n", - "`404 Engine {ENGINE_NAME} is not found`\n", - "\n", - "Then wait a few minutes and try your query again." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": { - "id": "1c4dfb62-7846-43d0-9cba-fd8886ce5546" - }, - "outputs": [], - "source": [ - "def search_sample(\n", - " project_id: str,\n", - " location: str,\n", - " engine_id: str,\n", - " search_query: str,\n", - ") -> list[discoveryengine.SearchResponse]:\n", - " # For more information, refer to:\n", - " # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store\n", - " client_options = (\n", - " ClientOptions(api_endpoint=f\"{location}-discoveryengine.googleapis.com\")\n", - " if LOCATION != \"global\"\n", - " else None\n", - " )\n", - "\n", - " # Create a client\n", - " client = discoveryengine.SearchServiceClient(client_options=client_options)\n", - "\n", - " # The full resource name of the search engine serving config\n", - " # e.g. projects/{project_id}/locations/{location}/dataStores/{data_store_id}/servingConfigs/{serving_config_id}\n", - " serving_config = f\"projects/{project_id}/locations/{location}/collections/default_collection/engines/{engine_id}/servingConfigs/default_search\"\n", - "\n", - " # Optional: Configuration options for search\n", - " # Refer to the `ContentSearchSpec` reference for all supported fields:\n", - " # https://cloud.google.com/python/docs/reference/discoveryengine/latest/google.cloud.discoveryengine_v1.types.SearchRequest.ContentSearchSpec\n", - " content_search_spec = discoveryengine.SearchRequest.ContentSearchSpec(\n", - " # For information about snippets, refer to:\n", - " # https://cloud.google.com/generative-ai-app-builder/docs/snippets\n", - " snippet_spec=discoveryengine.SearchRequest.ContentSearchSpec.SnippetSpec(\n", - " return_snippet=True\n", - " ),\n", - " # For information about search summaries, refer to:\n", - " # https://cloud.google.com/generative-ai-app-builder/docs/get-search-summaries\n", - " summary_spec=discoveryengine.SearchRequest.ContentSearchSpec.SummarySpec(\n", - " summary_result_count=5,\n", - " include_citations=True,\n", - " ignore_adversarial_query=True,\n", - " ignore_non_summary_seeking_query=True,\n", - " ),\n", - " )\n", - "\n", - " # Refer to the `SearchRequest` reference for all supported fields:\n", - " # https://cloud.google.com/python/docs/reference/discoveryengine/latest/google.cloud.discoveryengine_v1.types.SearchRequest\n", - " request = discoveryengine.SearchRequest(\n", - " serving_config=serving_config,\n", - " query=search_query,\n", - " page_size=10,\n", - " content_search_spec=content_search_spec,\n", - " query_expansion_spec=discoveryengine.SearchRequest.QueryExpansionSpec(\n", - " condition=discoveryengine.SearchRequest.QueryExpansionSpec.Condition.AUTO,\n", - " ),\n", - " spell_correction_spec=discoveryengine.SearchRequest.SpellCorrectionSpec(\n", - " mode=discoveryengine.SearchRequest.SpellCorrectionSpec.Mode.AUTO\n", - " ),\n", - " )\n", - "\n", - " response = client.search(request)\n", - " return response" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "id": "ad41e18b-38d2-4f4c-98ae-df14eda900ae" - }, - "outputs": [], - "source": [ - "query = \"Who is the CEO of Google?\"\n", - "\n", - "response = search_sample(PROJECT_ID, LOCATION, ENGINE_ID, query)\n", - "print(response.summary.summary_text)" - ] - } - ], - "metadata": { - "colab": { - "name": "create_datastore_and_search.ipynb", - "toc_visible": true - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - } - }, - "nbformat": 4, - "nbformat_minor": 0 + "nbformat": 4, + "nbformat_minor": 0 } diff --git a/search/custom-embeddings/custom_embeddings.ipynb b/search/custom-embeddings/custom_embeddings.ipynb index 5fecf823d0a..2fb46c37b1d 100644 --- a/search/custom-embeddings/custom_embeddings.ipynb +++ b/search/custom-embeddings/custom_embeddings.ipynb @@ -57,7 +57,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/search/retrieval-augmented-generation/examples/contract_analysis.ipynb b/search/retrieval-augmented-generation/examples/contract_analysis.ipynb index ac962445c09..80b700f5e48 100644 --- a/search/retrieval-augmented-generation/examples/contract_analysis.ipynb +++ b/search/retrieval-augmented-generation/examples/contract_analysis.ipynb @@ -27,7 +27,31 @@ " Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/search/retrieval-augmented-generation/examples/question_answering.ipynb b/search/retrieval-augmented-generation/examples/question_answering.ipynb index c74a195e021..02baa9cb1f1 100644 --- a/search/retrieval-augmented-generation/examples/question_answering.ipynb +++ b/search/retrieval-augmented-generation/examples/question_answering.ipynb @@ -31,7 +31,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/search/retrieval-augmented-generation/examples/rag_google_documentation.ipynb b/search/retrieval-augmented-generation/examples/rag_google_documentation.ipynb index ae0603e8708..33b7bee01cc 100644 --- a/search/retrieval-augmented-generation/examples/rag_google_documentation.ipynb +++ b/search/retrieval-augmented-generation/examples/rag_google_documentation.ipynb @@ -49,7 +49,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/search/search_data_blending_with_gemini_summarization.ipynb b/search/search_data_blending_with_gemini_summarization.ipynb index 2eefaf5aa75..adee594bc88 100644 --- a/search/search_data_blending_with_gemini_summarization.ipynb +++ b/search/search_data_blending_with_gemini_summarization.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/search/search_filters_metadata.ipynb b/search/search_filters_metadata.ipynb index 8cc2ab6a846..6e8a15387ef 100644 --- a/search/search_filters_metadata.ipynb +++ b/search/search_filters_metadata.ipynb @@ -27,7 +27,31 @@ " Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/search/vertexai-search-options/vertexai_search_options.ipynb b/search/vertexai-search-options/vertexai_search_options.ipynb index 247c506f71d..606fc0afb69 100644 --- a/search/vertexai-search-options/vertexai_search_options.ipynb +++ b/search/vertexai-search-options/vertexai_search_options.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/vision/getting-started/image_editing.ipynb b/vision/getting-started/image_editing.ipynb index 3025e1fec2c..ece71d58aa3 100644 --- a/vision/getting-started/image_editing.ipynb +++ b/vision/getting-started/image_editing.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/vision/getting-started/image_editing_maskmode.ipynb b/vision/getting-started/image_editing_maskmode.ipynb index 216307e3c72..a64523d2e5d 100644 --- a/vision/getting-started/image_editing_maskmode.ipynb +++ b/vision/getting-started/image_editing_maskmode.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/vision/getting-started/image_generation.ipynb b/vision/getting-started/image_generation.ipynb index 0de6be5d80a..05b3ea197e7 100644 --- a/vision/getting-started/image_generation.ipynb +++ b/vision/getting-started/image_generation.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/vision/getting-started/image_segmentation.ipynb b/vision/getting-started/image_segmentation.ipynb index bd6b2aa6b53..d9d712d61b0 100644 --- a/vision/getting-started/image_segmentation.ipynb +++ b/vision/getting-started/image_segmentation.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/vision/getting-started/imagen3_image_generation.ipynb b/vision/getting-started/imagen3_image_generation.ipynb index dcd09c9607d..fabaefda7e3 100644 --- a/vision/getting-started/imagen3_image_generation.ipynb +++ b/vision/getting-started/imagen3_image_generation.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/vision/getting-started/prompt_generation_with_gemini.ipynb b/vision/getting-started/prompt_generation_with_gemini.ipynb index dbeb6e6f2e8..7456bdebef4 100644 --- a/vision/getting-started/prompt_generation_with_gemini.ipynb +++ b/vision/getting-started/prompt_generation_with_gemini.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/vision/getting-started/visual_captioning.ipynb b/vision/getting-started/visual_captioning.ipynb index 82a41c19d0c..b517a20aea8 100644 --- a/vision/getting-started/visual_captioning.ipynb +++ b/vision/getting-started/visual_captioning.ipynb @@ -47,7 +47,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/vision/getting-started/visual_question_answering.ipynb b/vision/getting-started/visual_question_answering.ipynb index a7d719eadee..1bf2505f216 100644 --- a/vision/getting-started/visual_question_answering.ipynb +++ b/vision/getting-started/visual_question_answering.ipynb @@ -47,7 +47,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/vision/gradio/gradio_image_generation_sdk.ipynb b/vision/gradio/gradio_image_generation_sdk.ipynb index 2e3df048d8c..cc770ff93f1 100644 --- a/vision/gradio/gradio_image_generation_sdk.ipynb +++ b/vision/gradio/gradio_image_generation_sdk.ipynb @@ -47,7 +47,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/vision/use-cases/advanced_prompting_for_imagen2.ipynb b/vision/use-cases/advanced_prompting_for_imagen2.ipynb index 83b3cf50815..441e03017bb 100644 --- a/vision/use-cases/advanced_prompting_for_imagen2.ipynb +++ b/vision/use-cases/advanced_prompting_for_imagen2.ipynb @@ -54,7 +54,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/vision/use-cases/advertisement-creation/advertisement_creation.ipynb b/vision/use-cases/advertisement-creation/advertisement_creation.ipynb index 38bf99ce23f..9163143563f 100644 --- a/vision/use-cases/advertisement-creation/advertisement_creation.ipynb +++ b/vision/use-cases/advertisement-creation/advertisement_creation.ipynb @@ -50,7 +50,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/vision/use-cases/brochure-creation-using-imagen/brochure_creation_using_imagen.ipynb b/vision/use-cases/brochure-creation-using-imagen/brochure_creation_using_imagen.ipynb index db632a5def5..3c97a8f3710 100644 --- a/vision/use-cases/brochure-creation-using-imagen/brochure_creation_using_imagen.ipynb +++ b/vision/use-cases/brochure-creation-using-imagen/brochure_creation_using_imagen.ipynb @@ -54,7 +54,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/vision/use-cases/creating_high_quality_visual_assets_with_gemini_and_imagen.ipynb b/vision/use-cases/creating_high_quality_visual_assets_with_gemini_and_imagen.ipynb index 4e202444265..aa3f363d691 100644 --- a/vision/use-cases/creating_high_quality_visual_assets_with_gemini_and_imagen.ipynb +++ b/vision/use-cases/creating_high_quality_visual_assets_with_gemini_and_imagen.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "\n" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " \n" ] }, { diff --git a/vision/use-cases/image_segmentation_layers.ipynb b/vision/use-cases/image_segmentation_layers.ipynb index f72be454b9e..822703bc937 100644 --- a/vision/use-cases/image_segmentation_layers.ipynb +++ b/vision/use-cases/image_segmentation_layers.ipynb @@ -52,7 +52,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/vision/use-cases/video-thumbnail-generation/video_thumbnail_generation.ipynb b/vision/use-cases/video-thumbnail-generation/video_thumbnail_generation.ipynb index cecf22b8cea..dc1be1b0216 100644 --- a/vision/use-cases/video-thumbnail-generation/video_thumbnail_generation.ipynb +++ b/vision/use-cases/video-thumbnail-generation/video_thumbnail_generation.ipynb @@ -52,7 +52,31 @@ " \"Vertex
Open in Vertex AI Workbench\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/workshops/rag-ops/1_prototyping_gemini.ipynb b/workshops/rag-ops/1_prototyping_gemini.ipynb index 7b1b41151c7..2eb68b43266 100644 --- a/workshops/rag-ops/1_prototyping_gemini.ipynb +++ b/workshops/rag-ops/1_prototyping_gemini.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/workshops/rag-ops/2.1_mvp_data_processing.ipynb b/workshops/rag-ops/2.1_mvp_data_processing.ipynb index 16fb199d098..3360e8779ac 100644 --- a/workshops/rag-ops/2.1_mvp_data_processing.ipynb +++ b/workshops/rag-ops/2.1_mvp_data_processing.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/workshops/rag-ops/2.2_mvp_chunk_embeddings.ipynb b/workshops/rag-ops/2.2_mvp_chunk_embeddings.ipynb index 4c15ad49fdc..5621f9b0fb0 100644 --- a/workshops/rag-ops/2.2_mvp_chunk_embeddings.ipynb +++ b/workshops/rag-ops/2.2_mvp_chunk_embeddings.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/workshops/rag-ops/2.3_mvp_rag.ipynb b/workshops/rag-ops/2.3_mvp_rag.ipynb index 74391029797..8911e1f5196 100644 --- a/workshops/rag-ops/2.3_mvp_rag.ipynb +++ b/workshops/rag-ops/2.3_mvp_rag.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/workshops/rag-ops/2.4_mvp_evaluation.ipynb b/workshops/rag-ops/2.4_mvp_evaluation.ipynb index d24264f2349..2ae6babafb3 100644 --- a/workshops/rag-ops/2.4_mvp_evaluation.ipynb +++ b/workshops/rag-ops/2.4_mvp_evaluation.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, { diff --git a/workshops/rag-ops/2.5_mvp_evaluation_vertexai_eval.ipynb b/workshops/rag-ops/2.5_mvp_evaluation_vertexai_eval.ipynb index 5c431e09b30..0dae15ad6d8 100644 --- a/workshops/rag-ops/2.5_mvp_evaluation_vertexai_eval.ipynb +++ b/workshops/rag-ops/2.5_mvp_evaluation_vertexai_eval.ipynb @@ -53,7 +53,31 @@ " \"GitHub
View on GitHub\n", " \n", " \n", - "" + "\n", + "\n", + "
\n", + "\n", + "Share to:\n", + "\n", + "\n", + " \"LinkedIn\n", + "\n", + "\n", + "\n", + " \"Bluesky\n", + "\n", + "\n", + "\n", + " \"X\n", + "\n", + "\n", + "\n", + " \"Reddit\n", + "\n", + "\n", + "\n", + " \"Facebook\n", + " " ] }, {