"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prompt = \"\"\"\n",
" Compare recipes from https://www.food.com/recipe/homemade-cream-of-broccoli-soup-271210\n",
" and from https://www.allrecipes.com/recipe/13313/best-cream-of-broccoli-soup/,\n",
" list the key differences between them.\n",
"\"\"\"\n",
"\n",
"tools = []\n",
"tools.append(types.Tool(url_context=types.UrlContext))\n",
"\n",
"client = genai.Client(api_key=GEMINI_API_KEY)\n",
"config = types.GenerateContentConfig(\n",
" tools=tools,\n",
")\n",
"\n",
"response = client.models.generate_content(\n",
" contents=[prompt],\n",
" model=MODEL_ID,\n",
" config=config\n",
")\n",
"\n",
"display(Markdown(response.text))"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Rl-y9SZywD0s"
},
"source": [
"\n",
"## Function calling\n",
"\n",
"[Function calling](https://ai.google.dev/gemini-api/docs/function-calling) lets you provide a set of tools that it can use to respond to the user's prompt. 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:\n",
"- The name of a function that matches the description.\n",
"- The arguments to call it with."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "sbng1zqyhNbU"
},
"source": [
"More details and examples in the [function calling guide ](./Function_calling.ipynb)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "APk6sXO6wLQp"
},
"outputs": [
{
"data": {
"text/plain": [
"FunctionCall(\n",
" args={\n",
" 'destination': 'Paris'\n",
" },\n",
" name='get_destination'\n",
")"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_destination = types.FunctionDeclaration(\n",
" name=\"get_destination\",\n",
" description=\"Get the destination that the user wants to go to\",\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 = types.Tool(\n",
" function_declarations=[get_destination],\n",
")\n",
"\n",
"response = client.models.generate_content(\n",
" model=MODEL_ID,\n",
" contents=\"I'd like to travel to Paris.\",\n",
" config=types.GenerateContentConfig(\n",
" tools=[destination_tool],\n",
" ),\n",
")\n",
"\n",
"response.candidates[0].content.parts[0].function_call"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0z2FJtzzHB2g"
},
"source": [
"You can also use [MCP servers](https://ai.google.dev/gemini-api/docs/function-calling#mcp)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "NsNd3DtDFX1X"
},
"source": [
"\n",
"## Code execution\n",
"\n",
"[Code execution](https://ai.google.dev/gemini-api/docs/code-execution?lang=python) lets the model generate and execute Python code to answer complex questions.\n",
"\n",
"You can find more examples in the [Code execution guide ](./Code_execution.ipynb)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "fY062-nsGLBu"
},
"outputs": [
{
"data": {
"text/html": [
"word = \"strawberry\"\n",
"count = word.count(\"r\")\n",
"print(f\"The number of 'r's in '{word}' is: {count}\")"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"---"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"The number of 'r's in 'strawberry' is: 3\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"---"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"The number of 'r's in the word \"strawberry\" is 3."
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"---"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.display import Image, Markdown, Code, HTML\n",
"\n",
"response = client.models.generate_content(\n",
" model=MODEL_ID,\n",
" contents=\"Generate and run a script to count how many letter r there are in the word strawberry\",\n",
" config = types.GenerateContentConfig(\n",
" tools=[types.Tool(code_execution=types.ToolCodeExecution)]\n",
" )\n",
")\n",
"\n",
"for part in response.candidates[0].content.parts:\n",
" if part.text is not None:\n",
" display(Markdown(part.text))\n",
" if part.executable_code is not None:\n",
" code_html = f'{part.executable_code.code}'\n",
" display(HTML(code_html))\n",
" if part.code_execution_result is not None:\n",
" display(Markdown(part.code_execution_result.output))\n",
" if part.inline_data is not None:\n",
" display(Image(data=part.inline_data.data, format=\"png\"))\n",
" display(Markdown(\"---\"))"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "oTgeR3_9wN5J"
},
"source": [
"\n",
"## Use context caching\n",
"\n",
"[Context caching](https://ai.google.dev/gemini-api/docs/caching?lang=python) lets you to store frequently used input tokens in a dedicated cache and reference them for subsequent requests, eliminating the need to repeatedly pass the same set of tokens to a model. You can find more caching examples [in the dedicated guide ](./Caching.ipynb).\n",
"\n",
"Note that for models older than 2.5, you needed to use fixed version models (often ending with `-001`)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Tgl2gzmuwQXz"
},
"source": [
"#### Create a cache"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "b2Jb0gaiwOVi"
},
"outputs": [],
"source": [
"system_instruction = \"\"\"\n",
" You are an expert researcher who has years of experience in conducting systematic literature surveys and meta-analyses of different topics.\n",
" You pride yourself on incredible accuracy and attention to detail. You always stick to the facts in the sources provided, and never make up new facts.\n",
" Now look at the research paper below, and answer the following questions in 1-2 sentences.\n",
"\"\"\"\n",
"\n",
"urls = [\n",
" 'https://storage.googleapis.com/cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf',\n",
" \"https://storage.googleapis.com/cloud-samples-data/generative-ai/pdf/2403.05530.pdf\",\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ZrZ64o5Sydm_"
},
"outputs": [
{
"data": {
"text/plain": [
"7228817"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Download files\n",
"pdf_bytes = requests.get(urls[0]).content\n",
"pdf_path = pathlib.Path('2312.11805v3.pdf')\n",
"pdf_path.write_bytes(pdf_bytes)\n",
"\n",
"pdf_bytes = requests.get(urls[1]).content\n",
"pdf_path = pathlib.Path('2403.05530.pdf')\n",
"pdf_path.write_bytes(pdf_bytes)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ZrylX7r3w2bF"
},
"outputs": [],
"source": [
"# Upload the PDFs using the File API\n",
"uploaded_pdfs = []\n",
"uploaded_pdfs.append(client.files.upload(file='2312.11805v3.pdf'))\n",
"uploaded_pdfs.append(client.files.upload(file='2403.05530.pdf'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "7MBsaipow7m5"
},
"outputs": [
{
"data": {
"text/plain": [
"CachedContent(\n",
" create_time=datetime.datetime(2025, 11, 15, 17, 13, 51, 402109, tzinfo=TzInfo(UTC)),\n",
" display_name='research papers',\n",
" expire_time=datetime.datetime(2025, 11, 15, 18, 13, 49, 999682, tzinfo=TzInfo(UTC)),\n",
" model='models/gemini-3.1-pro-preview',\n",
" name='cachedContents/51lc0rcel857wv16pekr76tkqk9sf69dtygyo8y5',\n",
" update_time=datetime.datetime(2025, 11, 15, 17, 13, 51, 402109, tzinfo=TzInfo(UTC)),\n",
" usage_metadata=CachedContentUsageMetadata(\n",
" total_token_count=93601\n",
" )\n",
")"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a cache with a 60 minute TTL\n",
"cached_content = client.caches.create(\n",
" model=MODEL_ID,\n",
" config=types.CreateCachedContentConfig(\n",
" display_name='research papers', # used to identify the cache\n",
" system_instruction=system_instruction,\n",
" contents=uploaded_pdfs,\n",
" ttl=\"3600s\",\n",
" )\n",
")\n",
"\n",
"cached_content"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2870527e1c84"
},
"source": [
"#### Listing available cache objects"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3be7c2339be3"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"name='cachedContents/51lc0rcel857wv16pekr76tkqk9sf69dtygyo8y5' display_name='research papers' model='models/gemini-3.1-pro-preview' create_time=datetime.datetime(2025, 11, 15, 17, 13, 51, 402109, tzinfo=TzInfo(UTC)) update_time=datetime.datetime(2025, 11, 15, 17, 13, 51, 402109, tzinfo=TzInfo(UTC)) expire_time=datetime.datetime(2025, 11, 15, 18, 13, 49, 999682, tzinfo=TzInfo(UTC)) usage_metadata=CachedContentUsageMetadata(\n",
" total_token_count=93601\n",
")\n"
]
}
],
"source": [
"for cache in client.caches.list():\n",
" print(cache)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "KKgCRRXfwU_m"
},
"source": [
"#### Use a cache"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "-Qo7-sU2w92j"
},
"outputs": [
{
"data": {
"text/markdown": [
"The shared research goal of these papers is to present and evaluate the Gemini family of multimodal models, demonstrating their advanced capabilities in reasoning and understanding across text, image, audio, and video domains. The authors aim to validate these models against a comprehensive suite of benchmarks to establish new state-of-the-art results in generalist AI capabilities, ranging from native multimodality to long-context processing."
],
"text/plain": [
""
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"response = client.models.generate_content(\n",
" model=MODEL_ID,\n",
" contents=\"What is the research goal shared by these research papers?\",\n",
" config=types.GenerateContentConfig(cached_content=cached_content.name)\n",
")\n",
"\n",
"Markdown(response.text)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4QSOsWurx4CG"
},
"source": [
"#### Delete a cache"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "zSZeG60Dx4V-"
},
"outputs": [],
"source": [
"result = client.caches.delete(name=cached_content.name)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "sXNCRn8Wx71d"
},
"source": [
"\n",
"## Get embeddings\n",
"\n",
"The Gemini API offers embedding models to generate embeddings for text, images, video, and other content. These resulting embeddings can then be used for tasks such as semantic search, classification, and clustering, providing more accurate, context-aware results than keyword-based approaches.\n",
"\n",
"The latest model, `gemini-embedding-2-preview`, is the first multimodal embedding model in the Gemini API. It maps text, images, video, audio, and PDFs into a unified embedding space, enabling cross-modal search, classification, and clustering across over 100 languages. For text-only use cases, `gemini-embedding-001` remains available.\n",
"\n",
"You can get text embeddings for a snippet of text by using `embed_content` method.\n",
"\n",
"The Gemini Embedding models produce an output with 3072 dimensions by default. However, you've the option to choose an output dimensionality between 1 and 3072. See the [embeddings documentation](https://ai.google.dev/gemini-api/docs/embeddings) or the [dedicated notebook ](./Embeddings.ipynb)\n",
"for more details."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"id": "hpJIA5zmx8Vy"
},
"outputs": [],
"source": [
"EMBEDDING_MODEL_ID = \"gemini-embedding-2-preview\" # @param [\"gemini-embedding-001\", \"gemini-embedding-2-preview\"] {\"allow-input\":true, isTemplate: true}"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"id": "0afi69R9x_bh"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ContentEmbedding(\n",
" values=[\n",
" -0.0051073395,\n",
" -0.008700113,\n",
" 0.012337968,\n",
" 0.015490749,\n",
" 0.013524115,\n",
" <... 3067 more items ...>,\n",
" ]\n",
"), ContentEmbedding(\n",
" values=[\n",
" 0.0047399383,\n",
" -0.02839862,\n",
" 0.0027905644,\n",
" -0.00028191903,\n",
" 0.00090539997,\n",
" <... 3067 more items ...>,\n",
" ]\n",
"), ContentEmbedding(\n",
" values=[\n",
" -0.00050140853,\n",
" -0.015329912,\n",
" 0.008328494,\n",
" 0.0022835443,\n",
" -0.0013814081,\n",
" <... 3067 more items ...>,\n",
" ]\n",
")]\n"
]
}
],
"source": [
"response = client.models.embed_content(\n",
" model=EMBEDDING_MODEL_ID,\n",
" contents=[\n",
" \"How do I get a driver's license/learner's permit?\",\n",
" \"How do I renew my driver's license?\",\n",
" \"How do I change my address on my driver's license?\"\n",
" ],\n",
")\n",
"\n",
"print(response.embeddings)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Tje8pMbd5z7j"
},
"source": [
"You'll get a set of three embeddings, one for each piece of text you passed in:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"id": "zNeuBlNt4CRk"
},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(response.embeddings)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "hG5UPmq3543E"
},
"source": [
"You can also see the length of each embedding is 3072, The default size."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"id": "s4oAtC8a4GYH"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3072\n",
"([-0.0051073395, -0.008700113, 0.012337968, 0.015490749], '...')\n"
]
}
],
"source": [
"print(len(response.embeddings[0].values))\n",
"print((response.embeddings[0].values[:4], '...'))"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "wHwF-KbCU_Xp"
},
"source": [
"#### Multimodal Embeddings\n",
"\n",
"With `gemini-embedding-2-preview`, you can create embeddings for text, audio,images, videos, and PDFs. See the [multimodal embeddings documentation](https://ai.google.dev/gemini-api/docs/embeddings#multimodal)\n",
"for more details."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"id": "PUDNy02NUO9T"
},
"outputs": [],
"source": [
"!wget -O cat.png https://storage.googleapis.com/generativeai-downloads/cookbook/image_out/cat.png -q"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"id": "3swRCdb_UAo6"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ContentEmbedding(\n",
" values=[\n",
" -0.029018743,\n",
" 0.0007757257,\n",
" -0.008576954,\n",
" -0.017866805,\n",
" 0.0027555688,\n",
" <... 3067 more items ...>,\n",
" ]\n",
")]\n"
]
}
],
"source": [
"MULTIMODAL_EMBEDDING_MODEL_ID = \"gemini-embedding-2-preview\"\n",
"\n",
"with open('cat.png', 'rb') as f:\n",
" image_bytes = f.read()\n",
"\n",
"result = client.models.embed_content(\n",
" model=MULTIMODAL_EMBEDDING_MODEL_ID,\n",
" contents=[\n",
" types.Part.from_bytes(\n",
" data=image_bytes,\n",
" mime_type='image/png',\n",
" ),\n",
" ]\n",
")\n",
"\n",
"print(result.embeddings)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d7pdO-4mlhZs"
},
"source": [
"## Gemini 3\n",
"\n",
"[Gemini 3 Pro](https://ai.google.dev/gemini-api/docs/models#gemini-3-pro) and [Gemini 3 Flash](https://ai.google.dev/gemini-api/docs/models#gemini-3-flash) are our new flagship models that comes with a few new features.\n",
"\n",
"The main one is the [thinking levels](#thinking_level) that simplifies how to control the amount of thinking your model does. The [Media resolution](#media_resolution) lets you control the quality of the images and videos that will be sent to the model. Finallly, the \"Thought Signatures\" are helping it maintain reasoning context across API calls.\n",
"\n",
"Also note that a temperature of 1 is recommended for this model generation."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "I0Gt67OplkxZ"
},
"outputs": [],
"source": [
"# @title Run this cell to set everything up (especially if you jumped directly to this section)from google.colab import userdata\n",
"from google import genai\n",
"from google.genai import types\n",
"from IPython.display import display, Markdown, HTML\n",
"\n",
"client = genai.Client(api_key=userdata.get('GEMINI_API_KEY'))\n",
"\n",
"# Select the Gemini 3 model\n",
"\n",
"GEMINI_3_MODEL_ID = \"gemini-3-flash-preview\" # @param [\"gemini-3.1-flash-lite-preview\", \"gemini-3-flash-preview\", \"gemini-3.1-pro-preview\"] {\"allow-input\":true, isTemplate: true}\n",
"\n",
"!wget https://storage.googleapis.com/generativeai-downloads/data/jetpack.png -O jetpack.png"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "aUBeYvL70O4y"
},
"source": [
"\n",
"### Thinking levels\n",
"\n",
"Instead of using a `thinking_budget` like the 2.5 generation (cf. [thinking](#thinking) section earlier), the third generation of Gemini models uses \"Thinking levels\" to make it simpler to manage.\n",
"\n",
"You can set that thinking level to \"minimal\" (more or less equivalent to \"off\"), \"low\", \"medium\" or \"high\" (default). This will indicate to the model if it allowed to do a lot of thinking. Since the thinking process stays dynamic, `high` doesn't mean it will always use a lot of token in its thinking phase, just that it's allowed to. Note that Gemini 3.1 Pro does not support \"minimal\".\n",
"\n",
"`thinking_budget` is still supported by Gemini 3 models.\n",
"\n",
"Check the [thinking guide ](./Get_started_thinking.ipynb#gemini3) or the [Gemini 3 documentation](https://ai.google.dev/gemini-api/docs/gemini-3) for more details."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5t_YHsJDLi0E"
},
"outputs": [
{
"data": {
"text/markdown": [
"### Thought summary:"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"**Unraveling the Riddle of Movement and Maze-Solving**\n",
"\n",
"Okay, so the riddle. Let's see... the core is movement without walking, a lack of fixed shape, and the ability to survive division, combined with maze-solving prowess, but no brain. Hmmm... first, I'm parsing the clues. \"Moves but doesn't walk, run, or swim\" - that screams something with a fluid form of locomotion. Think creeping, flowing, or expanding. Right away, snails, amoebas, some plants, maybe even certain fungal structures and slime molds come to mind. Water and clouds are a long shot, since they are inanimate.\n",
"\n",
"The \"no fixed shape, survives division\" clue zeroes in on a life form. Snails are out because cutting them up doesn't work. The no fixed shape points toward something amorphous, like a gelatinous blob or network. This also hints at a lack of centralized control. It sounds like something like a single-celled organism or perhaps a syncytial structure, which throws some other potential candidates into the mix.\n",
"\n",
"The \"no brain, but can solve mazes\" bit, that's the killer clue, that's some specific scientific trivia! It sounds like a non-animal, right? Not likely a worm, no matter how simple their brains might be, and not a cloud or puddle. It has to be an organism famous for maze solving. I recall a specific experiment with oat flakes and an organism growing through a maze to find the most efficient route. Another experiment mapped the Tokyo railway system.\n",
"\n",
"Okay, let's play the elimination game. Planarian worms have a basic nervous system, so they're not quite right. Amoebas fit some clues but not the maze solving. That leaves... oh, right, the slime mold! *Physarum polycephalum*, to be exact.\n",
"\n",
"* **Moves?** Yes, via cytoplasmic streaming, a distinct kind of \"creeping\" motion.\n",
"* **No fixed shape?** Absolutely! A yellow blobby network is its signature.\n",
"* **Cut pieces survive?** Yes! Its plasmodium structure is a syncytium, so cutting it just creates more independent or re-forming pieces.\n",
"* **No brain/maze solving?** Bingo! That's the *Physarum*'s claim to fame!\n",
"\n",
"Yeah, it's gotta be a **Slime Mold** (*Physarum polycephalum*). That's a classic riddle. This riddle is perfectly constructed. Good!\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/markdown": [
"### Answer:"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"You are thinking of a **Slime Mold** (specifically, *Physarum polycephalum*).\n",
"\n",
"Here is how it fits your clues:\n",
"* **It moves:** It moves via \"shuttling\" or cytoplasmic streaming, pulsing its way across forest floors (or petri dishes) without legs or fins.\n",
"* **Regeneration:** It is a single giant cell with millions of nuclei. If you cut it in half, the two pieces will heal and continue to act as independent organisms (or fuse back together).\n",
"* **The \"Blob\" intelligence:** Despite having no brain or central nervous system, it is famous in the scientific community for finding the shortest path between two food sources, effectively solving mazes and modeling efficient railway networks (like the Tokyo subway system)."
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"We used 834 tokens for the thinking phase and 62 for the output.\n"
]
}
],
"source": [
"prompt = \"\"\"\n",
" Find what I'm thinking of:\n",
" It moves, but doesn't walk, run, or swim.\n",
" It has no fixed shape and if cut into pieces, those pieces will keep living and moving.\n",
" It has no brain but can solve complex mazes.\n",
"\"\"\"\n",
"\n",
"thinking_level = \"high\" # @param [\"minimal\", \"low\", \"medium\",\"high\"]\n",
"\n",
"response = client.models.generate_content(\n",
" model=GEMINI_3_MODEL_ID,\n",
" contents=prompt,\n",
" config=types.GenerateContentConfig(\n",
" thinking_config=types.ThinkingConfig(\n",
" thinking_level=thinking_level,\n",
" include_thoughts=True\n",
" )\n",
" )\n",
")\n",
"\n",
"for part in response.parts:\n",
" if not part.text:\n",
" continue\n",
" if part.thought:\n",
" display(Markdown(\"### Thought summary:\"))\n",
" display(Markdown(part.text))\n",
" print()\n",
" else:\n",
" display(Markdown(\"### Answer:\"))\n",
" display(Markdown(part.text))\n",
" print()\n",
"\n",
"print(f\"We used {response.usage_metadata.thoughts_token_count} tokens for the thinking phase and {response.usage_metadata.prompt_token_count} for the output.\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "CRkqdIRESGOy"
},
"source": [
"\n",
"### Media resolution per file\n",
"\n",
"With Gemini 3 models, you can specify a media resolution for image and PDF inputs, which affects how images are tokenized and how many tokens are used for each image. This can be controlled **per file**.\n",
"\n",
"Here are what the different values corresponds to for images and PDFs:\n",
"* `MEDIA_RESOLUTION_HIGH`: 1120 tokens\n",
"* `MEDIA_RESOLUTION_MEDIUM`: 560 tokens\n",
"* `MEDIA_RESOLUTION_LOW`: 280 tokens\n",
"* `MEDIA_RESOLUTION_UNSPECIFIED` (default): Same as `MEDIA_RESOLUTION_HIGH` for images, and `MEDIA_RESOLUTION_MEDIUM` for PDFs.\n",
"\n",
"For videos, `MEDIA_RESOLUTION_LOW` and `MEDIA_RESOLUTION_MEDIUM` corresponds to 70 tokens per frame, while `MEDIA_RESOLUTION_HIGH` will send 280 tokens per frame.\n",
"\n",
"Note that these are maximums, and the actual token usage will usually be slightly lower (by approx 10%).\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xIUO5FJiM4Ug"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The image is worth 1081 tokens.\n"
]
}
],
"source": [
"# Media resolution is only available with `v1alpha`.\n",
"client = genai.Client(\n",
" api_key=userdata.get('GEMINI_API_KEY'),\n",
" http_options={\n",
" 'api_version': 'v1alpha',\n",
" }\n",
")\n",
"\n",
"# Upload to File API\n",
"sample_image = client.files.upload(file=\"jetpack.png\")\n",
"\n",
"media_resolution = 'MEDIA_RESOLUTION_HIGH' # @param ['MEDIA_RESOLUTION_UNSPECIFIED','MEDIA_RESOLUTION_LOW','MEDIA_RESOLUTION_MEDIUM','MEDIA_RESOLUTION_HIGH']\n",
"# You can also use types.PartMediaResolutionLevel.MEDIA_RESOLUTION_LOW/MEDIUM/HIGH\n",
"\n",
"count_tokens_response = client.models.count_tokens(\n",
" model=GEMINI_3_MODEL_ID,\n",
" contents=[\n",
" types.Part(\n",
" file_data=types.FileData(\n",
" file_uri=sample_image.uri,\n",
" mime_type=sample_image.mime_type\n",
" ),\n",
" media_resolution=types.PartMediaResolution(\n",
" level=media_resolution\n",
" ),\n",
" )\n",
" ],\n",
")\n",
"print(f\"The image is worth {count_tokens_response.total_tokens} tokens.\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "_tv2Fgd2572Z"
},
"source": [
"### Thoughts signatures\n",
"\n",
"This new addidtion won't affect you if you are using the SDK since it's entirerly managed by the SDKs. But if you are curious, here's what happening behind the scenes.\n",
"\n",
"If you check your response's part, you'll notice a new addition: a `thought_signature`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "mzxMHUlB-odd"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"b'\\x12\\x94\\x19\\n\\x91\\x19\\x01\\xd1\\xed\\x8aoD\\xe9\\xdc\\xcb>\\xd1\\xb4\\xb8\\x98\\xed]\\xa1;\\xda\\x0ck\\xa7\\x9e\\n\\x15$\\\\*\\xf6\\x87\\xf7\\xa6U\\xd0?\\x04|\\xd6\\xf3\\x84\\x97\\x9f\\xf2S\\xef\\xbeT?h\\xf8\\xb4\\xec\\xd3~]\\xe0\\xd9\\x96\\x14\\x98\\xf5\\xc2*\\xd7\\x87nH\\x19\\xeeS\\xc6\\x9d\\x0f\\x9c\\x0c\\xb5SJ\\xf3Y-#\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xa4\\xb1\\x08\\xc5\\xebh\\xdb\\xfb\\xf2=5\\xb0\\xa2\\xb2\\xc5\\xf4\\xc0\\xde.\\x9b1\\xaf\\xa7(B\n",
"### Migrating from Gemini 2.5\n",
"\n",
"[Gemini 3](https://ai.google.dev/gemini-api/docs/gemini-3) models are our most capable model family to date and offers a stepwise improvement over Gemini 2.5 Pro. When migrating, consider the following:\n",
"\n",
"* **Thinking:** If you were previously using complex prompt engineering (like Chain-of-thought) to force Gemini 2.5 to reason, try Gemini 3 with [`thinking_level: \"high\"`](#thinking_level) and simplified prompts (more in the [thinking](./Get_started_thinking.ipynb#gemini3migration) guide. \n",
"* **Temperature settings:** If your existing code explicitly sets temperature (especially to low values for deterministic outputs), we recommend removing this parameter and using the Gemini 3 default of 1.0 to avoid potential looping issues or performance degradation on complex tasks. \n",
"* **PDF & document understanding:** Default OCR resolution for PDFs has changed. If you relied on specific behavior for dense document parsing, test the new [`MEDIA_RESOLUTION_HIGH`](#media_resolution) setting to ensure continued accuracy. \n",
"* **Token consumption:** Migrating to Gemini 3 Pro defaults may **increase** token usage for PDFs but **decrease** token usage for video. If requests now exceed the context window due to higher default resolutions, we recommend explicitly reducing the [media resolution](#media_resolution). \n",
"* **Image segmentation:** Image segmentation capabilities (returning pixel-level masks for objects) are not supported in Gemini 3 Pro. For workloads requiring native image segmentation, we recommend continuing to utilize Gemini 2.5 Flash with thinking turned off (cf. [Spatial understanding guide ](./Spatial_understanding.ipynb)) or [Gemini Robotics-ER 1.5 ](./gemini-robotics-er.ipynb)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "_SOkIVJIyF1W"
},
"source": [
"## Next Steps\n",
"\n",
"### Useful API references:\n",
"\n",
"Check out the [Google GenAI SDK](https://github.com/googleapis/python-genai) and its [documentation](https://googleapis.github.io/python-genai/) for more details on the GenAI SDK.\n",
"\n",
"### Related examples\n",
"\n",
"For more detailed examples using Gemini models, check the [Quickstarts folder of the cookbook](https://github.com/google-gemini/cookbook/tree/main/quickstarts/).\n",
"\n",
"You'll learn how to use the [Live API ](./Get_started_LiveAPI.ipynb), juggle with [multiple tools ](../examples/LiveAPI_plotting_and_mapping.ipynb) or use Gemini's [spatial understanding ](./Spatial_understanding.ipynb) abilities.\n",
"\n",
"You should also check out all the gen-media models:\n",
" * Podcast and speech generation using [Gemini TTS ](./Get_started_TTS.ipynb),\n",
"* Live interaction with [Gemini Live ](./Get_started_LiveAPI.ipynb),\n",
"* Image generation using [Imagen ](./Get_started_imagen.ipynb),\n",
"* Video generation using [Veo ](./Get_started_Veo.ipynb),\n",
"* Music generation using [Lyria RealTime ](./Get_started_LyriaRealTime.ipynb).\n",
"\n",
"Then, head to the [Gemini thinking models ](./Get_started_thinking.ipynb) guide that explicitly showcases its thoughts summaries and can manage more complex reasonings.\n",
"\n",
"Finally, have a look at the [examples](https://github.com/google-gemini/cookbook/tree/main/examples/) folder of the cookbook for more complex use-cases and demos mixing different capabilities."
]
}
],
"metadata": {
"colab": {
"name": "Get_started.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}