Files API, Files API, Files API, Files API

Binjakët mund të trajtojnë lloje të ndryshme të të dhënave hyrëse, duke përfshirë tekstin, imazhet dhe audion, në të njëjtën kohë.

Ky udhëzues ju tregon se si të punoni me skedarët media duke përdorur API-n e Skedarëve. Operacionet bazë janë të njëjta për skedarët audio, imazhet, videot, dokumentet dhe llojet e tjera të skedarëve të mbështetur.

Për udhëzime rreth kërkesës për skedarë, shikoni seksionin Udhëzuesi i kërkesës për skedarë .

Ngarko një skedar

Mund të përdorni API-në e Skedarëve për të ngarkuar një skedar mediatik. Përdorni gjithmonë API-në e Skedarëve kur madhësia totale e kërkesës (duke përfshirë skedarët, njoftimin me tekst, udhëzimet e sistemit, etj.) është më e madhe se 100 MB. Për skedarët PDF, limiti është 50 MB.

Kodi i mëposhtëm ngarkon një skedar dhe më pas e përdor skedarin në një thirrje për generateContent .

Python

from google import genai

client = genai.Client()

myfile = client.files.upload(file="path/to/sample.mp3")

response = client.models.generate_content(
    model="gemini-3.8-flash", contents=["Describe this audio clip", myfile]
)

print(response.text)

JavaScript

import {
  GoogleGenAI,
  createUserContent,
  createPartFromUri,
} from "@google/genai";

const ai = new GoogleGenAI({});

async function main() {
  const myfile = await ai.files.upload({
    file: "path/to/sample.mp3",
    config: { mimeType: "audio/mpeg" },
  });

  const response = await ai.models.generateContent({
    model: "gemini-3.8-flash",
    contents: createUserContent([
      createPartFromUri(myfile.uri, myfile.mimeType),
      "Describe this audio clip",
    ]),
  });
  console.log(response.text);
}

await main();

Shko

file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
    log.Fatal(err)
}
defer client.Files.Delete(ctx, file.Name)

resp, err := client.Models.GenerateContent(ctx, "gemini-3.8-flash", []*genai.Content{
  {
    Parts: []*genai.Part{
      genai.NewPartFromFile(*file),
      genai.NewPartFromText("Describe this audio clip"),
    },
  },
}, nil)

if err != nil {
    log.Fatal(err)
}

printResponse(resp)

PUSHTIM

AUDIO_PATH="path/to/sample.mp3"
MIME_TYPE=$(file -b --mime-type "${AUDIO_PATH}")
NUM_BYTES=$(wc -c < "${AUDIO_PATH}")
DISPLAY_NAME=AUDIO

tmp_header_file=upload-header.tmp

# Initial resumable request defining metadata.
# The upload url is in the response headers dump them to a file.
curl "${BASE_URL}/upload/v1beta/files" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -D "${tmp_header_file}" \
  -H "X-Goog-Upload-Protocol: resumable" \
  -H "X-Goog-Upload-Command: start" \
  -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
  -H "Content-Type: application/json" \
  -d "{'file': {'display_name': '${DISPLAY_NAME}'}}" 2> /dev/null

upload_url=$(grep -i "x-goog-upload-url: " "${tmp_header_file}" | cut -d" " -f2 | tr -d "\r")
rm "${tmp_header_file}"

# Upload the actual bytes.
curl "${upload_url}" \
  -H "Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Offset: 0" \
  -H "X-Goog-Upload-Command: upload, finalize" \
  --data-binary "@${AUDIO_PATH}" 2> /dev/null > file_info.json

file_uri=$(jq ".file.uri" file_info.json)
echo file_uri=$file_uri

# Now generate content using that file
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent" \
    -H "x-goog-api-key: $GEMINI_API_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
      "contents": [{
        "parts":[
          {"text": "Describe this audio clip"},
          {"file_data":{"mime_type": "${MIME_TYPE}", "file_uri": '$file_uri'}}]
        }]
      }' 2> /dev/null > response.json

cat response.json
echo

jq ".candidates[].content.parts[].text" response.json

Merrni metadata për një skedar

Mund të verifikoni që API-ja e ka ruajtur me sukses skedarin e ngarkuar dhe të merrni meta të dhënat e tij duke thirrur files.get .

Python

from google import genai

client = genai.Client()

myfile = client.files.upload(file='path/to/sample.mp3')
file_name = myfile.name
myfile = client.files.get(name=file_name)
print(myfile)

JavaScript

import {
  GoogleGenAI,
} from "@google/genai";

const ai = new GoogleGenAI({});

async function main() {
  const myfile = await ai.files.upload({
    file: "path/to/sample.mp3",
    config: { mimeType: "audio/mpeg" },
  });

  const fileName = myfile.name;
  const fetchedFile = await ai.files.get({ name: fileName });
  console.log(fetchedFile);
}

await main();

Shko

file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
    log.Fatal(err)
}

gotFile, err := client.Files.Get(ctx, file.Name)
if err != nil {
    log.Fatal(err)
}
fmt.Println("Got file:", gotFile.Name)

PUSHTIM

# file_info.json was created in the upload example
name=$(jq ".file.name" file_info.json)
# Get the file of interest to check state
curl https://generativelanguage.googleapis.com/v1beta/files/$name \
-H "x-goog-api-key: $GEMINI_API_KEY" > file_info.json
# Print some information about the file you got
name=$(jq ".file.name" file_info.json)
echo name=$name
file_uri=$(jq ".file.uri" file_info.json)
echo file_uri=$file_uri

Listo skedarët e ngarkuar

Kodi i mëposhtëm merr një listë të të gjithë skedarëve të ngarkuar:

Python

from google import genai

client = genai.Client()

print('My files:')
for f in client.files.list():
    print(' ', f.name)

JavaScript

import {
  GoogleGenAI,
} from "@google/genai";

const ai = new GoogleGenAI({});

async function main() {
  const listResponse = await ai.files.list({ config: { pageSize: 10 } });
  for await (const file of listResponse) {
    console.log(file.name);
  }
}

await main();

Shko

for file, err := range client.Files.All(ctx) {
  if err != nil {
    log.Fatal(err)
  }
  fmt.Println(file.Name)
}

PUSHTIM

echo "My files: "

curl "https://generativelanguage.googleapis.com/v1beta/files" \
  -H "x-goog-api-key: $GEMINI_API_KEY"

Fshi skedarët e ngarkuar

Skedarët fshihen automatikisht pas 48 orësh. Gjithashtu mund ta fshini manualisht një skedar të ngarkuar:

Python

from google import genai

client = genai.Client()

myfile = client.files.upload(file='path/to/sample.mp3')
client.files.delete(name=myfile.name)

JavaScript

import {
  GoogleGenAI,
} from "@google/genai";

const ai = new GoogleGenAI({});

async function main() {
  const myfile = await ai.files.upload({
    file: "path/to/sample.mp3",
    config: { mimeType: "audio/mpeg" },
  });

  const fileName = myfile.name;
  await ai.files.delete({ name: fileName });
}

await main();

Shko

file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
    log.Fatal(err)
}
client.Files.Delete(ctx, file.Name)

PUSHTIM

curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/files/$name \
  -H "x-goog-api-key: $GEMINI_API_KEY"

Informacion përdorimi

Mund të përdorni API-n e Skedarëve për të ngarkuar dhe bashkëvepruar me skedarët mediatikë. API-ja e Skedarëve ju lejon të ruani deri në 20 GB skedarë për projekt, me një madhësi maksimale për skedar prej 2 GB. Skedarët ruhen për 48 orë.

Gjatë asaj kohe, mund ta përdorni API-në për të marrë meta të dhëna rreth skedarëve. Megjithatë, nuk mund të shkarkoni skedarë të ngarkuar nga përdoruesit. Mund të shkarkoni skedarë të gjeneruar nga modelet, siç janë videot, duke përdorur metodën files.download . API-ja e skedarëve është e disponueshme pa pagesë në të gjitha rajonet ku është e disponueshme API-ja Gemini.

Strategjitë e nxitjes së skedarëve

Ky seksion ofron udhëzime dhe praktikat më të mira për përdorimin e skedarëve media me kërkesa për Gemini API.

Mundësia për të përdorur lloje të ndryshme të të dhënave në kërkesat tuaja ju jep më shumë fleksibilitet në lidhje me detyrat që mund të trajtoni me Gemini API. Për shembull, mund t'i dërgoni modelit një foto të një vakti të shijshëm dhe t'i kërkoni të shkruajë një blog të shkurtër rreth tij.

Nxitje Përgjigje

Shkruaj një postim të shkurtër dhe tërheqës në blog bazuar në këtë fotografi. Duhet të përfshijë një përshkrim të vaktit në foto dhe të flasë për udhëtimin tim të përgatitjes së vakteve.


Kukitë

Përgatitja e vakteve është një mënyrë e shkëlqyer për të kursyer kohë dhe para, dhe gjithashtu mund t'ju ndihmojë të hani më shëndetshëm. Ky vakt është një shembull i shkëlqyer i një vakti të shëndetshëm dhe të shijshëm që mund të përgatitet lehtësisht paraprakisht.

Ky vakt përmban oriz të kaftë, perime të pjekura në furrë dhe pulë teriyaki. Orizi i kaftë është një karbohidrat i shëndetshëm dhe kompleks që do t'ju japë energji të qëndrueshme. Perimet e pjekura janë një mënyrë e shkëlqyer për të marrë dozën tuaj të përditshme të vitaminave dhe mineraleve, dhe pula teriyaki është një opsion i shijshëm dhe i pasur me proteina.

Ky vakt është gjithashtu shumë i lehtë për t’u përgatitur. Thjesht gatuani orizin e kaftë, piqni perimet dhe gatuani pulën teriyaki. Pasi të jetë gatuar gjithçka, ndajeni në enë përgatitore dhe vendosini në frigorifer. Pastaj mund të merrni një enë dhe të shkoni në mëngjeset e ngarkuara!

Nëse jeni duke kërkuar një vakt të shëndetshëm dhe të shijshëm që mund të përgatitet lehtësisht paraprakisht, ky vakt është një zgjedhje e shkëlqyer. Është i mbushur me lëndë ushqyese dhe shije, dhe me siguri do t'ju mbajë të ngopur dhe të kënaqur.

Ja ku është përgatitja e vakteve të shëndetshme dhe të shijshme!

Nëse keni probleme me marrjen e rezultatit që dëshironi nga kërkesat që përdorin skedarë mediatikë, ekzistojnë disa strategji që mund t'ju ndihmojnë të merrni rezultatet që dëshironi. Seksionet e mëposhtme ofrojnë qasje në dizajn dhe këshilla për zgjidhjen e problemeve për përmirësimin e kërkesave që përdorin hyrje multimodale.

