|
92 | 92 | }, |
93 | 93 | { |
94 | 94 | "cell_type": "code", |
95 | | - "execution_count": 1, |
| 95 | + "execution_count": null, |
96 | 96 | "metadata": { |
97 | 97 | "id": "46zEFO2a9FFd" |
98 | 98 | }, |
|
118 | 118 | "source": [ |
119 | 119 | "### Setup your API key\n", |
120 | 120 | "\n", |
121 | | - "To run the following cell, your API key must be stored it in a Colab Secret named `GOOGLE_API_KEY`. If you don't already have an API key, or you're not sure how to create a Colab Secret, see [Authentication](../quickstarts/Authentication.ipynb) for an example." |
| 121 | + "To run the following cell, your API key must be stored it in a Colab Secret named `GOOGLE_API_KEY`. If you don't already have an API key or you aren't sure how to create a Colab Secret, see [Authentication](../quickstarts/Authentication.ipynb) for an example." |
122 | 122 | ] |
123 | 123 | }, |
124 | 124 | { |
125 | 125 | "cell_type": "code", |
126 | | - "execution_count": 2, |
| 126 | + "execution_count": null, |
127 | 127 | "metadata": { |
128 | 128 | "id": "A1pkoyZb9Jm3" |
129 | 129 | }, |
|
142 | 142 | "source": [ |
143 | 143 | "### Initialize SDK client\n", |
144 | 144 | "\n", |
145 | | - "With the new SDK you now only need to initialize a client with you API key (or OAuth if using [Vertex AI](https://cloud.google.com/vertex-ai)). The model is now set in each call." |
| 145 | + "With the new SDK, now you only need to initialize a client with you API key (or OAuth if using [Vertex AI](https://cloud.google.com/vertex-ai)). The model is now set in each call." |
146 | 146 | ] |
147 | 147 | }, |
148 | 148 | { |
149 | 149 | "cell_type": "code", |
150 | | - "execution_count": 3, |
| 150 | + "execution_count": null, |
151 | 151 | "metadata": { |
152 | 152 | "id": "HghvVpbU0Uap" |
153 | 153 | }, |
|
167 | 167 | "source": [ |
168 | 168 | "### Choose a model\n", |
169 | 169 | "\n", |
170 | | - "Now select the model you want to use in this guide, either by selecting one in the list or writing it down. Keep in mind that some models, like the 2.5 ones are thinking models and thus take slightly more time to respond (cf. [thinking notebook](./Get_started_thinking.ipynb) for more details and in particular learn how to switch the thiking off).\n", |
| 170 | + "Select the model you want to use in this guide. You can either select one from the list or enter a model name manually. Keep in mind that some models, such as the 2.5 ones are thinking models and thus take slightly more time to respond. For more details, you can see [thinking notebook](./Get_started_thinking.ipynb) to learn how to switch the thinking off.\n", |
171 | 171 | "\n", |
172 | | - "For more information about all Gemini models, check the [documentation](https://ai.google.dev/gemini-api/docs/models/gemini) for extended information on each of them." |
| 172 | + "For a full overview of all Gemini models, check the [documentation](https://ai.google.dev/gemini-api/docs/models/gemini)." |
173 | 173 | ] |
174 | 174 | }, |
175 | 175 | { |
176 | 176 | "cell_type": "code", |
177 | | - "execution_count": 4, |
| 177 | + "execution_count": null, |
178 | 178 | "metadata": { |
179 | 179 | "id": "AChpZWIXu62m" |
180 | 180 | }, |
|
191 | 191 | "source": [ |
192 | 192 | "## Send text prompts\n", |
193 | 193 | "\n", |
194 | | - "Use the `generate_content` method to generate responses to your prompts. You can pass text directly to `generate_content`, and use the `.text` property to get the text content of the response. Note that the `.text` field will work when there's only one part in the output." |
| 194 | + "Use the `generate_content` method to generate responses to your prompts. You can pass text directly to `generate_content` and use the `.text` property to get the text content of the response. Note that the `.text` field will work when there's only one part in the output." |
195 | 195 | ] |
196 | 196 | }, |
197 | 197 | { |
|
232 | 232 | "source": [ |
233 | 233 | "## Count tokens\n", |
234 | 234 | "\n", |
235 | | - "You can use the `count_tokens` method to calculate the number of input tokens before sending a request to the Gemini API." |
| 235 | + "Tokens are the basic inputs to the Gemini models. You can use the `count_tokens` method to calculate the number of input tokens before sending a request to the Gemini API." |
236 | 236 | ] |
237 | 237 | }, |
238 | 238 | { |
|
267 | 267 | "source": [ |
268 | 268 | "## Send multimodal prompts\n", |
269 | 269 | "\n", |
270 | | - "Use Gemini 2.0 model (`gemini-2.0-flash-exp`), a multimodal model that supports multimodal prompts. You can include text, [PDF documents](../quickstarts/PDF_Files.ipynb), images, [audio](../quickstarts/Audio.ipynb) and [video](../quickstarts/Video.ipynb) in your prompt requests and get text or code responses." |
| 270 | + "Use Gemini 2.0 model (`gemini-2.0-flash-exp`), a multimodal model that supports multimodal prompts. You can include text, [PDF documents](../quickstarts/PDF_Files.ipynb), images, [audio](../quickstarts/Audio.ipynb) and [video](../quickstarts/Video.ipynb) in your prompt requests and get text or code responses.\n", |
| 271 | + "\n", |
| 272 | + "In this first example, you'll download an image from a specified URL, save it as a byte stream and then write those bytes to a local file named `jetpack.png`." |
271 | 273 | ] |
272 | 274 | }, |
273 | 275 | { |
|
301 | 303 | "img_path.write_bytes(img_bytes)" |
302 | 304 | ] |
303 | 305 | }, |
| 306 | + { |
| 307 | + "cell_type": "markdown", |
| 308 | + "metadata": { |
| 309 | + "id": "xSjAMbVjOlnc" |
| 310 | + }, |
| 311 | + "source": [ |
| 312 | + "In this second example, you'll open a previously saved image, create a thumbnail of it and then generate a short blog post based on the thumbnail, displaying both the thumbnail and the generated blog post." |
| 313 | + ] |
| 314 | + }, |
304 | 315 | { |
305 | 316 | "cell_type": "code", |
306 | 317 | "execution_count": null, |
|
401 | 412 | "source": [ |
402 | 413 | "## Configure safety filters\n", |
403 | 414 | "\n", |
404 | | - "The Gemini API provides safety filters that you can adjust across multiple filter categories to restrict or allow certain types of content. You can use these filters to adjust what's appropriate for your use case. See the [Configure safety filters](https://ai.google.dev/gemini-api/docs/safety-settings) page for details." |
| 415 | + "The Gemini API provides safety filters that you can adjust across multiple filter categories to restrict or allow certain types of content. You can use these filters to adjust what is appropriate for your use case. See the [Configure safety filters](https://ai.google.dev/gemini-api/docs/safety-settings) page for details.\n", |
| 416 | + "\n", |
| 417 | + "\n", |
| 418 | + "In this example, you'll use a safety filter to only block highly dangerous content, when requesting the generation of potentially disrespectful phrases." |
405 | 419 | ] |
406 | 420 | }, |
407 | 421 | { |
|
454 | 468 | "source": [ |
455 | 469 | "## Start a multi-turn chat\n", |
456 | 470 | "\n", |
457 | | - "The Gemini API enables you to have freeform conversations across multiple turns." |
| 471 | + "The Gemini API enables you to have freeform conversations across multiple turns.\n", |
| 472 | + "\n", |
| 473 | + "Next you'll set up a helpful coding assistant:" |
458 | 474 | ] |
459 | 475 | }, |
460 | 476 | { |
|
514 | 530 | "Markdown(response.text)" |
515 | 531 | ] |
516 | 532 | }, |
| 533 | + { |
| 534 | + "cell_type": "markdown", |
| 535 | + "metadata": { |
| 536 | + "id": "gWWcDneQO4Ya" |
| 537 | + }, |
| 538 | + "source": [ |
| 539 | + "Here's another example using your new helpful coding assistant:" |
| 540 | + ] |
| 541 | + }, |
517 | 542 | { |
518 | 543 | "cell_type": "code", |
519 | 544 | "execution_count": null, |
|
751 | 776 | "source": [ |
752 | 777 | "## Generate content stream\n", |
753 | 778 | "\n", |
754 | | - "By default, the model returns a response after completing the entire generation process. You can also use the `generate_content_stream` method to stream the response as it is being generated, and the model will return chunks of the response as soon as they are generated.\n", |
| 779 | + "By default, the model returns a response after completing the entire generation process. You can also use the `generate_content_stream` method to stream the response as it's being generated, and the model will return chunks of the response as soon as they're generated.\n", |
755 | 780 | "\n", |
756 | | - "Note that if you are using a thinking model, it will only start streaming after finishing its thinking process." |
| 781 | + "Note that if you're using a thinking model, it'll only start streaming after finishing its thinking process." |
757 | 782 | ] |
758 | 783 | }, |
759 | 784 | { |
|
1016 | 1041 | "source": [ |
1017 | 1042 | "## Function calling\n", |
1018 | 1043 | "\n", |
1019 | | - "[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 the name of a function that matches the description and the arguments to call it with." |
| 1044 | + "[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", |
| 1045 | + "- The name of a function that matches the description.\n", |
| 1046 | + "- The arguments to call it with." |
1020 | 1047 | ] |
1021 | 1048 | }, |
1022 | 1049 | { |
|
1076 | 1103 | "source": [ |
1077 | 1104 | "## Code execution\n", |
1078 | 1105 | "\n", |
1079 | | - "[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. You can find more examples in the [Code execution quickstart guide](./Code_execution.ipynb)" |
| 1106 | + "[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. You can find more examples in the [Code execution quickstart guide](./Code_execution.ipynb)." |
1080 | 1107 | ] |
1081 | 1108 | }, |
1082 | 1109 | { |
|
1185 | 1212 | "source": [ |
1186 | 1213 | "## Upload files\n", |
1187 | 1214 | "\n", |
1188 | | - "Now that you've seen how to send multimodal prompts, try uploading files to the API of different multimedia types. For small images, such as the previous multimodal example, you can point the Gemini model directly to a local file when providing a prompt. When you have larger files, many files, or files you don't want to send over and over again, you can use the File Upload API, and then pass the file by reference.\n", |
| 1215 | + "Now that you've seen how to send multimodal prompts, try uploading files to the API of different multimedia types. For small images, such as the previous multimodal example, you can point the Gemini model directly to a local file when providing a prompt. When you've larger files, many files, or files you don't want to send over and over again, you can use the File Upload API, and then pass the file by reference.\n", |
1189 | 1216 | "\n", |
1190 | 1217 | "For larger text files, images, videos, and audio, upload the files with the File API before including them in prompts." |
1191 | 1218 | ] |
|
1196 | 1223 | "id": "zGswPFKrTvby" |
1197 | 1224 | }, |
1198 | 1225 | "source": [ |
1199 | | - "### Upload an image file\n" |
| 1226 | + "### Upload an image file\n", |
| 1227 | + "\n", |
| 1228 | + "After running this example, you'll have a local copy of the \"jetpack.png\" image in the same directory where your Python script is being executed." |
1200 | 1229 | ] |
1201 | 1230 | }, |
1202 | 1231 | { |
|
1340 | 1369 | "source": [ |
1341 | 1370 | "### Upload a PDF file\n", |
1342 | 1371 | "\n", |
1343 | | - "This PDF page is an article titled [Smoothly editing material properties of objects](https://research.google/blog/smoothly-editing-material-properties-of-objects-with-text-to-image-models-and-synthetic-data/) with text-to-image models and synthetic data available on the Google Research Blog." |
| 1372 | + "This PDF page is an article titled [Smoothly editing material properties of objects](https://research.google/blog/smoothly-editing-material-properties-of-objects-with-text-to-image-models-and-synthetic-data/) with text-to-image models and synthetic data available on the Google Research Blog.\n", |
| 1373 | + "\n", |
| 1374 | + "Firstly you'll download a the PDF file from an URL and save it locally as \"article.pdf" |
1344 | 1375 | ] |
1345 | 1376 | }, |
1346 | 1377 | { |
|
1370 | 1401 | "pdf_path.write_bytes(pdf_bytes)" |
1371 | 1402 | ] |
1372 | 1403 | }, |
| 1404 | + { |
| 1405 | + "cell_type": "markdown", |
| 1406 | + "metadata": { |
| 1407 | + "id": "bjrfdaiYPuIL" |
| 1408 | + }, |
| 1409 | + "source": [ |
| 1410 | + "Secondly, you'll upload the saved PDF file and generate a bulleted list summary of its contents." |
| 1411 | + ] |
| 1412 | + }, |
1373 | 1413 | { |
1374 | 1414 | "cell_type": "code", |
1375 | 1415 | "execution_count": null, |
|
1555 | 1595 | "id": "_yRG9BPXS65b" |
1556 | 1596 | }, |
1557 | 1597 | "source": [ |
1558 | | - "The state of the video is important. The video must finish processing, so do check the state. Once the state of the video is `ACTIVE`, you are able to pass it into `generate_content`." |
| 1598 | + "> **Note:** The state of the video is important. The video must finish processing, so do check the state. Once the state of the video is `ACTIVE`, you're able to pass it into `generate_content`." |
1559 | 1599 | ] |
1560 | 1600 | }, |
1561 | 1601 | { |
|
1656 | 1696 | "source": [ |
1657 | 1697 | "For YouTube links, you don't need to explicitly upload the video file content, but you do need to explicitly declare the video URL you want the model to process as part of the `contents` of the request. For more information see the [vision](https://ai.google.dev/gemini-api/docs/vision?lang=python#youtube) documentation including the features and limits.\n", |
1658 | 1698 | "\n", |
1659 | | - "> **Note:** You are only able to submit up to one YouTube link per `generate_content` request.\n", |
| 1699 | + "> **Note:** You're only able to submit up to one YouTube link per `generate_content` request.\n", |
1660 | 1700 | "\n", |
1661 | | - "> **Note:** YouTube links included as part of the text input won't being processed in the request, an can lead to incorrect responses. You must explicitly the URL using the `file_uri` argument of `FileData`.\n", |
| 1701 | + "> **Note:** If your text input includes YouTube links, the system won't process them, which may result in incorrect responses. To ensure proper handling, explicitly provide the URL using the `file_uri` parameter in `FileData`.\n", |
1662 | 1702 | "\n", |
1663 | 1703 | "The following example shows how you can use the model to summarize the video. In this case use a summary video of [Google I/O 2024](\"https://www.youtube.com/watch?v=WsEQjeZoEng\")." |
1664 | 1704 | ] |
|
1913 | 1953 | "\n", |
1914 | 1954 | "You can get text embeddings for a snippet of text by using `embed_content` method and using the `gemini-embedding-exp-03-07` model.\n", |
1915 | 1955 | "\n", |
1916 | | - "\n", |
1917 | | - "\n", |
1918 | | - "The Gemini Embeddings model produces an output with 3072 dimensions by default. However, you have the option to choose an output dimensionality between 1 and 3072. See the [embeddings guide](https://ai.google.dev/gemini-api/docs/embeddings) for more details." |
| 1956 | + "The Gemini Embeddings model produces an output with 3072 dimensions by default. However, you've the option to choose an output dimensionality between 1 and 3072. See the [embeddings guide](https://ai.google.dev/gemini-api/docs/embeddings) for more details." |
1919 | 1957 | ] |
1920 | 1958 | }, |
1921 | 1959 | { |
|
1964 | 2002 | "id": "Tje8pMbd5z7j" |
1965 | 2003 | }, |
1966 | 2004 | "source": [ |
1967 | | - "You will get a set of three embeddings, one for each piece of text you passed in:" |
| 2005 | + "You'll get a set of three embeddings, one for each piece of text you passed in:" |
1968 | 2006 | ] |
1969 | 2007 | }, |
1970 | 2008 | { |
|
0 commit comments