SPB Git

Repository Public

files.md 30.3 KB 631 lines markdown

1Gemini can handle various types of input data, including text, images, and2audio, at the same time.34This guide shows you how to work with media files using the Files API. The5basic operations are the same for audio files, images, videos, documents, and6other supported file types.78For file prompting guidance, check out the [File prompt guide](https://ai.google.dev/gemini-api/docs/files#prompt-guide) section.910## Upload a file1112You can use the Files API to upload a media file. Always use the Files API when13the total request size (including the files, text prompt, system instructions,14etc.) is larger than 100 MB. For PDF files, the limit is 50 MB.1516The following code uploads a file and then uses the file in a call to17`interactions.create`.1819### Python2021    from google import genai2223    client = genai.Client()2425    myfile = client.files.upload(file="path/to/sample.mp3")2627    interaction = client.interactions.create(28        model="gemini-3.8-flash",29        input=[30            {"type": "text", "text": "Describe this audio clip"},31            {"type": "audio", "uri": myfile.uri, "mime_type": myfile.mime_type}32        ]33    )3435    print(interaction.output_text)3637### JavaScript3839    import { GoogleGenAI } from "@google/genai";4041    const client = new GoogleGenAI({});4243    async function main() {44      const myfile = await client.files.upload({45        file: "path/to/sample.mp3",46        config: { mime_type: "audio/mpeg" },47      });4849      const interaction = await client.interactions.create({50        model: "gemini-3.8-flash",51        input: [52          { type: "text", text: "Describe this audio clip" },53          { type: "audio", uri: myfile.uri, mime_type: myfile.mimeType }54        ]55      });56      console.log(interaction.output_text);57    }5859    await main();6061### Java6263    import com.google.genai.Client;64    import com.google.genai.gaos.models.interactions.AudioContent;65    import com.google.genai.gaos.models.interactions.AudioContentMimeType;66    import com.google.genai.gaos.models.interactions.Content;67    import com.google.genai.gaos.models.interactions.CreateModelInteraction;68    import com.google.genai.gaos.models.interactions.Interaction;69    import com.google.genai.gaos.models.interactions.InteractionsInput;70    import com.google.genai.gaos.models.interactions.Model;71    import com.google.genai.gaos.models.interactions.TextContent;72    import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;73    import com.google.genai.types.File;74    import com.google.genai.types.UploadFileConfig;75    import java.util.Arrays;76    import java.util.List;7778    Client client = new Client();7980    File myFile =81        client.files.upload(82            new java.io.File("path/to/sample.mp3"),83            UploadFileConfig.builder().mimeType("audio/mp3").build());8485    Content textContent = TextContent.builder().text("Describe this audio clip").build();86    Content audioContent =87        AudioContent.builder()88            .uri(myFile.uri().orElse(""))89            .mimeType(AudioContentMimeType.of(myFile.mimeType().orElse("audio/mp3")))90            .build();9192    List<Content> contents = Arrays.asList(textContent, audioContent);9394    CreateModelInteraction params =95        CreateModelInteraction.builder()96            .model(Model.of("gemini-3.8-flash"))97            .input(InteractionsInput.ofContent(contents))98            .build();99100    Interaction interaction =101        client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();102103    System.out.println(interaction.outputText().orElse(""));104105### Go106107    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)108    if err != nil {109        log.Fatal(err)110    }111    defer client.Files.Delete(ctx, file.Name)112113    interaction, err := client.Interactions.Create(ctx, "gemini-3.8-flash", &genai.InteractionRequest{114        Input: []interface{}{115            genai.NewPartFromFile(*file),116            genai.NewPartFromText("Describe this audio clip"),117        },118    }, nil)119120    if err != nil {121        log.Fatal(err)122    }123124    // Print the model's text response125    for _, step := range interaction.Steps {126        if step.Type == "model_output" {127            for _, part := range step.Content {128                if part.Type == "text" {129                    fmt.Println(part.Text)130                }131            }132        }133    }134135### REST136137    AUDIO_PATH="path/to/sample.mp3"138    MIME_TYPE=$(file -b --mime-type "${AUDIO_PATH}")139    NUM_BYTES=$(wc -c < "${AUDIO_PATH}")140    DISPLAY_NAME=AUDIO141142    tmp_header_file=upload-header.tmp143144    # Initial resumable request defining metadata.145    # The upload url is in the response headers dump them to a file.146    curl "${BASE_URL}/upload/v1beta/files" \147      -H "x-goog-api-key: $GEMINI_API_KEY" \148      -D "${tmp_header_file}" \149      -H "X-Goog-Upload-Protocol: resumable" \150      -H "X-Goog-Upload-Command: start" \151      -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \152      -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \153      -H "Content-Type: application/json" \154      -d "{'file': {'display_name': '${DISPLAY_NAME}'}}" 2> /dev/null155156    upload_url=$(grep -i "x-goog-upload-url: " "${tmp_header_file}" | cut -d" " -f2 | tr -d "\r")157    rm "${tmp_header_file}"158159    # Upload the actual bytes.160    curl "${upload_url}" \161      -H "Content-Length: ${NUM_BYTES}" \162      -H "X-Goog-Upload-Offset: 0" \163      -H "X-Goog-Upload-Command: upload, finalize" \164      --data-binary "@${AUDIO_PATH}" 2> /dev/null > file_info.json165166    file_uri=$(jq ".file.uri" file_info.json)167    echo file_uri=$file_uri168169    # Now create an interaction using the Interactions API170    curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \171        -H "x-goog-api-key: $GEMINI_API_KEY" \172        -H 'Content-Type: application/json' \173        -d '{174          "model": "gemini-3.8-flash",175          "input": [176            {"type": "text", "text": "Describe this audio clip"},177            {"type": "audio", "uri": '$file_uri', "mime_type": "'${MIME_TYPE}'"}178          ]179        }' 2> /dev/null > response.json180181    cat response.json182    echo183184    jq ".outputs[] | select(.type == \"text\") | .text" response.json185186## Get metadata for a file187188You can verify that the API successfully stored the uploaded file and get its189metadata by calling `files.get`.190191### Python192193    from google import genai194195    client = genai.Client()196197    myfile = client.files.upload(file='path/to/sample.mp3')198    file_name = myfile.name199    myfile = client.files.get(name=file_name)200    print(myfile)201202### JavaScript203204    import {205      GoogleGenAI,206    } from "@google/genai";207208    const client = new GoogleGenAI({});209210    async function main() {211      const myfile = await client.files.upload({212        file: "path/to/sample.mp3",213        config: { mime_type: "audio/mpeg" },214      });215216      const fileName = myfile.name;217      const fetchedFile = await client.files.get({ name: fileName });218      console.log(fetchedFile);219    }220221    await main();222223### Java224225    import com.google.genai.Client;226    import com.google.genai.types.File;227    import com.google.genai.types.UploadFileConfig;228229    Client client = new Client();230231    File myFile =232        client.files.upload(233            new java.io.File("path/to/sample.mp3"),234            UploadFileConfig.builder().mimeType("audio/mp3").build());235236    String fileName = myFile.name().orElse("");237    File fileMetadata = client.files.get(fileName, null);238    System.out.println(fileMetadata);239240### Go241242    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)243    if err != nil {244        log.Fatal(err)245    }246247    gotFile, err := client.Files.Get(ctx, file.Name)248    if err != nil {249        log.Fatal(err)250    }251    fmt.Println("Got file:", gotFile.Name)252253### REST254255    # file_info.json was created in the upload example256    name=$(jq -r ".file.name" file_info.json)257    # Get the file of interest to check state258    curl https://generativelanguage.googleapis.com/v1beta/$name \259    -H "x-goog-api-key: $GEMINI_API_KEY" > file_info.json260    # Print some information about the file you got261    name=$(jq -r ".name" file_info.json)262    echo name=$name263    file_uri=$(jq -r ".uri" file_info.json)264    echo file_uri=$file_uri265266## List uploaded files267268The following code gets a list of all the files uploaded:269270### Python271272    from google import genai273274    client = genai.Client()275276    print('My files:')277    for f in client.files.list():278        print(' ', f.name)279280### JavaScript281282    import {283      GoogleGenAI,284    } from "@google/genai";285286    const client = new GoogleGenAI({});287288    async function main() {289      const listResponse = await client.files.list({ config: { pageSize: 10 } });290      for await (const file of listResponse) {291        console.log(file.name);292      }293    }294295    await main();296297### Java298299    import com.google.genai.Client;300    import com.google.genai.types.File;301302    Client client = new Client();303304    System.out.println("My files:");305    for (File f : client.files.list(null)) {306      System.out.println("  " + f.name().orElse(""));307    }308309### Go310311    for file, err := range client.Files.All(ctx) {312      if err != nil {313        log.Fatal(err)314      }315      fmt.Println(file.Name)316    }317318### REST319320    echo "My files: "321322    curl "https://generativelanguage.googleapis.com/v1beta/files" \323      -H "x-goog-api-key: $GEMINI_API_KEY"324325## Delete uploaded files326327Files are automatically deleted after 48 hours. You can also manually delete an328uploaded file:329330### Python331332    from google import genai333334    client = genai.Client()335336    myfile = client.files.upload(file='path/to/sample.mp3')337    client.files.delete(name=myfile.name)338339### JavaScript340341    import {342      GoogleGenAI,343    } from "@google/genai";344345    const client = new GoogleGenAI({});346347    async function main() {348      const myfile = await client.files.upload({349        file: "path/to/sample.mp3",350        config: { mime_type: "audio/mpeg" },351      });352353      const fileName = myfile.name;354      await client.files.delete({ name: fileName });355    }356357    await main();358359### Java360361    import com.google.genai.Client;362    import com.google.genai.types.File;363    import com.google.genai.types.UploadFileConfig;364365    Client client = new Client();366367    File myFile =368        client.files.upload(369            new java.io.File("path/to/sample.mp3"),370            UploadFileConfig.builder().mimeType("audio/mp3").build());371372    client.files.delete(myFile.name().orElse(""), null);373374### Go375376    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)377    if err != nil {378        log.Fatal(err)379    }380    client.Files.Delete(ctx, file.Name)381382### REST383384    curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/$name \385      -H "x-goog-api-key: $GEMINI_API_KEY"386387## Usage information388389You can use the Files API to upload and interact with media files. The Files API390lets you store up to 20 GB of files per project, with a per-file maximum391size of 2 GB. Files are stored for 48 hours.392393During that time, you can use the API to get metadata about the files. However,394you can't download user-uploaded files. You can download files generated by395models, such as videos, using the `files.download` method. The Files API is396available at no cost in all regions where the Gemini API is available.397398## File prompting strategies399400This section provides guidance and best practices for using media files with401prompts for the Gemini API.402403Being able to use various types of data in your prompts gives you more404flexibility in terms of what tasks you can tackle with the Gemini API. For405example, you can send the model a photo of a delicious meal and ask it to write406a short blog about the meal.407408|---|---|409| **Prompt** | **Response** |410| Write a short, engaging blog post based on this picture. It should include a description of the meal in the photo and talk about my journey meal prepping. <br /> ![Cookies](https://ai.google.dev/static/gemini-api/docs/images/image_prompt.png) | Meal prepping is a great way to save time and money, and it can also help you to eat healthier. This meal is a great example of a healthy and delicious meal that can be prepped ahead of time. This meal features brown rice, roasted vegetables, and chicken teriyaki. The brown rice is a healthy and complex carbohydrate that will give you sustained energy. The roasted vegetables are a great way to get your daily dose of vitamins and minerals, and the chicken teriyaki is a delicious and protein-rich option. This meal is also straightforward to prepare. Simply cook the brown rice, roast the vegetables, and cook the chicken teriyaki. Once everything is cooked, divide it into meal prep containers and store them in the refrigerator. You can then grab a container and go on busy mornings! If you're looking for a healthy and delicious meal that can be prepped ahead of time, this meal is a great option. It's packed with nutrients and flavor, and it's sure to keep you feeling full and satisfied. Here's to healthy and delicious meal prepping! |411412If you are having trouble getting the output you want from prompts that use413media files, there are some strategies that can help you get the results you414want. The following sections provide design approaches and troubleshooting415tips for improving prompts that use multimodal input.416417You can improve your multimodal prompts by following these best practices:418419-420421  ### [Prompt design fundamentals](https://ai.google.dev/gemini-api/docs/files#specific-instructions)422423  - **Be specific in your instructions**: Craft clear and concise instructions that leave minimal room for misinterpretation.424  - **Add a few examples to your prompt:** Use realistic few-shot examples to illustrate what you want to achieve.425  - **Break it down step-by-step**: Divide complex tasks into manageable sub-goals, guiding the model through the process.426  - **Specify the output format**: In your prompt, ask for the output to be in the format you want, like Markdown, JSON, HTML and more.427  - **Put your image first for single-image prompts**: While Gemini can handle image and text inputs in any order, for prompts containing a single image, it might perform better if that image (or video) is placed before the text prompt. However, for prompts that require images to be highly interleaved with texts to make sense, use whatever order is most natural.428-429430  ### [Troubleshooting your multimodal prompt](https://ai.google.dev/gemini-api/docs/files#troubleshooting)431432  - **If the model is not drawing information from the relevant part of the image:** Drop hints with which aspects of the image you want the prompt to draw information from.433  - **If the model output is too generic (not tailored enough to the image/video input):**At the start of the prompt, try asking the model to describe the image(s) or video before providing the task instruction, or try asking the model to refer to what's in the image.434  - **To troubleshoot which part failed:** Ask the model to describe the image, or ask the model to explain its reasoning, to gauge the model's initial understanding.435  - **If your prompt results in hallucinated content:** Try dialing down the temperature setting or asking the model for shorter descriptions so that it's less likely to extrapolate additional details.436  - **Tuning the sampling parameters:** Experiment with different temperature settings and top-k selections to adjust the model's creativity.437438### Be specific in your instructions439440Prompts have the most success when they are clear and detailed. If you have a441specific output in mind, it's better to include that requirement in the prompt442to ensure you get the output you want.443444For this image of an airport board, asking the model to just "describe this445image" could generate a general description. If you need the model to parse the446time and city from the image, you can include that request directly in your447prompt.448449| Prompt | Model response |450|---|---|451| ![](https://ai.google.dev/static/gemini-api/docs/images/timetable.png) Describe this image. | The image shows an airport arrivals and departures board. |452453<br />454455| **Updated prompt** | **Improved response** |456|---|---|457| ![Travel timetable](https://ai.google.dev/static/gemini-api/docs/images/timetable.png) Parse the time and city from the airport board shown in this image into a list. | <br /> - 10:50 Moscow - 11:05 Edinburgh - 11:05 London - 11:10 Bucharest - 11:30 Kiev - 11:35 Dublin - 11:45 East Midlands - 12:15 Sofia - 12:30 London - 12:30 Newcastle - 12:40 St Petersburg - 12:40 London - 12:45 Manchester |458459<br />460461### Add a few examples462463The Gemini model can accept multiple inputs which it can use as examples to464understand the output you want. Adding these examples can help the model465identify the patterns and apply the relationship between the given images and466responses to the new example. This is also called "few-shot" learning.467468In the following example, the initial output is written in sentence form,469and also contains the country (Brazil). Suppose you want the output in a470different format or style, and you want only the city, not the country. Adding471few-shot examples to your prompt can steer the model to respond in the way you472want.473474<br />475476| **Prompt** | **Model response** |477|---|---|478| ![Travel timetable](https://ai.google.dev/static/gemini-api/docs/images/redeemer.png) Determine the city along with the landmark. | The landmark is the Christ the Redeemer statue in Rio de Janeiro, Brazil. |479480<br />481482| **Updated prompt** | **Improved response** |483|---|---|484| Determine the city along with the landmark. ![colosseum](https://ai.google.dev/static/gemini-api/docs/images/colosseum.png) | city: Rome, landmark: the Colosseum. |485| ![Forbidden City](https://ai.google.dev/static/gemini-api/docs/images/forbidden-city.png) | city: Beijing, landmark: Forbidden City |486| ![forbidden-city](https://ai.google.dev/static/gemini-api/docs/images/redeemer.png) | city: Rio de Janeiro, landmark: Christ the Redeemer statue |487488### Break it down step-by-step489490For complex tasks like the ones that require both visual understanding and491reasoning, it can be helpful to split the task into smaller, more492straightforward steps. Alternatively, it could also be effective if you493directly ask the model to "think step by step" in your prompt.494495| Prompt | Model response |496|---|---|497| ![](https://ai.google.dev/static/gemini-api/docs/images/toilet-paper.jpg) When will I run out of toilet paper? | Soon, you only have 3 rolls left. |498499| **Updated prompt** | **Improved response** |500|---|---|501| ![](https://ai.google.dev/static/gemini-api/docs/images/toilet-paper.jpg) 1. First, count how many toilet paper rolls are in this picture. 2. Then, determine how much toilet paper a typical person uses per day. 3. Calculate how long these rolls of toilet paper will last. | 1. There are 3 rolls of toilet paper in this picture. 2. A typical person uses about 20 sheets of toilet paper per day. 3. If each roll contains 200 sheets, then each roll will last for about 10 days. Therefore, the 3 rolls will last for about a month. |502503Math problems or other types of word problems are great candidates for asking504the model to think step-by-step.505506| **Prompt** | **Response** |507|---|---|508| ![](https://ai.google.dev/static/gemini-api/docs/images/math.jpg) What is the 4th term in the sequence? | -135 |509510The response from the model is incorrect. Some ways to improve this is to ask511the model to parse the problem before answering the prompt.512513| **Prompt** | **Response** |514|---|---|515| ![](https://ai.google.dev/static/gemini-api/docs/images/math.jpg) Parse the formula in the image first. Then based on the formula, answer "what's the 4th term in the sequence?". | *Click to expand the result* $$ b(n) = b(n-1) \* (-3) $$ $$ b(1) = 15 $$ 1. Substitute n = 4 into the formula: $$ b(4) = b(4-1) \* (-3) $$ $$ b(4) = b(3) \* (-3) $$ 2. We don't know the value of b(3), so substitute n = 3 into the formula: $$ b(3) = b(3-1) \* (-3) $$ $$ b(3) = b(2) \* (-3) $$ 3. We don't know the value of b(2), so substitute n = 2 into the formula: $$ b(2) = b(2-1) \* (-3) $$ $$ b(2) = b(1) \* (-3) $$ 4. We know the value of b(1) is 15, so substitute it into the formula: $$ b(2) = 15 \* (-3) $$ $$ b(2) = -45 $$ 5. Now that we know the value of b(2), substitute it into the formula for b(3): $$ b(3) = b(2) \* (-3) $$ $$ b(3) = -45 \* (-3) $$ $$ b(3) = 135 $$ 6. Now that we know the value of b(3), substitute it into the formula for b(4): $$ b(4) = b(3) \* (-3) $$ $$ b(4) = 135 \* (-3) $$ $$ b(4) = -405 $$ Therefore, the 4th term in the sequence is -405. |516517This model response is correct - now to make the response even more streamlined,518you can ask the model to to think step-by-step.519520<br />521522| **Updated prompt** | **Improved response** |523|---|---|524| ![](https://ai.google.dev/static/gemini-api/docs/images/math.jpg) What is the 4th term in the sequence? Think step by step. | The first term is 15. The second term is b(1) \* (-3) = 15 \* (-3) = -45. The third term is b(2) \* (-3) = -45 \* (-3) = 135. The fourth term is b(3) \* (-3) = 135 \* (-3) = -405. |525526<br />527528### Specify the output format529530A common problem is the need for model output to be in a certain format531(e.g. Markdown, JSON, HTML), especially if the model output needs to532be ingested by a downstream task. You can try to produce output in that format533by instructing the model to do so within the prompt. The following are two534examples:535536| Prompt | Model response |537|---|---|538| ![](https://ai.google.dev/static/gemini-api/docs/images/excel-example.png) Parse the table in this image into Markdown format | \`\`\`none \| Subject \| Status \| Time \| Start date \| Due on \| \| --- \| --- \| --- \| --- \| --- \| \| Math \| Done \| 1.5 hrs \| 11/29/2023 \| 12/1/2023 \| \| Geography \| Done \| 30 min \| 12/2/2023 \| 12/4/2023 \| \| Physics \| In progress \| 2 hrs \| 12/3/2023 \| 12/5/2023 \| \| Biology \| Not started \| 6 hrs \| 11/2/2016 \| 12/6/2023 \| \`\`\` |539540| **Prompt** | **Model response** |541|---|---|542| ![](https://ai.google.dev/static/gemini-api/docs/images/spanish-meal.png) Provide a list of all the following attributes: ingredients, type of cuisine, vegetarian or not, in JSON format | \`\`\`json { "ingredients": \[ "rice", "shrimp", "clams", "mussels", "peas", "tomatoes", "onions", "garlic", "olive oil", "paprika", "salt", "pepper" \], "type of cuisine": "Spanish", "vegetarian": false } \`\`\` |543544### Put your image first for single-image prompts545546While Gemini can interpret image and text in any order within a prompt, placing547a single image before the text prompt might lead to better results.548In the following samples, you'll notice the image comes first before the text in549each prompt.550551### Troubleshooting your multimodal prompt552553You might need to troubleshoot your prompt if you are not getting a helpful554response. Here are a few strategies you could try.555556#### If the model is not drawing information from the relevant part of the image557558To get a more specific response, you can point out which aspects of the image559you want the prompt to draw information from to inform its response.560561| Prompt | Model response |562|---|---|563| ![](https://ai.google.dev/static/gemini-api/docs/images/diapers.png) How many days will these diapers last a baby? | The diapers will last for 198 days before they run out. |564565| **Updated prompt** | **Improved response** |566|---|---|567| ![](https://ai.google.dev/static/gemini-api/docs/images/diapers.png) How long will these diapers last before I run out? Use the weight shown on the box to determine the child's age, and use the total number of diapers in the box. Divide the total number by how many diapers the child goes through per day. | The box contains 198 diapers. The box states the diapers are for a child weighing 22-37 lbs. The average child in this weight range is likely between 1 and 2 years old. A 2-year-old typically goes through 6 diapers per day, therefore, the diapers will last around 33 days (198/6). |568569#### If the model output is too generic and not tailored enough to the image input570571To help the model tailor its response to the image(s), try asking it to describe572the images before performing its reasoning task.573574| Prompt | Model response |575|---|---|576| ![](https://ai.google.dev/static/gemini-api/docs/images/packing.jpg) ![](https://ai.google.dev/static/gemini-api/docs/images/mall.jpg) ![](https://ai.google.dev/static/gemini-api/docs/images/toilet-paper.jpg) ![](https://ai.google.dev/static/gemini-api/docs/images/ocean.jpg) What is in common between these images? | All four images are examples of landscape photography. |577578| **Updated prompt** | **Improved response** |579|---|---|580| ![](https://ai.google.dev/static/gemini-api/docs/images/packing.jpg) ![](https://ai.google.dev/static/gemini-api/docs/images/mall.jpg) ![](https://ai.google.dev/static/gemini-api/docs/images/toilet-paper.jpg) ![](https://ai.google.dev/static/gemini-api/docs/images/ocean.jpg) First, describe what's in each image in detail. What's in common between these images? | The first image shows a person packing a suitcase. The second image shows an empty hallway in a shopping mall. The third image shows a roll of toilet paper. The fourth image shows a dark and stormy sea. The commonality between these images is that they are all examples of liminal spaces. Liminal spaces are places or situations that are in between two other places or situations. They are often characterized by a sense of uncertainty or ambiguity. The first image shows the person in between being at home and being on a trip. The second image shows the hallway in between two stores. The third image is of toilet paper, which can represent a bathroom. A bathroom is a transitional space between private and public realms. It's a place where we prepare ourselves to enter or leave the outside world. The fourth image shows the sea in between being calm and being stormy. Liminal spaces can be both exciting and unsettling. They can be a place of new beginning or a place of endings. They can be a place of reflection or a place of action. |581582You can also try explicitly asking the model to refer to what's in the image.583584| **Updated prompt** | **Improved response** |585|---|---|586| ![](https://ai.google.dev/static/gemini-api/docs/images/packing.jpg) ![](https://ai.google.dev/static/gemini-api/docs/images/mall.jpg) ![](https://ai.google.dev/static/gemini-api/docs/images/toilet-paper.jpg) ![](https://ai.google.dev/static/gemini-api/docs/images/ocean.jpg) What is in common between these images? Refer to what's in the images in your response. | All of the images are related to travel. The first image shows a person packing a suitcase, the second image shows an empty hallway in a shopping mall, the third image shows a stack of toilet paper, and the fourth image shows a dark and stormy sea. These images are all related to travel because they are all things that people need or use when they travel. The first image shows a person packing a suitcase, which is something that people do when they are going on a trip. The second image shows an empty hallway in a shopping mall, which is a place where people often go to buy things for their trips. The third image shows a stack of toilet paper, which is something that people often use when they are traveling. The fourth image shows a dark and stormy sea, which is something that people often encounter when they are traveling. |587588The same tips work for creative output from images. In the following example with589the rabbit, explicitly asking the model to include aspects from the image can590improve the output.591592| Prompt | Model response |593|---|---|594| ![](https://ai.google.dev/static/gemini-api/docs/images/rabbit.jpg) Can you write me a poem about this image? | Little bunny, so soft and brown, Hopping through the field, up and down. Your ears so long, your tail so small, You're the cutest creature of them all. You nibble on the grass, so green and sweet, And hop away when you see me. But I'll always be your friend, Little bunny, until the very end. |595596<br />597598| **Updated prompt** | **Improved response** |599|---|---|600| ![](https://ai.google.dev/static/gemini-api/docs/images/rabbit.jpg) Can you write me a descriptive and dramatic poem about this image and include the location? | Little bunny on the green, Ears so long, so keen. What do you see out there, In the distance, where you stare? Is it the ocean blue, Sparkling in the sun's hue? Or the waves that crash and roar, A rhythm that you adore? Little bunny, tell me true, What captures your attention so? Is it the salty breeze, Or the seagulls' cries that please? Perhaps it's the vastness of it all, A world so big and small. A place where dreams can roam, And adventures can be sown. Little bunny, I wonder what you dream, As you sit on the grass, so serene. Do you yearn to explore the deep, Or stay on land, where you can leap? Whatever it may be, little bunny, Keep that spark of wonder burning brightly. For in your dreams and aspirations, Lies a world waiting for your creation. |601602<br />603604#### Troubleshooting which part of the prompt failed605606It can be hard to know whether a prompt failed because the model607didn't **understand the image** to begin with, or if it did understand the image608but did not perform the correct **reasoning steps** afterward.609To disambiguate between those reasons, ask the model to describe what's in the image.610611In the following example, if the model responds with a snack that seems surprising612when paired with tea (e.g. popcorn), you can first troubleshoot to determine613whether the model correctly recognized that the image contains tea.614615| Prompt | Prompt for troubleshooting |616|---|---|617| ![](https://ai.google.dev/static/gemini-api/docs/images/tea-set.png) What's a snack I can make in 1 minute that would go well with this? | ![](https://ai.google.dev/static/gemini-api/docs/images/tea-set.png) Describe what's in this image. |618619Another strategy is to ask the model to explain its reasoning. That can help you620narrow down which part of the reasoning broke down, if any.621622| Prompt | Prompt for troubleshooting |623|---|---|624| ![](https://ai.google.dev/static/gemini-api/docs/images/tea-set.png) What's a snack I can make in 1 minute that would go well with this? | ![](https://ai.google.dev/static/gemini-api/docs/images/tea-set.png) What's a snack I can make in 1 minute that would go well with this? Please explain why. |625626## What's next627628- Try writing your own multimodal prompts using [Google AI629  Studio](http://aistudio.google.com).630- For information on using the Gemini Files API for uploading media files and including them in your prompts, see the [Vision](https://ai.google.dev/gemini-api/docs/vision), [Audio](https://ai.google.dev/gemini-api/docs/audio), and [Document processing](https://ai.google.dev/gemini-api/docs/document-processing) guides.631- For more guidance on prompt design, like tuning sampling parameters, see the [Prompt strategies](https://ai.google.dev/gemini-api/docs/prompting-strategies) page.
Files main
Menu

Theme