Ju mund t'i përmirësoni kërkesat tuaja multimodale duke ndjekur këto praktika më të mira:

  • Bazat e dizajnit të shpejtë

    • Ji specifik në udhëzimet e tua : Harto udhëzime të qarta dhe koncize që lënë hapësirë ​​minimale për keqinterpretime.
    • Shtoni disa shembuj në kërkesën tuaj: Përdorni shembuj realistë me pak shembuj për të ilustruar atë që dëshironi të arrini.
    • Ndani atë hap pas hapi : Ndani detyrat komplekse në nën-qëllime të menaxhueshme, duke e udhëhequr modelin përmes procesit.
    • Specifikoni formatin e daljes : Në kërkesën tuaj, kërkoni që rezultati të jetë në formatin që dëshironi, si markdown, JSON, HTML dhe më shumë.
    • Vendosni imazhin tuaj të parin për kërkesat me një imazh të vetëm : Ndërsa Gemini mund të trajtojë imazhet dhe tekstin në çdo renditje, për kërkesat që përmbajnë një imazh të vetëm, mund të funksionojë më mirë nëse ai imazh (ose video) vendoset para kërkesës me tekst. Megjithatë, për kërkesat që kërkojnë që imazhet të jenë shumë të ndërthurura me tekstet për të pasur kuptim, përdorni çfarëdo renditjeje që është më e natyrshme.
  • Zgjidhja e problemeve të kërkesës suaj multimodale

    • Nëse modeli nuk po tërheq informacion nga pjesa përkatëse e imazhit: Jepni sugjerime me anë të të cilave aspekte të imazhit dëshironi që kërkesa të nxjerrë informacion.
    • Nëse rezultati i modelit është shumë i përgjithshëm (nuk është përshtatur mjaftueshëm për hyrjen e imazhit/videos): Në fillim të kërkesës, provoni t'i kërkoni modelit të përshkruajë imazhin/imazhet ose videon përpara se të jepni udhëzimin e detyrës, ose provoni t'i kërkoni modelit të referohet asaj që është në imazh.
    • Për të zgjidhur problemin se cila pjesë dështoi: Kërkojini modelit të përshkruajë imazhin ose kërkojini modelit të shpjegojë arsyetimin e tij, për të vlerësuar kuptimin fillestar të modelit.
    • Nëse kërkesa juaj rezulton në përmbajtje halucinuese: Mundohuni ta ulni temperaturën ose t'i kërkoni modelit përshkrime më të shkurtra në mënyrë që të ketë më pak gjasa të ekstrapolohen detaje shtesë.
    • Rregullimi i parametrave të marrjes së mostrave: Eksperimentoni me cilësime të ndryshme të temperaturës dhe përzgjedhje top-k për të rregulluar kreativitetin e modelit.

Ji specifik në udhëzimet e tua

Kërkesat kanë më shumë sukses kur janë të qarta dhe të detajuara. Nëse keni në mendje një rezultat specifik, është më mirë ta përfshini atë kërkesë në kërkesë për t'u siguruar që të merrni rezultatin që dëshironi.

Për këtë imazh të një bordi aeroporti, t'i kërkosh modelit thjesht të "përshkruajë këtë imazh" mund të gjenerojë një përshkrim të përgjithshëm. Nëse ke nevojë që modeli të analizojë kohën dhe qytetin nga imazhi, mund ta përfshish atë kërkesë direkt në kërkesën tënde.

Nxitje Përgjigje modeli

Përshkruani këtë imazh.

Imazhi tregon një tabelë mbërritjesh dhe nisjesh në aeroport.

Kërkesa e përditësuar Përgjigje e përmirësuar
Orari i udhëtimit

Analizoni kohën dhe qytetin nga tabela e aeroportit e treguar në këtë imazh në një listë.

  • 10:50 Moskë
  • 11:05 Edinburg
  • 11:05 Londër
  • 11:10 Bukuresht
  • 11:30 Kiev
  • 11:35 Dublin
  • 11:45 Midlands Lindore
  • 12:15 Sofje
  • 12:30 Londër
  • 12:30 Njukasëll
  • 12:40 Shën Petersburg
  • 12:40 Londër
  • 12:45 Mançester
  • Shtoni disa shembuj

    Modeli Gemini mund të pranojë të dhëna të shumëfishta të cilat mund t’i përdorë si shembuj për të kuptuar rezultatin që dëshironi. Shtimi i këtyre shembujve mund ta ndihmojë modelin të identifikojë modelet dhe të zbatojë marrëdhënien midis imazheve të dhëna dhe përgjigjeve në shembullin e ri. Kjo quhet edhe të mësuarit "me pak goditje".

    Në shembullin më poshtë, rezultati fillestar është shkruar në formë fjalie dhe gjithashtu përmban vendin (Brazilin). Supozoni se dëshironi rezultatin në një format ose stil të ndryshëm dhe dëshironi vetëm qytetin, jo vendin. Shtimi i shembujve me pak shembuj në kërkesën tuaj mund ta orientojë modelin që të përgjigjet në mënyrën që dëshironi.

    Nxitje Përgjigje modeli
    Orari i udhëtimit

    Përcaktoni qytetin së bashku me pikën referuese.

    Pika referuese është statuja e Krishtit Shëlbues në Rio de Janeiro, Brazil.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    Përcaktoni qytetin së bashku me pikën referuese.

    koliseum

    qytet: Romë, pikë referimi: Koloseu.

    Qyteti i Ndaluar

    qytet: Pekin, pikë referimi: Qyteti i Ndaluar

    qytet i ndaluar

    qytet: Rio de Janeiro, pikë referimi: statuja e Krishtit Shëlbues

    Zbërthejeni hap pas hapi

    Për detyra komplekse si ato që kërkojnë si kuptim vizual ashtu edhe arsyetim, mund të jetë e dobishme ta ndani detyrën në hapa më të vegjël dhe më të drejtpërdrejtë. Nga ana tjetër, mund të jetë gjithashtu efektive nëse i kërkoni drejtpërdrejt modelit të "mendojë hap pas hapi" në kërkesën tuaj.

    Nxitje Përgjigje modeli

    Kur do të më mbarojë letra higjienike?

    Së shpejti, të kanë mbetur vetëm 3 rrotulla.

    Kërkesa e përditësuar Përgjigje e përmirësuar

      1. Së pari, numëroni sa rrotulla letre higjienike ka në këtë fotografi.
      2. Pastaj, përcaktoni se sa letër higjienike përdor një person tipik në ditë.
      3. Llogaritni se sa do të zgjasin këto rrotulla letre higjienike.

      1. Në këtë fotografi ka 3 rrotulla letre higjienike.
      2. Një person tipik përdor rreth 20 fletë letër higjienike në ditë.
      3. Nëse çdo rrotull përmban 200 fletë, atëherë çdo rrotull do të zgjasë për rreth 10 ditë. Prandaj, 3 rrotullat do të zgjasin për rreth një muaj.

    Problemet matematikore ose llojet e tjera të problemeve me fjalë janë kandidatë të shkëlqyer për t'i kërkuar modelit të mendojë hap pas hapi.

    Nxitje Përgjigje

    Cili është termi i 4-t në varg?

    -135

    Përgjigja nga modeli është e pasaktë. Disa mënyra për ta përmirësuar këtë janë t'i kërkoni modelit ta analizojë problemin përpara se t'i përgjigjet kërkesës.

    Nxitje Përgjigje

    Analizoni së pari formulën në imazh.

    Pastaj, bazuar në formulë, përgjigjuni pyetjes "cili është termi i 4-t në varg?".

    Kliko për të zgjeruar rezultatin

    $$ b(n) = b(n-1) * (-3) $$

    $$ b(1) = 15 $$

    1. Zëvendësoni n = 4 në formulë:
    2. $$ b(4) = b(4-1) * (-3) $$

      $$ b(4) = b(3) * (-3) $$

    3. Ne nuk e dimë vlerën e b(3), kështu që zëvendësojmë n = 3 në formulë:
    4. $$ b(3) = b(3-1) * (-3) $$

      $$ b(3) = b(2) * (-3) $$

    5. Ne nuk e dimë vlerën e b(2), kështu që zëvendësojmë n = 2 në formulë:
    6. $$ b(2) = b(2-1) * (-3) $$

      $$ b(2) = b(1) * (-3) $$

    7. Ne e dimë që vlera e b(1) është 15, prandaj zëvendësojeni atë në formulë:
    8. $$ b(2) = 15 * (-3) $$

      $$ b(2) = -45 $$

    9. Tani që e dimë vlerën e b(2), zëvendësojeni atë në formulën për b(3):
    10. $$ b(3) = b(2) * (-3) $$

      $$ b(3) = -45 * (-3) $$

      $$ b(3) = 135 $$

    11. Tani që e dimë vlerën e b(3), zëvendësojeni atë në formulën për b(4):
    12. $$ b(4) = b(3) * (-3) $$

      $$ b(4) = 135 * (-3) $$

      $$ b(4) = -405 $$

    Prandaj, termi i 4-t në sekuencë është -405.

    Kjo përgjigje e modelit është e saktë - tani, për ta bërë përgjigjen edhe më të efektshme, mund t'i kërkoni modelit të mendojë hap pas hapi.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    Cili është termi i 4-t në varg? Mendo hap pas hapi.

    Termi i parë është 15.

    Termi i dytë është b(1) * (-3) = 15 * (-3) = -45.

    Termi i tretë është b(2) * (-3) = -45 * (-3) = 135.

    Termi i katërt është b(3) * (-3) = 135 * (-3) = -405.

    Specifikoni formatin e daljes

    Një problem i zakonshëm është nevoja që rezultati i modelit të jetë në një format të caktuar (p.sh. markdown, JSON, HTML), veçanërisht nëse rezultati i modelit duhet të përthithet nga një detyrë rrjedhëse. Mund të provoni të prodhoni rezultate në atë format duke i dhënë udhëzime modelit ta bëjë këtë brenda njoftimit. Më poshtë janë dy shembuj:

    Nxitje Përgjigje modeli

    Analizoni tabelën në këtë imazh në formatin markdown

    | Subjekti | Statusi | Ora | Data e fillimit | Afati i fundit |

    | ------- | ------ | ---- | ---------- | ------- |

    | Matematikë | Përfunduar | 1.5 orë | 29/11/2023 | 1/12/2023 |

    | Gjeografi | Përfunduar | 30 min | 2/12/2023 | 4/12/2023 |

    | Fizikë | Në vazhdim | 2 orë | 3/12/2023 | 5/12/2023 |

    | Biologji | Nuk ka filluar | 6 orë | 11/2/2016 | 12/6/2023 |

    Nxitje Përgjigje modeli

    Jepni një listë të të gjitha atributeve të mëposhtme:

    përbërësit, lloji i kuzhinës, vegjetariane apo jo, në formatin JSON

    ``json

    {

    "përbërësit": [

    "oriz",

    "karkaleca deti",

    "midhje",

    "midhje",

    "bizele",

    "domate",

    "qepë",

    "hudhër",

    "vaj ulliri",

    "paprikë",

    "kripë",

    "piper"

    ],

    "lloj kuzhine": "Spanjisht",

    "vegjetarian": i rremë

    }

    ```

    Vendos imazhin tënd të parin për kërkesat me një imazh të vetëm

    Ndërsa Binjakët mund ta interpretojnë imazhin dhe tekstin në çdo renditje brenda një pyetjeje, vendosja e një imazhi të vetëm para pyetjes së tekstit mund të çojë në rezultate më të mira. Në shembujt e mëposhtëm, do të vini re se imazhi vjen i pari para tekstit në secilën pyetje.

    Zgjidhja e problemeve të kërkesës suaj multimodale

    Mund të duhet të zgjidhni problemin e kërkesës suaj nëse nuk po merrni një përgjigje të dobishme. Ja disa strategji që mund të provoni.

    Nëse modeli nuk po nxjerr informacion nga pjesa përkatëse e imazhit

    Për të marrë një përgjigje më specifike, mund të tregoni se nga cilat aspekte të imazhit dëshironi që kërkesa të nxjerrë informacion për të informuar përgjigjen e saj.

    Nxitje Përgjigje modeli

    Sa ditë do t’i zgjasin këto pelena një foshnje?

    Pelenat do të zgjasin 198 ditë para se të mbarojnë.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    Sa do të zgjasin këto pelena para se të më mbarojnë?

    Përdorni peshën e treguar në kuti për të përcaktuar moshën e fëmijës dhe përdorni numrin total të pelenave në kuti.

    Pjesëtoni numrin total me numrin e pelenave që përdor fëmija në ditë.

    Kutia përmban 198 pelena. Në kuti shkruhet se pelenat janë për një fëmijë që peshon 22-37 lbs.

    Fëmija mesatar në këtë diapazon peshe është ka të ngjarë të jetë midis 1 dhe 2 vjeç.

    Një fëmijë 2-vjeçar zakonisht ndërron 6 pelena në ditë, prandaj pelenat do të zgjasin rreth 33 ditë (198/6).

    Nëse rezultati i modelit është shumë i përgjithshëm dhe nuk është i përshtatur mjaftueshëm për hyrjen e imazhit

    Për ta ndihmuar modelin të përshtasë përgjigjen e tij ndaj imazhit/imazheve, provoni t'i kërkoni që t'i përshkruajë imazhet përpara se të kryejë detyrën e arsyetimit.

    Nxitje Përgjigje modeli

    Çfarë është e përbashkët midis këtyre imazheve?

    Të katër imazhet janë shembuj të fotografisë së peizazhit.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    Së pari, përshkruani në detaje se çfarë ka në secilën imazh. Çfarë kanë të përbashkët këto imazhe?

    Imazhi i parë tregon një person që po paketon një valixhe. Imazhi i dytë tregon një korridor bosh në një qendër tregtare. Imazhi i tretë tregon një rrotull letre higjienike. Imazhi i katërt tregon një det të errët dhe të stuhishëm.

    E përbashkëta midis këtyre imazheve është se të gjitha janë shembuj të hapësirave liminale. Hapësirat liminale janë vende ose situata që ndodhen midis dy vendeve ose situatave të tjera. Ato shpesh karakterizohen nga një ndjenjë pasigurie ose paqartësie.

    Imazhi i parë tregon personin midis të qenit në shtëpi dhe të qenit në një udhëtim. Imazhi i dytë tregon korridorin midis dy dyqaneve. Imazhi i tretë është letër higjienike, e cila mund të përfaqësojë një banjo. Një banjo është një hapësirë ​​kalimtare midis sferave private dhe publike. Është një vend ku ne përgatitemi për të hyrë ose për t'u larguar nga bota e jashtme.

    Imazhi i katërt tregon detin midis qetësisë dhe stuhive.

    Hapësirat liminale mund të jenë njëkohësisht emocionuese dhe shqetësuese. Ato mund të jenë një vend fillimi të ri ose një vend mbarimesh. Ato mund të jenë një vend reflektimi ose një vend veprimi.

    Gjithashtu mund të provoni t'i kërkoni modelit në mënyrë të qartë t'i referohet asaj që është në imazh.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    Çfarë kanë të përbashkët këto imazhe? Në përgjigjen tuaj, referojuni asaj që përmbahet në imazhe.

    Të gjitha imazhet lidhen me udhëtimet. Imazhi i parë tregon një person që po paketon një valixhe, imazhi i dytë tregon një korridor bosh në një qendër tregtare, imazhi i tretë tregon një pirg letre higjienike dhe imazhi i katërt tregon një det të errët dhe të stuhishëm.

    Këto imazhe lidhen të gjitha me udhëtimet sepse janë të gjitha gjëra që njerëzit kanë nevojë ose i përdorin kur udhëtojnë. Imazhi i parë tregon një person që po paketon një valixhe, diçka që njerëzit bëjnë kur shkojnë në një udhëtim. Imazhi i dytë tregon një korridor bosh në një qendër tregtare, i cili është një vend ku njerëzit shpesh shkojnë për të blerë gjëra për udhëtimet e tyre. Imazhi i tretë tregon një pirg letre higjienike, diçka që njerëzit shpesh e përdorin kur udhëtojnë. Imazhi i katërt tregon një det të errët dhe të stuhishëm, diçka që njerëzit e hasin shpesh kur udhëtojnë.

    Të njëjtat këshilla funksionojnë për rezultatet krijuese nga imazhet. Në shembullin e mëposhtëm me lepurin, kërkesa e qartë që modeli të përfshijë aspekte nga imazhi mund ta përmirësojë rezultatin.

    Nxitje Përgjigje modeli

    A mund të më shkruash një poezi për këtë imazh?

    Lepurush i vogël, kaq i butë dhe kafe,
    Duke kërcyer nëpër fushë, lart e poshtë.
    Veshët e tu kaq të gjatë, bishti yt kaq i vogël,
    Je krijesa më e lezetshme nga të gjitha.

    Ti kafshon barin, kaq të gjelbër dhe të ëmbël,
    Dhe largohu kur të më shohësh.
    Por unë gjithmonë do të jem shoku/shoqja jote,
    Lepurush i vogël, deri në fund.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    A mund të më shkruani një poezi përshkruese dhe dramatike rreth këtij imazhi dhe të përfshini vendndodhjen?

    Lepur i vogël në të gjelbër,
    Veshë kaq të gjatë, kaq të mprehtë.
    Çfarë sheh atje jashtë,
    Në distancë, ku shikon?

    A është bluja e oqeanit,
    Shkëlqen në ngjyrën e diellit?
    Apo valët që përplasen dhe gjëmojnë,
    Një ritëm që e adhuroni?

    Lepurush i vogël, më thuaj të vërtetën,
    Çfarë tërheq kaq shumë vëmendjen tuaj?
    A është flladi i kripur,
    Apo britmat e pulëbardhave që të pëlqejnë?

    Ndoshta është pafundësia e gjithçkaje,
    Një botë kaq e madhe dhe kaq e vogël.
    Një vend ku ëndrrat mund të enden,
    Dhe aventurat mund të mbillen.

    Lepurush i vogël, pyes veten se çfarë ëndërron,
    Ndërsa rri ulur në bar, kaq i qetë.
    A dëshiron të eksplorosh thellësitë,
    Apo të qëndrosh në tokë, ku mund të kërcesh?

    Çfarëdo që të jetë, lepurush i vogël,
    Mbaje të ndezur fort atë shkëndijë mrekullie.
    Sepse në ëndrrat dhe aspiratat tuaja,
    Shtrihet një botë që pret krijimin tënd.

    Zgjidhja e problemeve se cila pjesë e kërkesës dështoi

    Mund të jetë e vështirë të dish nëse një kërkesë dështoi sepse modeli nuk e kuptoi imazhin që në fillim, apo nëse e kuptoi imazhin, por nuk kreu hapat e saktë të arsyetimit më pas. Për të sqaruar midis këtyre arsyeve, kërkojini modelit të përshkruajë se çfarë ka në imazh.

    Në shembullin vijues, nëse modeli përgjigjet me një meze të lehtë që duket e habitshme kur shoqërohet me çaj (p.sh. kokoshka), së pari mund të zgjidhni problemin për të përcaktuar nëse modeli e ka njohur saktë që imazhi përmban çaj.

    Nxitje Kërkesë për zgjidhjen e problemeve

    Çfarë mezeje mund të bëj për 1 minutë që do të shkonte mirë me këtë?

    Përshkruani se çfarë është në këtë imazh.

    Një strategji tjetër është t’i kërkosh modelit të shpjegojë arsyetimin e tij. Kjo mund të të ndihmojë të kuptosh se cila pjesë e arsyetimit është e ndarë, nëse ka ndonjë.

    Nxitje Kërkesë për zgjidhjen e problemeve

    Çfarë mezeje mund të bëj për 1 minutë që do të shkonte mirë me këtë?

    Çfarë mezeje mund të përgatis për 1 minutë që do të shkonte mirë me këtë? Ju lutem shpjegoni pse.

    Çfarë vjen më pas

    • Provo të shkruash vetë kërkesat multimodale duke përdorur Google AI Studio .
    • Për informacion mbi përdorimin e Gemini Files API për ngarkimin e skedarëve media dhe përfshirjen e tyre në kërkesat tuaja, shihni udhëzuesit e përpunimit të Vizionit , Audios dhe Dokumentit .
    • Për më shumë udhëzime mbi dizajnin e shpejtë, si p.sh. rregullimi i parametrave të marrjes së mostrave, shihni faqen e Strategjive të shpejtë .
    ,

    Binjakët mund të trajtojnë lloje të ndryshme të të dhënave hyrëse, duke përfshirë tekstin, imazhet dhe audion, në të njëjtën kohë.

    Ky udhëzues ju tregon se si të punoni me skedarët media duke përdorur API-n e Skedarëve. Operacionet bazë janë të njëjta për skedarët audio, imazhet, videot, dokumentet dhe llojet e tjera të skedarëve të mbështetur.

    Për udhëzime rreth kërkesës për skedarë, shikoni seksionin Udhëzuesi i kërkesës për skedarë .

    Ngarko një skedar

    Mund të përdorni API-në e Skedarëve për të ngarkuar një skedar mediatik. Përdorni gjithmonë API-në e Skedarëve kur madhësia totale e kërkesës (duke përfshirë skedarët, njoftimin me tekst, udhëzimet e sistemit, etj.) është më e madhe se 100 MB. Për skedarët PDF, limiti është 50 MB.

    Kodi i mëposhtëm ngarkon një skedar dhe më pas e përdor skedarin në një thirrje për generateContent .

    Python

    from google import genai
    
    client = genai.Client()
    
    myfile = client.files.upload(file="path/to/sample.mp3")
    
    response = client.models.generate_content(
        model="gemini-3.8-flash", contents=["Describe this audio clip", myfile]
    )
    
    print(response.text)
    

    JavaScript

    import {
      GoogleGenAI,
      createUserContent,
      createPartFromUri,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const myfile = await ai.files.upload({
        file: "path/to/sample.mp3",
        config: { mimeType: "audio/mpeg" },
      });
    
      const response = await ai.models.generateContent({
        model: "gemini-3.8-flash",
        contents: createUserContent([
          createPartFromUri(myfile.uri, myfile.mimeType),
          "Describe this audio clip",
        ]),
      });
      console.log(response.text);
    }
    
    await main();
    

    Shko

    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Files.Delete(ctx, file.Name)
    
    resp, err := client.Models.GenerateContent(ctx, "gemini-3.8-flash", []*genai.Content{
      {
        Parts: []*genai.Part{
          genai.NewPartFromFile(*file),
          genai.NewPartFromText("Describe this audio clip"),
        },
      },
    }, nil)
    
    if err != nil {
        log.Fatal(err)
    }
    
    printResponse(resp)
    

    PUSHTIM

    AUDIO_PATH="path/to/sample.mp3"
    MIME_TYPE=$(file -b --mime-type "${AUDIO_PATH}")
    NUM_BYTES=$(wc -c < "${AUDIO_PATH}")
    DISPLAY_NAME=AUDIO
    
    tmp_header_file=upload-header.tmp
    
    # Initial resumable request defining metadata.
    # The upload url is in the response headers dump them to a file.
    curl "${BASE_URL}/upload/v1beta/files" \
      -H "x-goog-api-key: $GEMINI_API_KEY" \
      -D "${tmp_header_file}" \
      -H "X-Goog-Upload-Protocol: resumable" \
      -H "X-Goog-Upload-Command: start" \
      -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
      -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
      -H "Content-Type: application/json" \
      -d "{'file': {'display_name': '${DISPLAY_NAME}'}}" 2> /dev/null
    
    upload_url=$(grep -i "x-goog-upload-url: " "${tmp_header_file}" | cut -d" " -f2 | tr -d "\r")
    rm "${tmp_header_file}"
    
    # Upload the actual bytes.
    curl "${upload_url}" \
      -H "Content-Length: ${NUM_BYTES}" \
      -H "X-Goog-Upload-Offset: 0" \
      -H "X-Goog-Upload-Command: upload, finalize" \
      --data-binary "@${AUDIO_PATH}" 2> /dev/null > file_info.json
    
    file_uri=$(jq ".file.uri" file_info.json)
    echo file_uri=$file_uri
    
    # Now generate content using that file
    curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent" \
        -H "x-goog-api-key: $GEMINI_API_KEY" \
        -H 'Content-Type: application/json' \
        -X POST \
        -d '{
          "contents": [{
            "parts":[
              {"text": "Describe this audio clip"},
              {"file_data":{"mime_type": "${MIME_TYPE}", "file_uri": '$file_uri'}}]
            }]
          }' 2> /dev/null > response.json
    
    cat response.json
    echo
    
    jq ".candidates[].content.parts[].text" response.json
    

    Merrni metadata për një skedar

    Mund të verifikoni që API-ja e ka ruajtur me sukses skedarin e ngarkuar dhe të merrni meta të dhënat e tij duke thirrur files.get .

    Python

    from google import genai
    
    client = genai.Client()
    
    myfile = client.files.upload(file='path/to/sample.mp3')
    file_name = myfile.name
    myfile = client.files.get(name=file_name)
    print(myfile)
    

    JavaScript

    import {
      GoogleGenAI,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const myfile = await ai.files.upload({
        file: "path/to/sample.mp3",
        config: { mimeType: "audio/mpeg" },
      });
    
      const fileName = myfile.name;
      const fetchedFile = await ai.files.get({ name: fileName });
      console.log(fetchedFile);
    }
    
    await main();
    

    Shko

    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }
    
    gotFile, err := client.Files.Get(ctx, file.Name)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Got file:", gotFile.Name)
    

    PUSHTIM

    # file_info.json was created in the upload example
    name=$(jq ".file.name" file_info.json)
    # Get the file of interest to check state
    curl https://generativelanguage.googleapis.com/v1beta/files/$name \
    -H "x-goog-api-key: $GEMINI_API_KEY" > file_info.json
    # Print some information about the file you got
    name=$(jq ".file.name" file_info.json)
    echo name=$name
    file_uri=$(jq ".file.uri" file_info.json)
    echo file_uri=$file_uri
    

    Listo skedarët e ngarkuar

    Kodi i mëposhtëm merr një listë të të gjithë skedarëve të ngarkuar:

    Python

    from google import genai
    
    client = genai.Client()
    
    print('My files:')
    for f in client.files.list():
        print(' ', f.name)
    

    JavaScript

    import {
      GoogleGenAI,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const listResponse = await ai.files.list({ config: { pageSize: 10 } });
      for await (const file of listResponse) {
        console.log(file.name);
      }
    }
    
    await main();
    

    Shko

    for file, err := range client.Files.All(ctx) {
      if err != nil {
        log.Fatal(err)
      }
      fmt.Println(file.Name)
    }
    

    PUSHTIM

    echo "My files: "
    
    curl "https://generativelanguage.googleapis.com/v1beta/files" \
      -H "x-goog-api-key: $GEMINI_API_KEY"
    

    Fshi skedarët e ngarkuar

    Skedarët fshihen automatikisht pas 48 orësh. Gjithashtu mund ta fshini manualisht një skedar të ngarkuar:

    Python

    from google import genai
    
    client = genai.Client()
    
    myfile = client.files.upload(file='path/to/sample.mp3')
    client.files.delete(name=myfile.name)
    

    JavaScript

    import {
      GoogleGenAI,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const myfile = await ai.files.upload({
        file: "path/to/sample.mp3",
        config: { mimeType: "audio/mpeg" },
      });
    
      const fileName = myfile.name;
      await ai.files.delete({ name: fileName });
    }
    
    await main();
    

    Shko

    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }
    client.Files.Delete(ctx, file.Name)
    

    PUSHTIM

    curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/files/$name \
      -H "x-goog-api-key: $GEMINI_API_KEY"
    

    Informacion përdorimi

    Mund të përdorni API-n e Skedarëve për të ngarkuar dhe bashkëvepruar me skedarët mediatikë. API-ja e Skedarëve ju lejon të ruani deri në 20 GB skedarë për projekt, me një madhësi maksimale për skedar prej 2 GB. Skedarët ruhen për 48 orë.

    Gjatë asaj kohe, mund ta përdorni API-në për të marrë meta të dhëna rreth skedarëve. Megjithatë, nuk mund të shkarkoni skedarë të ngarkuar nga përdoruesit. Mund të shkarkoni skedarë të gjeneruar nga modelet, siç janë videot, duke përdorur metodën files.download . API-ja e skedarëve është e disponueshme pa pagesë në të gjitha rajonet ku është e disponueshme API-ja Gemini.

    Strategjitë e nxitjes së skedarëve

    Ky seksion ofron udhëzime dhe praktikat më të mira për përdorimin e skedarëve media me kërkesa për Gemini API.

    Mundësia për të përdorur lloje të ndryshme të të dhënave në kërkesat tuaja ju jep më shumë fleksibilitet në lidhje me detyrat që mund të trajtoni me Gemini API. Për shembull, mund t'i dërgoni modelit një foto të një vakti të shijshëm dhe t'i kërkoni të shkruajë një blog të shkurtër rreth tij.

    Nxitje Përgjigje

    Shkruaj një postim të shkurtër dhe tërheqës në blog bazuar në këtë fotografi. Duhet të përfshijë një përshkrim të vaktit në foto dhe të flasë për udhëtimin tim të përgatitjes së vakteve.


    Kukitë

    Përgatitja e vakteve është një mënyrë e shkëlqyer për të kursyer kohë dhe para, dhe gjithashtu mund t'ju ndihmojë të hani më shëndetshëm. Ky vakt është një shembull i shkëlqyer i një vakti të shëndetshëm dhe të shijshëm që mund të përgatitet lehtësisht paraprakisht.

    Ky vakt përmban oriz të kaftë, perime të pjekura në furrë dhe pulë teriyaki. Orizi i kaftë është një karbohidrat i shëndetshëm dhe kompleks që do t'ju japë energji të qëndrueshme. Perimet e pjekura janë një mënyrë e shkëlqyer për të marrë dozën tuaj të përditshme të vitaminave dhe mineraleve, dhe pula teriyaki është një opsion i shijshëm dhe i pasur me proteina.

    Ky vakt është gjithashtu shumë i lehtë për t’u përgatitur. Thjesht gatuani orizin e kaftë, piqni perimet dhe gatuani pulën teriyaki. Pasi të jetë gatuar gjithçka, ndajeni në enë përgatitore dhe vendosini në frigorifer. Pastaj mund të merrni një enë dhe të shkoni në mëngjeset e ngarkuara!

    Nëse jeni duke kërkuar një vakt të shëndetshëm dhe të shijshëm që mund të përgatitet lehtësisht paraprakisht, ky vakt është një zgjedhje e shkëlqyer. Është i mbushur me lëndë ushqyese dhe shije, dhe me siguri do t'ju mbajë të ngopur dhe të kënaqur.

    Ja ku është përgatitja e vakteve të shëndetshme dhe të shijshme!

    Nëse keni probleme me marrjen e rezultatit që dëshironi nga kërkesat që përdorin skedarë mediatikë, ekzistojnë disa strategji që mund t'ju ndihmojnë të merrni rezultatet që dëshironi. Seksionet e mëposhtme ofrojnë qasje në dizajn dhe këshilla për zgjidhjen e problemeve për përmirësimin e kërkesave që përdorin hyrje multimodale.

    Ju mund t'i përmirësoni kërkesat tuaja multimodale duke ndjekur këto praktika më të mira:

    • Bazat e dizajnit të shpejtë

      • Ji specifik në udhëzimet e tua : Harto udhëzime të qarta dhe koncize që lënë hapësirë ​​minimale për keqinterpretime.
      • Shtoni disa shembuj në kërkesën tuaj: Përdorni shembuj realistë me pak shembuj për të ilustruar atë që dëshironi të arrini.
      • Ndani atë hap pas hapi : Ndani detyrat komplekse në nën-qëllime të menaxhueshme, duke e udhëhequr modelin përmes procesit.
      • Specifikoni formatin e daljes : Në kërkesën tuaj, kërkoni që rezultati të jetë në formatin që dëshironi, si markdown, JSON, HTML dhe më shumë.
      • Vendosni imazhin tuaj të parin për kërkesat me një imazh të vetëm : Ndërsa Gemini mund të trajtojë imazhet dhe tekstin në çdo renditje, për kërkesat që përmbajnë një imazh të vetëm, mund të funksionojë më mirë nëse ai imazh (ose video) vendoset para kërkesës me tekst. Megjithatë, për kërkesat që kërkojnë që imazhet të jenë shumë të ndërthurura me tekstet për të pasur kuptim, përdorni çfarëdo renditjeje që është më e natyrshme.
    • Zgjidhja e problemeve të kërkesës suaj multimodale

      • Nëse modeli nuk po tërheq informacion nga pjesa përkatëse e imazhit: Jepni sugjerime me anë të të cilave aspekte të imazhit dëshironi që kërkesa të nxjerrë informacion.
      • Nëse rezultati i modelit është shumë i përgjithshëm (nuk është përshtatur mjaftueshëm për hyrjen e imazhit/videos): Në fillim të kërkesës, provoni t'i kërkoni modelit të përshkruajë imazhin/imazhet ose videon përpara se të jepni udhëzimin e detyrës, ose provoni t'i kërkoni modelit të referohet asaj që është në imazh.
      • Për të zgjidhur problemin se cila pjesë dështoi: Kërkojini modelit të përshkruajë imazhin ose kërkojini modelit të shpjegojë arsyetimin e tij, për të vlerësuar kuptimin fillestar të modelit.
      • Nëse kërkesa juaj rezulton në përmbajtje halucinuese: Mundohuni ta ulni temperaturën ose t'i kërkoni modelit përshkrime më të shkurtra në mënyrë që të ketë më pak gjasa të ekstrapolohen detaje shtesë.
      • Rregullimi i parametrave të marrjes së mostrave: Eksperimentoni me cilësime të ndryshme të temperaturës dhe përzgjedhje top-k për të rregulluar kreativitetin e modelit.

    Ji specifik në udhëzimet e tua

    Kërkesat kanë më shumë sukses kur janë të qarta dhe të detajuara. Nëse keni në mendje një rezultat specifik, është më mirë ta përfshini atë kërkesë në kërkesë për t'u siguruar që të merrni rezultatin që dëshironi.

    Për këtë imazh të një bordi aeroporti, t'i kërkosh modelit thjesht të "përshkruajë këtë imazh" mund të gjenerojë një përshkrim të përgjithshëm. Nëse ke nevojë që modeli të analizojë kohën dhe qytetin nga imazhi, mund ta përfshish atë kërkesë direkt në kërkesën tënde.

    Nxitje Përgjigje modeli

    Përshkruani këtë imazh.

    Imazhi tregon një tabelë mbërritjesh dhe nisjesh në aeroport.

    Kërkesa e përditësuar Përgjigje e përmirësuar
    Orari i udhëtimit

    Analizoni kohën dhe qytetin nga tabela e aeroportit e treguar në këtë imazh në një listë.

  • 10:50 Moskë
  • 11:05 Edinburg
  • 11:05 Londër
  • 11:10 Bukuresht
  • 11:30 Kiev
  • 11:35 Dublin
  • 11:45 Midlands Lindore
  • 12:15 Sofje
  • 12:30 Londër
  • 12:30 Njukasëll
  • 12:40 Shën Petersburg
  • 12:40 Londër
  • 12:45 Mançester
  • Shtoni disa shembuj

    Modeli Gemini mund të pranojë të dhëna të shumëfishta të cilat mund t’i përdorë si shembuj për të kuptuar rezultatin që dëshironi. Shtimi i këtyre shembujve mund ta ndihmojë modelin të identifikojë modelet dhe të zbatojë marrëdhënien midis imazheve të dhëna dhe përgjigjeve në shembullin e ri. Kjo quhet edhe të mësuarit "me pak goditje".

    Në shembullin më poshtë, rezultati fillestar është shkruar në formë fjalie dhe gjithashtu përmban vendin (Brazilin). Supozoni se dëshironi rezultatin në një format ose stil të ndryshëm dhe dëshironi vetëm qytetin, jo vendin. Shtimi i shembujve me pak shembuj në kërkesën tuaj mund ta orientojë modelin që të përgjigjet në mënyrën që dëshironi.

    Nxitje Përgjigje modeli
    Orari i udhëtimit

    Përcaktoni qytetin së bashku me pikën referuese.

    Pika referuese është statuja e Krishtit Shëlbues në Rio de Janeiro, Brazil.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    Përcaktoni qytetin së bashku me pikën referuese.

    koliseum

    qytet: Romë, pikë referimi: Koloseu.

    Qyteti i Ndaluar

    qytet: Pekin, pikë referimi: Qyteti i Ndaluar

    qytet i ndaluar

    qytet: Rio de Janeiro, pikë referimi: statuja e Krishtit Shëlbues

    Zbërthejeni hap pas hapi

    Për detyra komplekse si ato që kërkojnë si kuptim vizual ashtu edhe arsyetim, mund të jetë e dobishme ta ndani detyrën në hapa më të vegjël dhe më të drejtpërdrejtë. Nga ana tjetër, mund të jetë gjithashtu efektive nëse i kërkoni drejtpërdrejt modelit të "mendojë hap pas hapi" në kërkesën tuaj.

    Nxitje Përgjigje modeli

    Kur do të më mbarojë letra higjienike?

    Së shpejti, të kanë mbetur vetëm 3 rrotulla.

    Kërkesa e përditësuar Përgjigje e përmirësuar

      1. Së pari, numëroni sa rrotulla letre higjienike ka në këtë fotografi.
      2. Pastaj, përcaktoni se sa letër higjienike përdor një person tipik në ditë.
      3. Llogaritni se sa do të zgjasin këto rrotulla letre higjienike.

      1. Në këtë fotografi ka 3 rrotulla letre higjienike.
      2. Një person tipik përdor rreth 20 fletë letër higjienike në ditë.
      3. Nëse çdo rrotull përmban 200 fletë, atëherë çdo rrotull do të zgjasë për rreth 10 ditë. Prandaj, 3 rrotullat do të zgjasin për rreth një muaj.

    Problemet matematikore ose llojet e tjera të problemeve me fjalë janë kandidatë të shkëlqyer për t'i kërkuar modelit të mendojë hap pas hapi.

    Nxitje Përgjigje

    Cili është termi i 4-t në varg?

    -135

    Përgjigja nga modeli është e pasaktë. Disa mënyra për ta përmirësuar këtë janë t'i kërkoni modelit ta analizojë problemin përpara se t'i përgjigjet kërkesës.

    Nxitje Përgjigje

    Analizoni së pari formulën në imazh.

    Pastaj, bazuar në formulë, përgjigjuni pyetjes "cili është termi i 4-t në varg?".

    Kliko për të zgjeruar rezultatin

    $$ b(n) = b(n-1) * (-3) $$

    $$ b(1) = 15 $$

    1. Zëvendësoni n = 4 në formulë:
    2. $$ b(4) = b(4-1) * (-3) $$

      $$ b(4) = b(3) * (-3) $$

    3. Ne nuk e dimë vlerën e b(3), kështu që zëvendësojmë n = 3 në formulë:
    4. $$ b(3) = b(3-1) * (-3) $$

      $$ b(3) = b(2) * (-3) $$

    5. Ne nuk e dimë vlerën e b(2), kështu që zëvendësojmë n = 2 në formulë:
    6. $$ b(2) = b(2-1) * (-3) $$

      $$ b(2) = b(1) * (-3) $$

    7. Ne e dimë që vlera e b(1) është 15, prandaj zëvendësojeni atë në formulë:
    8. $$ b(2) = 15 * (-3) $$

      $$ b(2) = -45 $$

    9. Tani që e dimë vlerën e b(2), zëvendësojeni atë në formulën për b(3):
    10. $$ b(3) = b(2) * (-3) $$

      $$ b(3) = -45 * (-3) $$

      $$ b(3) = 135 $$

    11. Tani që e dimë vlerën e b(3), zëvendësojeni atë në formulën për b(4):
    12. $$ b(4) = b(3) * (-3) $$

      $$ b(4) = 135 * (-3) $$

      $$ b(4) = -405 $$

    Prandaj, termi i 4-t në sekuencë është -405.

    Kjo përgjigje e modelit është e saktë - tani, për ta bërë përgjigjen edhe më të efektshme, mund t'i kërkoni modelit të mendojë hap pas hapi.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    Cili është termi i 4-t në varg? Mendo hap pas hapi.

    Termi i parë është 15.

    Termi i dytë është b(1) * (-3) = 15 * (-3) = -45.

    Termi i tretë është b(2) * (-3) = -45 * (-3) = 135.

    Termi i katërt është b(3) * (-3) = 135 * (-3) = -405.

    Specifikoni formatin e daljes

    Një problem i zakonshëm është nevoja që rezultati i modelit të jetë në një format të caktuar (p.sh. markdown, JSON, HTML), veçanërisht nëse rezultati i modelit duhet të përthithet nga një detyrë rrjedhëse. Mund të provoni të prodhoni rezultate në atë format duke i dhënë udhëzime modelit ta bëjë këtë brenda njoftimit. Më poshtë janë dy shembuj:

    Nxitje Përgjigje modeli

    Analizoni tabelën në këtë imazh në formatin markdown

    | Subjekti | Statusi | Ora | Data e fillimit | Afati i fundit |

    | ------- | ------ | ---- | ---------- | ------- |

    | Matematikë | Përfunduar | 1.5 orë | 29/11/2023 | 1/12/2023 |

    | Gjeografi | Përfunduar | 30 min | 2/12/2023 | 4/12/2023 |

    | Fizikë | Në vazhdim | 2 orë | 3/12/2023 | 5/12/2023 |

    | Biologji | Nuk ka filluar | 6 orë | 11/2/2016 | 12/6/2023 |

    Nxitje Përgjigje modeli

    Jepni një listë të të gjitha atributeve të mëposhtme:

    përbërësit, lloji i kuzhinës, vegjetariane apo jo, në formatin JSON

    ``json

    {

    "përbërësit": [

    "oriz",

    "karkaleca deti",

    "midhje",

    "midhje",

    "bizele",

    "domate",

    "qepë",

    "hudhër",

    "vaj ulliri",

    "paprikë",

    "kripë",

    "piper"

    ],

    "lloj kuzhine": "Spanjisht",

    "vegjetarian": i rremë

    }

    ```

    Vendos imazhin tënd të parin për kërkesat me një imazh të vetëm

    Ndërsa Binjakët mund ta interpretojnë imazhin dhe tekstin në çdo renditje brenda një pyetjeje, vendosja e një imazhi të vetëm para pyetjes së tekstit mund të çojë në rezultate më të mira. Në shembujt e mëposhtëm, do të vini re se imazhi vjen i pari para tekstit në secilën pyetje.

    Zgjidhja e problemeve të kërkesës suaj multimodale

    Mund të duhet të zgjidhni problemin e kërkesës suaj nëse nuk po merrni një përgjigje të dobishme. Ja disa strategji që mund të provoni.

    Nëse modeli nuk po nxjerr informacion nga pjesa përkatëse e imazhit

    Për të marrë një përgjigje më specifike, mund të tregoni se nga cilat aspekte të imazhit dëshironi që kërkesa të nxjerrë informacion për të informuar përgjigjen e saj.

    Nxitje Përgjigje modeli

    Sa ditë do t’i zgjasin këto pelena një foshnje?

    Pelenat do të zgjasin 198 ditë para se të mbarojnë.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    Sa do të zgjasin këto pelena para se të më mbarojnë?

    Përdorni peshën e treguar në kuti për të përcaktuar moshën e fëmijës dhe përdorni numrin total të pelenave në kuti.

    Pjesëtoni numrin total me numrin e pelenave që përdor fëmija në ditë.

    Kutia përmban 198 pelena. Në kuti shkruhet se pelenat janë për një fëmijë që peshon 22-37 lbs.

    Fëmija mesatar në këtë diapazon peshe është ka të ngjarë të jetë midis 1 dhe 2 vjeç.

    Një fëmijë 2-vjeçar zakonisht ndërron 6 pelena në ditë, prandaj pelenat do të zgjasin rreth 33 ditë (198/6).

    Nëse rezultati i modelit është shumë i përgjithshëm dhe nuk është i përshtatur mjaftueshëm për hyrjen e imazhit

    Për ta ndihmuar modelin të përshtasë përgjigjen e tij ndaj imazhit/imazheve, provoni t'i kërkoni që t'i përshkruajë imazhet përpara se të kryejë detyrën e arsyetimit.

    Nxitje Përgjigje modeli

    Çfarë është e përbashkët midis këtyre imazheve?

    Të katër imazhet janë shembuj të fotografisë së peizazhit.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    Së pari, përshkruani në detaje se çfarë ka në secilën imazh. Çfarë kanë të përbashkët këto imazhe?

    Imazhi i parë tregon një person që po paketon një valixhe. Imazhi i dytë tregon një korridor bosh në një qendër tregtare. Imazhi i tretë tregon një rrotull letre higjienike. Imazhi i katërt tregon një det të errët dhe të stuhishëm.

    E përbashkëta midis këtyre imazheve është se të gjitha janë shembuj të hapësirave liminale. Hapësirat liminale janë vende ose situata që ndodhen midis dy vendeve ose situatave të tjera. Ato shpesh karakterizohen nga një ndjenjë pasigurie ose paqartësie.

    Imazhi i parë tregon personin midis të qenit në shtëpi dhe të qenit në një udhëtim. Imazhi i dytë tregon korridorin midis dy dyqaneve. Imazhi i tretë është letër higjienike, e cila mund të përfaqësojë një banjo. Një banjo është një hapësirë ​​kalimtare midis sferave private dhe publike. Është një vend ku ne përgatitemi për të hyrë ose për t'u larguar nga bota e jashtme.

    Imazhi i katërt tregon detin midis qetësisë dhe stuhive.

    Hapësirat liminale mund të jenë njëkohësisht emocionuese dhe shqetësuese. Ato mund të jenë një vend fillimi të ri ose një vend mbarimesh. Ato mund të jenë një vend reflektimi ose një vend veprimi.

    Gjithashtu mund të provoni t'i kërkoni modelit në mënyrë të qartë t'i referohet asaj që është në imazh.

    Kërkesa e përditësuar Përgjigje e përmirësuar

    Çfarë kanë të përbashkët këto imazhe? Në përgjigjen tuaj, referojuni asaj që përmbahet në imazhe.

    Të gjitha imazhet lidhen me udhëtimet. Imazhi i parë tregon një person që po paketon një valixhe, imazhi i dytë tregon një korridor bosh në një qendër tregtare, imazhi i tretë tregon një pirg letre higjienike dhe imazhi i katërt tregon një det të errët dhe të stuhishëm.

    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.

    The same tips work for creative output from images. In the following example with the rabbit, explicitly asking the model to include aspects from the image can improve the output.

    Prompt Model response

    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.

    Updated prompt Improved response

    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.

    Troubleshooting which part of the prompt failed

    It can be hard to know whether a prompt failed because the model didn't understand the image to begin with, or if it did understand the image but did not perform the correct reasoning steps afterward. To disambiguate between those reasons, ask the model to describe what's in the image.

    In the following example, if the model responds with a snack that seems surprising when paired with tea (eg popcorn), you can first troubleshoot to determine whether the model correctly recognized that the image contains tea.

    Prompt Prompt for troubleshooting

    What's a snack I can make in 1 minute that would go well with this?

    Describe what's in this image.

    Another strategy is to ask the model to explain its reasoning. That can help you narrow down which part of the reasoning broke down, if any.

    Prompt Prompt for troubleshooting

    What's a snack I can make in 1 minute that would go well with this?

    What's a snack I can make in 1 minute that would go well with this? Please explain why.

    Çfarë vjen më pas

    • Provo të shkruash vetë kërkesat multimodale duke përdorur Google AI Studio .
    • For information on using the Gemini Files API for uploading media files and including them in your prompts, see the Vision , Audio , and Document processing guides.
    • For more guidance on prompt design, like tuning sampling parameters, see the Prompt strategies page.
    ,

    Gemini can handle various types of input data, including text, images, and audio, at the same time.

    This guide shows you how to work with media files using the Files API. The basic operations are the same for audio files, images, videos, documents, and other supported file types.

    For file prompting guidance, check out the File prompt guide section.

    Upload a file

    You can use the Files API to upload a media file. Always use the Files API when the total request size (including the files, text prompt, system instructions, etc.) is larger than 100 MB. For PDF files, the limit is 50 MB.

    The following code uploads a file and then uses the file in a call to generateContent .

    Python

    from google import genai
    
    client = genai.Client()
    
    myfile = client.files.upload(file="path/to/sample.mp3")
    
    response = client.models.generate_content(
        model="gemini-3.8-flash", contents=["Describe this audio clip", myfile]
    )
    
    print(response.text)
    

    JavaScript

    import {
      GoogleGenAI,
      createUserContent,
      createPartFromUri,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const myfile = await ai.files.upload({
        file: "path/to/sample.mp3",
        config: { mimeType: "audio/mpeg" },
      });
    
      const response = await ai.models.generateContent({
        model: "gemini-3.8-flash",
        contents: createUserContent([
          createPartFromUri(myfile.uri, myfile.mimeType),
          "Describe this audio clip",
        ]),
      });
      console.log(response.text);
    }
    
    await main();
    

    Shko

    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Files.Delete(ctx, file.Name)
    
    resp, err := client.Models.GenerateContent(ctx, "gemini-3.8-flash", []*genai.Content{
      {
        Parts: []*genai.Part{
          genai.NewPartFromFile(*file),
          genai.NewPartFromText("Describe this audio clip"),
        },
      },
    }, nil)
    
    if err != nil {
        log.Fatal(err)
    }
    
    printResponse(resp)
    

    PUSHTIM

    AUDIO_PATH="path/to/sample.mp3"
    MIME_TYPE=$(file -b --mime-type "${AUDIO_PATH}")
    NUM_BYTES=$(wc -c < "${AUDIO_PATH}")
    DISPLAY_NAME=AUDIO
    
    tmp_header_file=upload-header.tmp
    
    # Initial resumable request defining metadata.
    # The upload url is in the response headers dump them to a file.
    curl "${BASE_URL}/upload/v1beta/files" \
      -H "x-goog-api-key: $GEMINI_API_KEY" \
      -D "${tmp_header_file}" \
      -H "X-Goog-Upload-Protocol: resumable" \
      -H "X-Goog-Upload-Command: start" \
      -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
      -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
      -H "Content-Type: application/json" \
      -d "{'file': {'display_name': '${DISPLAY_NAME}'}}" 2> /dev/null
    
    upload_url=$(grep -i "x-goog-upload-url: " "${tmp_header_file}" | cut -d" " -f2 | tr -d "\r")
    rm "${tmp_header_file}"
    
    # Upload the actual bytes.
    curl "${upload_url}" \
      -H "Content-Length: ${NUM_BYTES}" \
      -H "X-Goog-Upload-Offset: 0" \
      -H "X-Goog-Upload-Command: upload, finalize" \
      --data-binary "@${AUDIO_PATH}" 2> /dev/null > file_info.json
    
    file_uri=$(jq ".file.uri" file_info.json)
    echo file_uri=$file_uri
    
    # Now generate content using that file
    curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent" \
        -H "x-goog-api-key: $GEMINI_API_KEY" \
        -H 'Content-Type: application/json' \
        -X POST \
        -d '{
          "contents": [{
            "parts":[
              {"text": "Describe this audio clip"},
              {"file_data":{"mime_type": "${MIME_TYPE}", "file_uri": '$file_uri'}}]
            }]
          }' 2> /dev/null > response.json
    
    cat response.json
    echo
    
    jq ".candidates[].content.parts[].text" response.json
    

    Get metadata for a file

    You can verify that the API successfully stored the uploaded file and get its metadata by calling files.get .

    Python

    from google import genai
    
    client = genai.Client()
    
    myfile = client.files.upload(file='path/to/sample.mp3')
    file_name = myfile.name
    myfile = client.files.get(name=file_name)
    print(myfile)
    

    JavaScript

    import {
      GoogleGenAI,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const myfile = await ai.files.upload({
        file: "path/to/sample.mp3",
        config: { mimeType: "audio/mpeg" },
      });
    
      const fileName = myfile.name;
      const fetchedFile = await ai.files.get({ name: fileName });
      console.log(fetchedFile);
    }
    
    await main();
    

    Shko

    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }
    
    gotFile, err := client.Files.Get(ctx, file.Name)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Got file:", gotFile.Name)
    

    PUSHTIM

    # file_info.json was created in the upload example
    name=$(jq ".file.name" file_info.json)
    # Get the file of interest to check state
    curl https://generativelanguage.googleapis.com/v1beta/files/$name \
    -H "x-goog-api-key: $GEMINI_API_KEY" > file_info.json
    # Print some information about the file you got
    name=$(jq ".file.name" file_info.json)
    echo name=$name
    file_uri=$(jq ".file.uri" file_info.json)
    echo file_uri=$file_uri
    

    List uploaded files

    The following code gets a list of all the files uploaded:

    Python

    from google import genai
    
    client = genai.Client()
    
    print('My files:')
    for f in client.files.list():
        print(' ', f.name)
    

    JavaScript

    import {
      GoogleGenAI,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const listResponse = await ai.files.list({ config: { pageSize: 10 } });
      for await (const file of listResponse) {
        console.log(file.name);
      }
    }
    
    await main();
    

    Shko

    for file, err := range client.Files.All(ctx) {
      if err != nil {
        log.Fatal(err)
      }
      fmt.Println(file.Name)
    }
    

    PUSHTIM

    echo "My files: "
    
    curl "https://generativelanguage.googleapis.com/v1beta/files" \
      -H "x-goog-api-key: $GEMINI_API_KEY"
    

    Delete uploaded files

    Files are automatically deleted after 48 hours. You can also manually delete an uploaded file:

    Python

    from google import genai
    
    client = genai.Client()
    
    myfile = client.files.upload(file='path/to/sample.mp3')
    client.files.delete(name=myfile.name)
    

    JavaScript

    import {
      GoogleGenAI,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const myfile = await ai.files.upload({
        file: "path/to/sample.mp3",
        config: { mimeType: "audio/mpeg" },
      });
    
      const fileName = myfile.name;
      await ai.files.delete({ name: fileName });
    }
    
    await main();
    

    Shko

    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }
    client.Files.Delete(ctx, file.Name)
    

    PUSHTIM

    curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/files/$name \
      -H "x-goog-api-key: $GEMINI_API_KEY"
    

    Usage information

    You can use the Files API to upload and interact with media files. The Files API lets you store up to 20 GB of files per project, with a per-file maximum size of 2 GB. Files are stored for 48 hours.

    During that time, you can use the API to get metadata about the files. However, you can't download user-uploaded files. You can download files generated by models, such as videos, using the files.download method. The Files API is available at no cost in all regions where the Gemini API is available.

    File prompting strategies

    This section provides guidance and best practices for using media files with prompts for the Gemini API.

    Being able to use various types of data in your prompts gives you more flexibility in terms of what tasks you can tackle with the Gemini API. For example, you can send the model a photo of a delicious meal and ask it to write a short blog about the meal.

    Prompt Përgjigje

    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.


    Kukitë

    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 easily 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 very easy 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 easily 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!

    If you are having trouble getting the output you want from prompts that use media files, there are some strategies that can help you get the results you want. The following sections provide design approaches and troubleshooting tips for improving prompts that use multimodal input.

    You can improve your multimodal prompts by following these best practices:

    • Prompt design fundamentals

      • Be specific in your instructions : Craft clear and concise instructions that leave minimal room for misinterpretation.
      • Add a few examples to your prompt: Use realistic few-shot examples to illustrate what you want to achieve.
      • Break it down step-by-step : Divide complex tasks into manageable sub-goals, guiding the model through the process.
      • Specify the output format : In your prompt, ask for the output to be in the format you want, like markdown, JSON, HTML and more.
      • 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.
    • Troubleshooting your multimodal prompt

      • 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.
      • 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.
      • 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.
      • 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.
      • Tuning the sampling parameters: Experiment with different temperature settings and top-k selections to adjust the model's creativity.

    Be specific in your instructions

    Prompts have the most success when they are clear and detailed. If you have a specific output in mind, it's better to include that requirement in the prompt to ensure you get the output you want.

    For this image of an airport board, asking the model to just "describe this image" could generate a general description. If you need the model to parse the time and city from the image, you can include that request directly in your prompt.

    Prompt Model response

    Describe this image.

    The image shows an airport arrivals and departures board.

    Updated prompt Improved response
    Travel timetable

    Parse the time and city from the airport board shown in this image into a list.

  • 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
  • Add a few examples

    The Gemini model can accept multiple inputs which it can use as examples to understand the output you want. Adding these examples can help the model identify the patterns and apply the relationship between the given images and responses to the new example. This is also called "few-shot" learning.

    In the example below, the initial output is written in sentence form, and also contains the country (Brazil). Suppose you want the output in a different format or style, and you want only the city, not the country. Adding few-shot examples to your prompt can steer the model to respond in the way you want.

    Prompt Model response
    Travel timetable

    Determine the city along with the landmark.

    The landmark is the Christ the Redeemer statue in Rio de Janeiro, Brazil.

    Updated prompt Improved response

    Determine the city along with the landmark.

    colosseum

    city: Rome, landmark: the Colosseum.

    Forbidden City

    city: Beijing, landmark: Forbidden City

    forbidden-city

    city: Rio de Janeiro, landmark: Christ the Redeemer statue

    Break it down step-by-step

    For complex tasks like the ones that require both visual understanding and reasoning, it can be helpful to split the task into smaller, more straightforward steps. Alternatively, it could also be effective if you directly ask the model to “think step by step” in your prompt.

    Prompt Model response

    When will I run out of toilet paper?

    Soon, you only have 3 rolls left.

    Updated prompt Improved response

      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.

    Math problems or other types of word problems are great candidates for asking the model to think step-by-step.

    Prompt Përgjigje

    What is the 4th term in the sequence?

    -135

    The response from the model is incorrect. Some ways to improve this is to ask the model to parse the problem before answering the prompt.

    Prompt Përgjigje

    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:
    2. $$ b(4) = b(4-1) * (-3) $$

      $$ b(4) = b(3) * (-3) $$

    3. We don't know the value of b(3), so substitute n = 3 into the formula:
    4. $$ b(3) = b(3-1) * (-3) $$

      $$ b(3) = b(2) * (-3) $$

    5. We don't know the value of b(2), so substitute n = 2 into the formula:
    6. $$ b(2) = b(2-1) * (-3) $$

      $$ b(2) = b(1) * (-3) $$

    7. We know the value of b(1) is 15, so substitute it into the formula:
    8. $$ b(2) = 15 * (-3) $$

      $$ b(2) = -45 $$

    9. Now that we know the value of b(2), substitute it into the formula for b(3):
    10. $$ b(3) = b(2) * (-3) $$

      $$ b(3) = -45 * (-3) $$

      $$ b(3) = 135 $$

    11. Now that we know the value of b(3), substitute it into the formula for b(4):
    12. $$ b(4) = b(3) * (-3) $$

      $$ b(4) = 135 * (-3) $$

      $$ b(4) = -405 $$

    Therefore, the 4th term in the sequence is -405.

    This model response is correct - now to make the response even more streamlined, you can ask the model to to think step-by-step.

    Updated prompt Improved response

    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.

    Specify the output format

    A common problem is the need for model output to be in a certain format (eg markdown, JSON, HTML), especially if the model output needs to be ingested by a downstream task. You can try to produce output in that format by instructing the model to do so within the prompt. Below are two examples:

    Prompt Model response

    Parse the table in this image into markdown format

    | 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 |

    Prompt Model response

    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

    }

    ```

    Put your image first for single-image prompts

    While Gemini can interpret image and text in any order within a prompt, placing a single image before the text prompt might lead to better results. In the following samples, you'll notice the image comes first before the text in each prompt.

    Troubleshooting your multimodal prompt

    You might need to troubleshoot your prompt if you are not getting a helpful response. Here are a few strategies you could try.

    If the model is not drawing information from the relevant part of the image

    To get a more specific response, you can point out which aspects of the image you want the prompt to draw information from to inform its response.

    Prompt Model response

    How many days will these diapers last a baby?

    The diapers will last for 198 days before they run out.

    Updated prompt Improved response

    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).

    If the model output is too generic and not tailored enough to the image input

    To help the model tailor its response to the image(s), try asking it to describe the images before performing its reasoning task.

    Prompt Model response

    What is in common between these images?

    All four images are examples of landscape photography.

    Updated prompt Improved response

    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.

    You can also try explicitly asking the model to refer to what's in the image.

    Updated prompt Improved response

    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.

    The same tips work for creative output from images. In the following example with the rabbit, explicitly asking the model to include aspects from the image can improve the output.

    Prompt Model response

    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.

    Updated prompt Improved response

    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.

    Troubleshooting which part of the prompt failed

    It can be hard to know whether a prompt failed because the model didn't understand the image to begin with, or if it did understand the image but did not perform the correct reasoning steps afterward. To disambiguate between those reasons, ask the model to describe what's in the image.

    In the following example, if the model responds with a snack that seems surprising when paired with tea (eg popcorn), you can first troubleshoot to determine whether the model correctly recognized that the image contains tea.

    Prompt Prompt for troubleshooting

    What's a snack I can make in 1 minute that would go well with this?

    Describe what's in this image.

    Another strategy is to ask the model to explain its reasoning. That can help you narrow down which part of the reasoning broke down, if any.

    Prompt Prompt for troubleshooting

    What's a snack I can make in 1 minute that would go well with this?

    What's a snack I can make in 1 minute that would go well with this? Please explain why.

    Çfarë vjen më pas

    • Provo të shkruash vetë kërkesat multimodale duke përdorur Google AI Studio .
    • For information on using the Gemini Files API for uploading media files and including them in your prompts, see the Vision , Audio , and Document processing guides.
    • For more guidance on prompt design, like tuning sampling parameters, see the Prompt strategies page.
    ,

    Gemini can handle various types of input data, including text, images, and audio, at the same time.

    This guide shows you how to work with media files using the Files API. The basic operations are the same for audio files, images, videos, documents, and other supported file types.

    For file prompting guidance, check out the File prompt guide section.

    Upload a file

    You can use the Files API to upload a media file. Always use the Files API when the total request size (including the files, text prompt, system instructions, etc.) is larger than 100 MB. For PDF files, the limit is 50 MB.

    The following code uploads a file and then uses the file in a call to generateContent .

    Python

    from google import genai
    
    client = genai.Client()
    
    myfile = client.files.upload(file="path/to/sample.mp3")
    
    response = client.models.generate_content(
        model="gemini-3.8-flash", contents=["Describe this audio clip", myfile]
    )
    
    print(response.text)
    

    JavaScript

    import {
      GoogleGenAI,
      createUserContent,
      createPartFromUri,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const myfile = await ai.files.upload({
        file: "path/to/sample.mp3",
        config: { mimeType: "audio/mpeg" },
      });
    
      const response = await ai.models.generateContent({
        model: "gemini-3.8-flash",
        contents: createUserContent([
          createPartFromUri(myfile.uri, myfile.mimeType),
          "Describe this audio clip",
        ]),
      });
      console.log(response.text);
    }
    
    await main();
    

    Shko

    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Files.Delete(ctx, file.Name)
    
    resp, err := client.Models.GenerateContent(ctx, "gemini-3.8-flash", []*genai.Content{
      {
        Parts: []*genai.Part{
          genai.NewPartFromFile(*file),
          genai.NewPartFromText("Describe this audio clip"),
        },
      },
    }, nil)
    
    if err != nil {
        log.Fatal(err)
    }
    
    printResponse(resp)
    

    PUSHTIM

    AUDIO_PATH="path/to/sample.mp3"
    MIME_TYPE=$(file -b --mime-type "${AUDIO_PATH}")
    NUM_BYTES=$(wc -c < "${AUDIO_PATH}")
    DISPLAY_NAME=AUDIO
    
    tmp_header_file=upload-header.tmp
    
    # Initial resumable request defining metadata.
    # The upload url is in the response headers dump them to a file.
    curl "${BASE_URL}/upload/v1beta/files" \
      -H "x-goog-api-key: $GEMINI_API_KEY" \
      -D "${tmp_header_file}" \
      -H "X-Goog-Upload-Protocol: resumable" \
      -H "X-Goog-Upload-Command: start" \
      -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
      -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
      -H "Content-Type: application/json" \
      -d "{'file': {'display_name': '${DISPLAY_NAME}'}}" 2> /dev/null
    
    upload_url=$(grep -i "x-goog-upload-url: " "${tmp_header_file}" | cut -d" " -f2 | tr -d "\r")
    rm "${tmp_header_file}"
    
    # Upload the actual bytes.
    curl "${upload_url}" \
      -H "Content-Length: ${NUM_BYTES}" \
      -H "X-Goog-Upload-Offset: 0" \
      -H "X-Goog-Upload-Command: upload, finalize" \
      --data-binary "@${AUDIO_PATH}" 2> /dev/null > file_info.json
    
    file_uri=$(jq ".file.uri" file_info.json)
    echo file_uri=$file_uri
    
    # Now generate content using that file
    curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent" \
        -H "x-goog-api-key: $GEMINI_API_KEY" \
        -H 'Content-Type: application/json' \
        -X POST \
        -d '{
          "contents": [{
            "parts":[
              {"text": "Describe this audio clip"},
              {"file_data":{"mime_type": "${MIME_TYPE}", "file_uri": '$file_uri'}}]
            }]
          }' 2> /dev/null > response.json
    
    cat response.json
    echo
    
    jq ".candidates[].content.parts[].text" response.json
    

    Get metadata for a file

    You can verify that the API successfully stored the uploaded file and get its metadata by calling files.get .

    Python

    from google import genai
    
    client = genai.Client()
    
    myfile = client.files.upload(file='path/to/sample.mp3')
    file_name = myfile.name
    myfile = client.files.get(name=file_name)
    print(myfile)
    

    JavaScript

    import {
      GoogleGenAI,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const myfile = await ai.files.upload({
        file: "path/to/sample.mp3",
        config: { mimeType: "audio/mpeg" },
      });
    
      const fileName = myfile.name;
      const fetchedFile = await ai.files.get({ name: fileName });
      console.log(fetchedFile);
    }
    
    await main();
    

    Shko

    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }
    
    gotFile, err := client.Files.Get(ctx, file.Name)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Got file:", gotFile.Name)
    

    PUSHTIM

    # file_info.json was created in the upload example
    name=$(jq ".file.name" file_info.json)
    # Get the file of interest to check state
    curl https://generativelanguage.googleapis.com/v1beta/files/$name \
    -H "x-goog-api-key: $GEMINI_API_KEY" > file_info.json
    # Print some information about the file you got
    name=$(jq ".file.name" file_info.json)
    echo name=$name
    file_uri=$(jq ".file.uri" file_info.json)
    echo file_uri=$file_uri
    

    List uploaded files

    The following code gets a list of all the files uploaded:

    Python

    from google import genai
    
    client = genai.Client()
    
    print('My files:')
    for f in client.files.list():
        print(' ', f.name)
    

    JavaScript

    import {
      GoogleGenAI,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const listResponse = await ai.files.list({ config: { pageSize: 10 } });
      for await (const file of listResponse) {
        console.log(file.name);
      }
    }
    
    await main();
    

    Shko

    for file, err := range client.Files.All(ctx) {
      if err != nil {
        log.Fatal(err)
      }
      fmt.Println(file.Name)
    }
    

    PUSHTIM

    echo "My files: "
    
    curl "https://generativelanguage.googleapis.com/v1beta/files" \
      -H "x-goog-api-key: $GEMINI_API_KEY"
    

    Delete uploaded files

    Files are automatically deleted after 48 hours. You can also manually delete an uploaded file:

    Python

    from google import genai
    
    client = genai.Client()
    
    myfile = client.files.upload(file='path/to/sample.mp3')
    client.files.delete(name=myfile.name)
    

    JavaScript

    import {
      GoogleGenAI,
    } from "@google/genai";
    
    const ai = new GoogleGenAI({});
    
    async function main() {
      const myfile = await ai.files.upload({
        file: "path/to/sample.mp3",
        config: { mimeType: "audio/mpeg" },
      });
    
      const fileName = myfile.name;
      await ai.files.delete({ name: fileName });
    }
    
    await main();
    

    Shko

    file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
    if err != nil {
        log.Fatal(err)
    }
    client.Files.Delete(ctx, file.Name)
    

    PUSHTIM

    curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/files/$name \
      -H "x-goog-api-key: $GEMINI_API_KEY"
    

    Usage information

    You can use the Files API to upload and interact with media files. The Files API lets you store up to 20 GB of files per project, with a per-file maximum size of 2 GB. Files are stored for 48 hours.

    During that time, you can use the API to get metadata about the files. However, you can't download user-uploaded files. You can download files generated by models, such as videos, using the files.download method. The Files API is available at no cost in all regions where the Gemini API is available.

    File prompting strategies

    This section provides guidance and best practices for using media files with prompts for the Gemini API.

    Being able to use various types of data in your prompts gives you more flexibility in terms of what tasks you can tackle with the Gemini API. For example, you can send the model a photo of a delicious meal and ask it to write a short blog about the meal.

    Prompt Përgjigje

    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.


    Kukitë

    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 easily 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 very easy 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 easily 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!

    If you are having trouble getting the output you want from prompts that use media files, there are some strategies that can help you get the results you want. The following sections provide design approaches and troubleshooting tips for improving prompts that use multimodal input.

    You can improve your multimodal prompts by following these best practices:

    • Prompt design fundamentals

      • Be specific in your instructions : Craft clear and concise instructions that leave minimal room for misinterpretation.
      • Add a few examples to your prompt: Use realistic few-shot examples to illustrate what you want to achieve.
      • Break it down step-by-step : Divide complex tasks into manageable sub-goals, guiding the model through the process.
      • Specify the output format : In your prompt, ask for the output to be in the format you want, like markdown, JSON, HTML and more.
      • 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.
    • Troubleshooting your multimodal prompt

      • 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.
      • 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.
      • 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.
      • 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.
      • Tuning the sampling parameters: Experiment with different temperature settings and top-k selections to adjust the model's creativity.

    Be specific in your instructions

    Prompts have the most success when they are clear and detailed. If you have a specific output in mind, it's better to include that requirement in the prompt to ensure you get the output you want.

    For this image of an airport board, asking the model to just "describe this image" could generate a general description. If you need the model to parse the time and city from the image, you can include that request directly in your prompt.

    Prompt Model response

    Describe this image.

    The image shows an airport arrivals and departures board.

    Updated prompt Improved response
    Travel timetable

    Parse the time and city from the airport board shown in this image into a list.

  • 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
  • Add a few examples

    The Gemini model can accept multiple inputs which it can use as examples to understand the output you want. Adding these examples can help the model identify the patterns and apply the relationship between the given images and responses to the new example. This is also called "few-shot" learning.

    In the example below, the initial output is written in sentence form, and also contains the country (Brazil). Suppose you want the output in a different format or style, and you want only the city, not the country. Adding few-shot examples to your prompt can steer the model to respond in the way you want.

    Prompt Model response
    Travel timetable

    Determine the city along with the landmark.

    The landmark is the Christ the Redeemer statue in Rio de Janeiro, Brazil.

    Updated prompt Improved response

    Determine the city along with the landmark.

    colosseum

    city: Rome, landmark: the Colosseum.

    Forbidden City

    city: Beijing, landmark: Forbidden City

    forbidden-city

    city: Rio de Janeiro, landmark: Christ the Redeemer statue

    Break it down step-by-step

    For complex tasks like the ones that require both visual understanding and reasoning, it can be helpful to split the task into smaller, more straightforward steps. Alternatively, it could also be effective if you directly ask the model to “think step by step” in your prompt.

    Prompt Model response

    When will I run out of toilet paper?

    Soon, you only have 3 rolls left.

    Updated prompt Improved response

      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.

    Math problems or other types of word problems are great candidates for asking the model to think step-by-step.

    Prompt Përgjigje

    What is the 4th term in the sequence?

    -135

    The response from the model is incorrect. Some ways to improve this is to ask the model to parse the problem before answering the prompt.

    Prompt Përgjigje

    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:
    2. $$ b(4) = b(4-1) * (-3) $$

      $$ b(4) = b(3) * (-3) $$

    3. We don't know the value of b(3), so substitute n = 3 into the formula:
    4. $$ b(3) = b(3-1) * (-3) $$

      $$ b(3) = b(2) * (-3) $$

    5. We don't know the value of b(2), so substitute n = 2 into the formula:
    6. $$ b(2) = b(2-1) * (-3) $$

      $$ b(2) = b(1) * (-3) $$

    7. We know the value of b(1) is 15, so substitute it into the formula:
    8. $$ b(2) = 15 * (-3) $$

      $$ b(2) = -45 $$

    9. Now that we know the value of b(2), substitute it into the formula for b(3):
    10. $$ b(3) = b(2) * (-3) $$

      $$ b(3) = -45 * (-3) $$

      $$ b(3) = 135 $$

    11. Now that we know the value of b(3), substitute it into the formula for b(4):
    12. $$ b(4) = b(3) * (-3) $$

      $$ b(4) = 135 * (-3) $$

      $$ b(4) = -405 $$

    Therefore, the 4th term in the sequence is -405.

    This model response is correct - now to make the response even more streamlined, you can ask the model to to think step-by-step.

    Updated prompt Improved response

    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.

    Specify the output format

    A common problem is the need for model output to be in a certain format (eg markdown, JSON, HTML), especially if the model output needs to be ingested by a downstream task. You can try to produce output in that format by instructing the model to do so within the prompt. Below are two examples:

    Prompt Model response

    Parse the table in this image into markdown format

    | 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 |

    Prompt Model response

    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

    }

    ```

    Put your image first for single-image prompts

    While Gemini can interpret image and text in any order within a prompt, placing a single image before the text prompt might lead to better results. In the following samples, you'll notice the image comes first before the text in each prompt.

    Troubleshooting your multimodal prompt

    You might need to troubleshoot your prompt if you are not getting a helpful response. Here are a few strategies you could try.

    If the model is not drawing information from the relevant part of the image

    To get a more specific response, you can point out which aspects of the image you want the prompt to draw information from to inform its response.

    Prompt Model response

    How many days will these diapers last a baby?

    The diapers will last for 198 days before they run out.

    Updated prompt Improved response

    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).

    If the model output is too generic and not tailored enough to the image input

    To help the model tailor its response to the image(s), try asking it to describe the images before performing its reasoning task.

    Prompt Model response

    What is in common between these images?

    All four images are examples of landscape photography.

    Updated prompt Improved response

    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.

    You can also try explicitly asking the model to refer to what's in the image.

    Updated prompt Improved response

    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.

    The same tips work for creative output from images. In the following example with the rabbit, explicitly asking the model to include aspects from the image can improve the output.

    Prompt Model response

    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.

    Updated prompt Improved response

    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.

    Troubleshooting which part of the prompt failed

    It can be hard to know whether a prompt failed because the model didn't understand the image to begin with, or if it did understand the image but did not perform the correct reasoning steps afterward. To disambiguate between those reasons, ask the model to describe what's in the image.

    In the following example, if the model responds with a snack that seems surprising when paired with tea (eg popcorn), you can first troubleshoot to determine whether the model correctly recognized that the image contains tea.

    Prompt Prompt for troubleshooting

    What's a snack I can make in 1 minute that would go well with this?

    Describe what's in this image.

    Another strategy is to ask the model to explain its reasoning. That can help you narrow down which part of the reasoning broke down, if any.

    Prompt Prompt for troubleshooting

    What's a snack I can make in 1 minute that would go well with this?

    What's a snack I can make in 1 minute that would go well with this? Please explain why.

    Çfarë vjen më pas

    • Provo të shkruash vetë kërkesat multimodale duke përdorur Google AI Studio .
    • For information on using the Gemini Files API for uploading media files and including them in your prompts, see the Vision , Audio , and Document processing guides.
    • For more guidance on prompt design, like tuning sampling parameters, see the Prompt strategies page.