جمینی میتواند انواع مختلفی از دادههای ورودی، از جمله متن، تصاویر و صدا را به طور همزمان مدیریت کند.
این راهنما به شما نشان میدهد که چگونه با فایلهای رسانهای با استفاده از API فایلها کار کنید. عملیات اساسی برای فایلهای صوتی، تصاویر، ویدیوها، اسناد و سایر انواع فایلهای پشتیبانی شده یکسان است.
برای راهنمایی در مورد نحوهی ارسال فایل، به بخش راهنمای ارسال فایل مراجعه کنید.
آپلود فایل
شما میتوانید از API فایلها برای آپلود یک فایل رسانهای استفاده کنید. همیشه زمانی که حجم کل درخواست (شامل فایلها، متن درخواست، دستورالعملهای سیستم و غیره) بیشتر از ۱۰۰ مگابایت است، از API فایلها استفاده کنید. برای فایلهای PDF، این محدودیت ۵۰ مگابایت است.
کد زیر یک فایل را آپلود میکند و سپس از آن فایل در فراخوانی interactions.create استفاده میکند.
پایتون
from google import genai
client = genai.Client()
myfile = client.files.upload(file="path/to/sample.mp3")
interaction = client.interactions.create(
model="gemini-3.8-flash",
input=[
{"type": "text", "text": "Describe this audio clip"},
{"type": "audio", "uri": myfile.uri, "mime_type": myfile.mime_type}
]
)
print(interaction.output_text)
جاوا اسکریپت
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const interaction = await client.interactions.create({
model: "gemini-3.8-flash",
input: [
{ type: "text", text: "Describe this audio clip" },
{ type: "audio", uri: myfile.uri, mime_type: myfile.mimeType }
]
});
console.log(interaction.output_text);
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
log.Fatal(err)
}
defer client.Files.Delete(ctx, file.Name)
interaction, err := client.Interactions.Create(ctx, "gemini-3.8-flash", &genai.InteractionRequest{
Input: []interface{}{
genai.NewPartFromFile(*file),
genai.NewPartFromText("Describe this audio clip"),
},
}, nil)
if err != nil {
log.Fatal(err)
}
// Print the model's text response
for _, step := range interaction.Steps {
if step.Type == "model_output" {
for _, part := range step.Content {
if part.Type == "text" {
fmt.Println(part.Text)
}
}
}
}
استراحت
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 create an interaction using the Interactions API
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3.8-flash",
"input": [
{"type": "text", "text": "Describe this audio clip"},
{"type": "audio", "uri": '$file_uri', "mime_type": "'${MIME_TYPE}'"}
]
}' 2> /dev/null > response.json
cat response.json
echo
jq ".outputs[] | select(.type == \"text\") | .text" response.json
دریافت متادیتا برای یک فایل
شما میتوانید با فراخوانی files.get تأیید کنید که API با موفقیت فایل آپلود شده را ذخیره کرده و فرادادههای آن را دریافت کنید.
پایتون
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)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const fileName = myfile.name;
const fetchedFile = await client.files.get({ name: fileName });
console.log(fetchedFile);
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
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)
استراحت
# file_info.json was created in the upload example
name=$(jq -r ".file.name" file_info.json)
# Get the file of interest to check state
curl https://generativelanguage.googleapis.com/v1beta/$name \
-H "x-goog-api-key: $GEMINI_API_KEY" > file_info.json
# Print some information about the file you got
name=$(jq -r ".name" file_info.json)
echo name=$name
file_uri=$(jq -r ".uri" file_info.json)
echo file_uri=$file_uri
فهرست کردن فایلهای آپلود شده
کد زیر لیستی از تمام فایلهای آپلود شده را دریافت میکند:
پایتون
from google import genai
client = genai.Client()
print('My files:')
for f in client.files.list():
print(' ', f.name)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const listResponse = await client.files.list({ config: { pageSize: 10 } });
for await (const file of listResponse) {
console.log(file.name);
}
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
for file, err := range client.Files.All(ctx) {
if err != nil {
log.Fatal(err)
}
fmt.Println(file.Name)
}
استراحت
echo "My files: "
curl "https://generativelanguage.googleapis.com/v1beta/files" \
-H "x-goog-api-key: $GEMINI_API_KEY"
حذف فایلهای آپلود شده
فایلها پس از ۴۸ ساعت بهطور خودکار حذف میشوند. همچنین میتوانید فایل آپلود شده را بهصورت دستی حذف کنید:
پایتون
from google import genai
client = genai.Client()
myfile = client.files.upload(file='path/to/sample.mp3')
client.files.delete(name=myfile.name)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const fileName = myfile.name;
await client.files.delete({ name: fileName });
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
log.Fatal(err)
}
client.Files.Delete(ctx, file.Name)
استراحت
curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/$name \
-H "x-goog-api-key: $GEMINI_API_KEY"
اطلاعات استفاده
شما میتوانید از API فایلها برای آپلود و تعامل با فایلهای رسانهای استفاده کنید. API فایلها به شما امکان میدهد تا حداکثر 20 گیگابایت فایل در هر پروژه ذخیره کنید، که حداکثر اندازه هر فایل 2 گیگابایت است. فایلها به مدت 48 ساعت ذخیره میشوند.
در طول این مدت، میتوانید از API برای دریافت فرادادههای مربوط به فایلها استفاده کنید. با این حال، نمیتوانید فایلهای آپلود شده توسط کاربر را دانلود کنید. میتوانید فایلهای تولید شده توسط مدلها، مانند ویدیوها، را با استفاده از روش files.download دانلود کنید. API فایلها در تمام مناطقی که API Gemini در دسترس است، به صورت رایگان در دسترس است.
استراتژیهای ارسال فایل
این بخش راهنماییها و بهترین شیوهها را برای استفاده از فایلهای رسانهای با اعلانهایی برای API Gemini ارائه میدهد.
امکان استفاده از انواع مختلف دادهها در درخواستهایتان، انعطافپذیری بیشتری را در مورد وظایفی که میتوانید با API Gemini انجام دهید، به شما میدهد. به عنوان مثال، میتوانید عکسی از یک غذای خوشمزه را برای مدل ارسال کنید و از او بخواهید که یک وبلاگ کوتاه در مورد آن غذا بنویسد.
| سریع | پاسخ |
یک پست وبلاگ کوتاه و جذاب بر اساس این تصویر بنویسید. این پست باید شامل توضیحی از غذای داخل عکس و نحوه آمادهسازی غذای سفر من باشد. ![]() | آماده کردن وعدههای غذایی راهی عالی برای صرفهجویی در زمان و هزینه است و همچنین میتواند به شما در داشتن تغذیه سالمتر کمک کند. این وعده غذایی نمونهای عالی از یک وعده غذایی سالم و خوشمزه است که میتوان آن را از قبل آماده کرد. این غذا شامل برنج قهوهای، سبزیجات کبابی و مرغ تِریاکی است. برنج قهوهای یک کربوهیدرات سالم و پیچیده است که به شما انرژی پایدار میدهد. سبزیجات کبابی راهی عالی برای دریافت دوز روزانه ویتامینها و مواد معدنی هستند و مرغ تِریاکی یک گزینه خوشمزه و سرشار از پروتئین است. تهیه این غذا نیز ساده است. کافیست برنج قهوهای را بپزید، سبزیجات را کباب کنید و مرغ تِریاکی را بپزید. وقتی همه چیز پخته شد، آن را در ظروف مخصوص غذا تقسیم کنید و در یخچال نگهداری کنید. سپس میتوانید یک ظرف بردارید و صبحهای پرمشغلهتان را شروع کنید! اگر به دنبال یک وعده غذایی سالم و خوشمزه هستید که بتوانید از قبل آن را آماده کنید، این غذا گزینه بسیار خوبی است. این غذا سرشار از مواد مغذی و طعم دهنده است و مطمئناً شما را سیر و راضی نگه میدارد. آمادهسازی وعدههای غذایی سالم و خوشمزه! |
اگر در دریافت خروجی مورد نظر خود از اعلانهایی که از فایلهای رسانهای استفاده میکنند، مشکل دارید، چند استراتژی وجود دارد که میتواند به شما در دستیابی به نتایج مورد نظر کمک کند. بخشهای زیر رویکردهای طراحی و نکات عیبیابی را برای بهبود اعلانهایی که از ورودی چندوجهی استفاده میکنند، ارائه میدهند.
شما میتوانید با دنبال کردن این بهترین شیوهها، پیامهای چندوجهی خود را بهبود بخشید:
اصول طراحی سریع
- در دستورالعملهای خود دقیق باشید : دستورالعملهای واضح و مختصری تهیه کنید که کمترین امکان سوء تعبیر را باقی بگذارد.
- چند مثال به سوالتان اضافه کنید: از مثالهای واقعبینانه و کوتاه برای نشان دادن آنچه میخواهید به دست آورید، استفاده کنید.
- گام به گام آن را تجزیه کنید : وظایف پیچیده را به زیر اهداف قابل مدیریت تقسیم کنید و مدل را در طول فرآیند هدایت کنید.
- قالب خروجی را مشخص کنید : در اعلان خود، فرمت خروجی مورد نظر خود را مانند Markdown، JSON، HTML و موارد دیگر درخواست کنید.
- برای درخواستهای تک تصویری، تصویر خود را در اولویت قرار دهید : اگرچه Gemini میتواند ورودیهای تصویر و متن را به هر ترتیبی مدیریت کند، اما برای درخواستهایی که شامل یک تصویر واحد هستند، اگر آن تصویر (یا ویدیو) قبل از متن قرار گیرد، ممکن است عملکرد بهتری داشته باشد. با این حال، برای درخواستهایی که برای معنادار شدن نیاز به تصاویر با متنهای زیاد دارند، از هر ترتیبی که طبیعیتر است استفاده کنید.
عیبیابی اعلان چندوجهی شما
- اگر مدل اطلاعات را از قسمت مربوط به تصویر استخراج نمیکند: با استفاده از راهنما مشخص کنید که میخواهید از کدام جنبههای تصویر، اطلاعات استخراج شود.
- اگر خروجی مدل خیلی کلی است (به اندازه کافی با ورودی تصویر/ویدئو متناسب نیست): در ابتدای درخواست، قبل از ارائه دستورالعمل کار، از مدل بخواهید تصویر(ها) یا ویدئو را توصیف کند، یا سعی کنید از مدل بخواهید به آنچه در تصویر است اشاره کند.
- برای عیبیابی اینکه کدام بخش دچار مشکل شده است: از مدل بخواهید تصویر را توصیف کند، یا از مدل بخواهید استدلال خود را توضیح دهد تا درک اولیه مدل را بسنجید.
- اگر نتیجهی درخواست شما منجر به محتوای توهمزا شد: سعی کنید تنظیمات دما را کاهش دهید یا از مدل بخواهید توضیحات کوتاهتری ارائه دهد تا احتمال تعمیم جزئیات اضافی کمتر شود.
- تنظیم پارامترهای نمونهبرداری: برای تنظیم خلاقیت مدل، تنظیمات دمایی مختلف و انتخابهای top-k را آزمایش کنید.
در دستورالعملهایتان دقیق باشید
دستورالعملها زمانی بیشترین موفقیت را دارند که واضح و با جزئیات باشند. اگر خروجی خاصی مد نظر دارید، بهتر است آن الزام را در دستورالعمل بگنجانید تا مطمئن شوید خروجی مورد نظر خود را دریافت میکنید.
برای این تصویر از تابلوی فرودگاه، درخواست از مدل برای «توصیف این تصویر» میتواند یک توصیف کلی ایجاد کند. اگر به مدل نیاز دارید که زمان و شهر را از تصویر تجزیه کند، میتوانید این درخواست را مستقیماً در اعلان خود وارد کنید.
| سریع | پاسخ مدل |
|---|---|
![]() این تصویر را توصیف کنید. | تصویر، تابلوی ورود و خروج مسافران فرودگاه را نشان میدهد. |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() زمان و شهر را از روی تابلوی فرودگاه که در این تصویر نشان داده شده است، در یک لیست تجزیه کنید. |
چند مثال اضافه کنید
مدل Gemini میتواند چندین ورودی را بپذیرد که میتواند از آنها به عنوان مثال برای درک خروجی مورد نظر شما استفاده کند. افزودن این مثالها میتواند به مدل کمک کند تا الگوها را شناسایی کرده و رابطه بین تصاویر و پاسخهای داده شده را در مثال جدید اعمال کند. به این روش یادگیری "چند مرحلهای" نیز گفته میشود.
در مثال زیر، خروجی اولیه به صورت جمله نوشته شده است و شامل کشور (برزیل) نیز میشود. فرض کنید میخواهید خروجی با فرمت یا سبک متفاوتی باشد و فقط شهر را میخواهید، نه کشور را. اضافه کردن چند مثال کوتاه به درخواست شما میتواند مدل را به سمتی هدایت کند که شما میخواهید پاسخ دهد.
| سریع | پاسخ مدل |
|---|---|
![]() شهر را به همراه نقطه عطف آن مشخص کنید. | یکی از نمادهای مهم این شهر، مجسمه مسیح منجی در ریودوژانیرو برزیل است. |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
شهر را به همراه نقطه عطف آن مشخص کنید. ![]() | شهر: رم، بنای تاریخی: کولوسئوم. |
![]() | شهر: پکن، جاذبه گردشگری: شهر ممنوعه |
![]() | شهر: ریودوژانیرو، نقطه عطف: مجسمه مسیح منجی |
گام به گام آن را تجزیه کنید
برای کارهای پیچیدهای مانند کارهایی که هم به درک بصری و هم به استدلال نیاز دارند، تقسیم کار به مراحل کوچکتر و سرراستتر میتواند مفید باشد. از طرف دیگر، اگر مستقیماً از مدل بخواهید که در سوال شما «گام به گام فکر کند» نیز میتواند مؤثر باشد.
| سریع | پاسخ مدل |
|---|---|
![]() کی دستمال توالتم تموم میشه؟ | خیلی زود، فقط ۳ رول دیگر باقی مانده است. |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]()
|
|
مسائل ریاضی یا انواع دیگر مسائل کلامی، گزینههای بسیار خوبی برای درخواست از مدل برای تفکر گام به گام هستند.
| سریع | پاسخ |
|---|---|
![]() جمله چهارم دنباله چیست؟ | -۱۳۵ |
پاسخ مدل نادرست است. یکی از راههای بهبود این مشکل این است که از مدل بخواهیم قبل از پاسخ دادن به سوال، مسئله را تجزیه و تحلیل کند.
| سریع | پاسخ |
|---|---|
![]() ابتدا فرمول موجود در تصویر را تجزیه کنید. سپس بر اساس فرمول، به سوال «جمله چهارم در دنباله چیست؟» پاسخ دهید. | برای گسترش نتیجه کلیک کنید$$ b(n) = b(n-1) * (-3) $$ $$ b(1) = 15 $$
بنابراین، جمله چهارم در این دنباله -405 است. |
این پاسخ مدل صحیح است - اکنون برای سادهتر کردن پاسخ، میتوانید از مدل بخواهید که گام به گام فکر کند.
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() جمله چهارم این دنباله چیست؟ گام به گام فکر کنید. | ترم اول ۱۵ است. جمله دوم عبارت است از b(1) * (-3) = 15 * (-3) = -45. جمله سوم عبارت است از b(2) * (-3) = -45 * (-3) = 135. جمله چهارم عبارت است از b(3) * (-3) = 135 * (-3) = -405. |
فرمت خروجی را مشخص کنید
یک مشکل رایج، نیاز به خروجی مدل در قالب خاصی (مثلاً Markdown، JSON، HTML) است، به خصوص اگر خروجی مدل نیاز به استفاده توسط یک وظیفه پاییندستی داشته باشد. میتوانید با دستور دادن به مدل برای انجام این کار در داخل اعلان، سعی کنید خروجی را در آن قالب تولید کنید. در زیر دو مثال آورده شده است:
| سریع | پاسخ مدل |
|---|---|
![]() جدول موجود در این تصویر را به فرمت Markdown تجزیه کنید | ```هیچ | موضوع | وضعیت | زمان | تاریخ شروع | مهلت تحویل | | ------- | ----- | ---- | ---------- | ----- | | ریاضی | انجام شده | ۱.۵ ساعت | ۲۹/۱۱/۲۰۲۳ | ۱/۱۲/۲۰۲۳ | | جغرافیا | انجام شده | ۳۰ دقیقه | ۲/۱۲/۲۰۲۳ | ۴/۱۲/۲۰۲۳ | | فیزیک | در حال انجام | ۲ ساعت | ۳/۱۲/۲۰۲۳ | ۵/۱۲/۲۰۲۳ | | زیست شناسی | شروع نشده | ۶ ساعت | ۲/۱۱/۲۰۱۶ | ۶/۱۲/۲۰۲۳ | ``` |
| سریع | پاسخ مدل |
|---|---|
![]() فهرستی از تمام ویژگیهای زیر ارائه دهید: مواد لازم، نوع غذا، گیاهی یا غیرگیاهی، در قالب JSON | ```json { "مواد لازم": [ "برنج"، "میگو"، "صدف"، "صدف سیاه"، "نخود فرنگی"، "گوجه فرنگی"، "پیاز"، "سیر"، "روغن زیتون"، "پاپریکا"، "نمک"، "فلفل" ]، "نوع غذا": "اسپانیایی"، "گیاهخواری": false } ``` |
برای درخواستهای تکتصویری، تصویر خود را در اولویت قرار دهید
اگرچه Gemini میتواند تصویر و متن را به هر ترتیبی در یک اعلان تفسیر کند، قرار دادن یک تصویر واحد قبل از اعلان متنی ممکن است منجر به نتایج بهتری شود. در نمونههای زیر، متوجه خواهید شد که تصویر در هر اعلان قبل از متن قرار میگیرد.
عیبیابی اعلان چندوجهی شما
اگر پاسخ مفیدی دریافت نمیکنید، ممکن است لازم باشد مشکل درخواست خود را عیبیابی کنید. در اینجا چند استراتژی وجود دارد که میتوانید امتحان کنید.
اگر مدل اطلاعات را از قسمت مربوط به تصویر ترسیم نمیکند
برای دریافت پاسخ دقیقتر، میتوانید مشخص کنید که میخواهید سوال از کدام جنبههای تصویر برای ارائه پاسخ استفاده کند.
| سریع | پاسخ مدل |
|---|---|
![]() این پوشکها برای چند روز برای نوزاد کافی هستند؟ | این پوشکها تا ۱۹۸ روز دوام میآورند و بعد تمام میشوند. |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() این پوشکها قبل از اینکه تمام شوند، چقدر دوام میآورند؟ از وزن نشان داده شده روی جعبه برای تعیین سن کودک استفاده کنید و تعداد کل پوشکهای موجود در جعبه را در نظر بگیرید. عدد کل را بر تعداد پوشکهایی که کودک در روز استفاده میکند تقسیم کنید. | این جعبه حاوی ۱۹۸ پوشک است. روی جعبه ذکر شده که این پوشکها برای کودکی با وزن ۲۲ تا ۳۷ پوند (حدود ۱۰ تا ۱۲ کیلوگرم) مناسب هستند. کودک متوسط در این محدوده وزنی احتمالاً بین ۱ تا ۲ سال سن دارد. یک کودک ۲ ساله معمولاً روزانه ۶ پوشک عوض میکند، بنابراین، پوشکها حدود ۳۳ روز (۱۹۸/۶) دوام میآورند. |
اگر خروجی مدل بیش از حد عمومی باشد و به اندازه کافی با ورودی تصویر متناسب نباشد
برای کمک به مدل در تنظیم پاسخ خود به تصویر(ها)، سعی کنید قبل از انجام وظیفه استدلال، از آن بخواهید تصاویر را توصیف کند.
| سریع | پاسخ مدل |
|---|---|
![]() ![]() ![]() ![]() چه وجه مشترکی بین این تصاویر وجود دارد؟ | هر چهار تصویر نمونههایی از عکاسی منظره هستند. |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() ![]() ![]() ![]() ابتدا، آنچه در هر تصویر وجود دارد را با جزئیات شرح دهید. چه چیزی بین این تصاویر مشترک است؟ | تصویر اول شخصی را نشان میدهد که در حال بستن چمدان است. تصویر دوم یک راهروی خالی در یک مرکز خرید را نشان میدهد. تصویر سوم یک رول دستمال توالت را نشان میدهد. تصویر چهارم دریایی تاریک و طوفانی را نشان میدهد. وجه مشترک این تصاویر این است که همه آنها نمونههایی از فضاهای آستانهای هستند. فضاهای آستانهای مکانها یا موقعیتهایی هستند که بین دو مکان یا موقعیت دیگر قرار دارند. آنها اغلب با حس عدم قطعیت یا ابهام مشخص میشوند. تصویر اول، فردی را نشان میدهد که بین خانه و سفر قرار دارد. تصویر دوم راهروی بین دو فروشگاه را نشان میدهد. تصویر سوم دستمال توالت است که میتواند نمایانگر حمام باشد. حمام یک فضای انتقالی بین قلمروهای خصوصی و عمومی است. جایی است که ما خود را برای ورود یا خروج از دنیای بیرون آماده میکنیم. تصویر چهارم دریا را در حالتی بین آرام و طوفانی نشان میدهد. فضاهای آستانهای میتوانند هم هیجانانگیز و هم نگرانکننده باشند. آنها میتوانند مکانی برای شروعهای جدید یا مکانی برای پایانها باشند. آنها میتوانند مکانی برای تأمل یا مکانی برای عمل باشند. |
همچنین میتوانید صریحاً از مدل بخواهید که به آنچه در تصویر است اشاره کند.
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() ![]() ![]() ![]() چه وجه مشترکی بین این تصاویر وجود دارد؟ در پاسخ خود به آنچه در تصاویر وجود دارد اشاره کنید. | همه تصاویر مربوط به سفر هستند. تصویر اول شخصی را در حال بستن چمدان نشان میدهد، تصویر دوم راهروی خالی یک مرکز خرید را نشان میدهد، تصویر سوم یک دسته دستمال توالت را نشان میدهد و تصویر چهارم دریایی تاریک و طوفانی را نشان میدهد. این تصاویر همگی مربوط به سفر هستند، زیرا همگی چیزهایی هستند که مردم هنگام سفر به آنها نیاز دارند یا از آنها استفاده میکنند. تصویر اول شخصی را نشان میدهد که در حال بستن چمدان است، کاری که مردم هنگام رفتن به سفر انجام میدهند. تصویر دوم یک راهروی خالی در یک مرکز خرید را نشان میدهد، جایی که مردم اغلب برای خرید وسایل سفر خود به آنجا میروند. تصویر سوم یک دسته دستمال توالت را نشان میدهد، چیزی که مردم اغلب هنگام سفر از آن استفاده میکنند. تصویر چهارم دریایی تاریک و طوفانی را نشان میدهد، چیزی که مردم اغلب هنگام سفر با آن مواجه میشوند. |
همین نکات برای خروجی خلاقانه از تصاویر نیز کارساز هستند. در مثال زیر با خرگوش، درخواست صریح از مدل برای گنجاندن جنبههایی از تصویر میتواند خروجی را بهبود بخشد.
| سریع | پاسخ مدل |
|---|---|
![]() میشه یه شعر در مورد این تصویر برام بنویسی؟ | خرگوش کوچولو، خیلی نرم و قهوهای، تو علفها را میجوی، چه سبز و شیرین، |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() میشه یه شعر توصیفی و دراماتیک در مورد این تصویر برام بنویسی و مکانش رو هم بنویسی؟ | خرگوش کوچولو روی چمنزار، آیا اقیانوس آبی است، خرگوش کوچولو، راستش را بگو، شاید به خاطر وسعت همه چیز باشد، خرگوش کوچولو، نمیدانم چه خوابی میبینی، هرچی که باشه، خرگوش کوچولو، |
عیبیابی اینکه کدام بخش از اعلان ناموفق بود
تشخیص اینکه آیا یک درخواست به این دلیل ناموفق بوده که مدل از ابتدا تصویر را نفهمیده است، یا اینکه تصویر را فهمیده اما مراحل استدلال صحیح را بعداً انجام نداده است، میتواند دشوار باشد. برای ابهامزدایی بین این دلایل، از مدل بخواهید آنچه را که در تصویر است توصیف کند.
در مثال زیر، اگر مدل با یک میان وعده که در کنار چای غافلگیرکننده به نظر میرسد (مثلاً پاپ کورن) پاسخ دهد، میتوانید ابتدا عیبیابی کنید تا مشخص شود که آیا مدل به درستی تشخیص داده است که تصویر حاوی چای است یا خیر.
| سریع | درخواست راهنمایی برای رفع مشکل |
|---|---|
![]() چه میان وعده ای هست که بتونم تو ۱ دقیقه درست کنم که با این خوب بشه؟ | ![]() آنچه در این تصویر است را توصیف کنید. |
یک استراتژی دیگر این است که از مدل بخواهید استدلال خود را توضیح دهد. این میتواند به شما کمک کند تا مشخص کنید کدام بخش از استدلال، در صورت وجود، با شکست مواجه شده است.
| سریع | درخواست راهنمایی برای رفع مشکل |
|---|---|
![]() چه میان وعده ای هست که بتونم تو ۱ دقیقه درست کنم که با این خوب بشه؟ | ![]() چه خوراکیای هست که بتونم تو ۱ دقیقه درست کنم که با این خوب بشه؟ لطفا توضیح بدید چرا؟ |
قدم بعدی چیست؟
- سعی کنید با استفاده از Google AI Studio، دستورالعملهای چندوجهی خودتان را بنویسید.
- برای اطلاعات بیشتر در مورد استفاده از API فایلهای Gemini برای آپلود فایلهای رسانهای و گنجاندن آنها در اعلانهایتان، به راهنماهای پردازش تصویر ، صدا و سند مراجعه کنید.
- برای راهنمایی بیشتر در مورد طراحی سریع، مانند تنظیم پارامترهای نمونهگیری، به صفحه استراتژیهای سریع مراجعه کنید.
جمینی میتواند انواع مختلفی از دادههای ورودی، از جمله متن، تصاویر و صدا را به طور همزمان مدیریت کند.
این راهنما به شما نشان میدهد که چگونه با فایلهای رسانهای با استفاده از API فایلها کار کنید. عملیات اساسی برای فایلهای صوتی، تصاویر، ویدیوها، اسناد و سایر انواع فایلهای پشتیبانی شده یکسان است.
برای راهنمایی در مورد نحوهی ارسال فایل، به بخش راهنمای ارسال فایل مراجعه کنید.
آپلود فایل
شما میتوانید از API فایلها برای آپلود یک فایل رسانهای استفاده کنید. همیشه زمانی که حجم کل درخواست (شامل فایلها، متن درخواست، دستورالعملهای سیستم و غیره) بیشتر از ۱۰۰ مگابایت است، از API فایلها استفاده کنید. برای فایلهای PDF، این محدودیت ۵۰ مگابایت است.
کد زیر یک فایل را آپلود میکند و سپس از آن فایل در فراخوانی interactions.create استفاده میکند.
پایتون
from google import genai
client = genai.Client()
myfile = client.files.upload(file="path/to/sample.mp3")
interaction = client.interactions.create(
model="gemini-3.8-flash",
input=[
{"type": "text", "text": "Describe this audio clip"},
{"type": "audio", "uri": myfile.uri, "mime_type": myfile.mime_type}
]
)
print(interaction.output_text)
جاوا اسکریپت
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const interaction = await client.interactions.create({
model: "gemini-3.8-flash",
input: [
{ type: "text", text: "Describe this audio clip" },
{ type: "audio", uri: myfile.uri, mime_type: myfile.mimeType }
]
});
console.log(interaction.output_text);
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
log.Fatal(err)
}
defer client.Files.Delete(ctx, file.Name)
interaction, err := client.Interactions.Create(ctx, "gemini-3.8-flash", &genai.InteractionRequest{
Input: []interface{}{
genai.NewPartFromFile(*file),
genai.NewPartFromText("Describe this audio clip"),
},
}, nil)
if err != nil {
log.Fatal(err)
}
// Print the model's text response
for _, step := range interaction.Steps {
if step.Type == "model_output" {
for _, part := range step.Content {
if part.Type == "text" {
fmt.Println(part.Text)
}
}
}
}
استراحت
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 create an interaction using the Interactions API
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3.8-flash",
"input": [
{"type": "text", "text": "Describe this audio clip"},
{"type": "audio", "uri": '$file_uri', "mime_type": "'${MIME_TYPE}'"}
]
}' 2> /dev/null > response.json
cat response.json
echo
jq ".outputs[] | select(.type == \"text\") | .text" response.json
دریافت متادیتا برای یک فایل
شما میتوانید با فراخوانی files.get تأیید کنید که API با موفقیت فایل آپلود شده را ذخیره کرده و فرادادههای آن را دریافت کنید.
پایتون
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)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const fileName = myfile.name;
const fetchedFile = await client.files.get({ name: fileName });
console.log(fetchedFile);
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
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)
استراحت
# file_info.json was created in the upload example
name=$(jq -r ".file.name" file_info.json)
# Get the file of interest to check state
curl https://generativelanguage.googleapis.com/v1beta/$name \
-H "x-goog-api-key: $GEMINI_API_KEY" > file_info.json
# Print some information about the file you got
name=$(jq -r ".name" file_info.json)
echo name=$name
file_uri=$(jq -r ".uri" file_info.json)
echo file_uri=$file_uri
فهرست کردن فایلهای آپلود شده
کد زیر لیستی از تمام فایلهای آپلود شده را دریافت میکند:
پایتون
from google import genai
client = genai.Client()
print('My files:')
for f in client.files.list():
print(' ', f.name)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const listResponse = await client.files.list({ config: { pageSize: 10 } });
for await (const file of listResponse) {
console.log(file.name);
}
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
for file, err := range client.Files.All(ctx) {
if err != nil {
log.Fatal(err)
}
fmt.Println(file.Name)
}
استراحت
echo "My files: "
curl "https://generativelanguage.googleapis.com/v1beta/files" \
-H "x-goog-api-key: $GEMINI_API_KEY"
حذف فایلهای آپلود شده
فایلها پس از ۴۸ ساعت بهطور خودکار حذف میشوند. همچنین میتوانید فایل آپلود شده را بهصورت دستی حذف کنید:
پایتون
from google import genai
client = genai.Client()
myfile = client.files.upload(file='path/to/sample.mp3')
client.files.delete(name=myfile.name)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const fileName = myfile.name;
await client.files.delete({ name: fileName });
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
log.Fatal(err)
}
client.Files.Delete(ctx, file.Name)
استراحت
curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/$name \
-H "x-goog-api-key: $GEMINI_API_KEY"
اطلاعات استفاده
شما میتوانید از API فایلها برای آپلود و تعامل با فایلهای رسانهای استفاده کنید. API فایلها به شما امکان میدهد تا حداکثر 20 گیگابایت فایل در هر پروژه ذخیره کنید، که حداکثر اندازه هر فایل 2 گیگابایت است. فایلها به مدت 48 ساعت ذخیره میشوند.
در طول این مدت، میتوانید از API برای دریافت فرادادههای مربوط به فایلها استفاده کنید. با این حال، نمیتوانید فایلهای آپلود شده توسط کاربر را دانلود کنید. میتوانید فایلهای تولید شده توسط مدلها، مانند ویدیوها، را با استفاده از روش files.download دانلود کنید. API فایلها در تمام مناطقی که API Gemini در دسترس است، به صورت رایگان در دسترس است.
استراتژیهای ارسال فایل
این بخش راهنماییها و بهترین شیوهها را برای استفاده از فایلهای رسانهای با اعلانهایی برای API Gemini ارائه میدهد.
امکان استفاده از انواع مختلف دادهها در درخواستهایتان، انعطافپذیری بیشتری را در مورد وظایفی که میتوانید با API Gemini انجام دهید، به شما میدهد. به عنوان مثال، میتوانید عکسی از یک غذای خوشمزه را برای مدل ارسال کنید و از او بخواهید که یک وبلاگ کوتاه در مورد آن غذا بنویسد.
| سریع | پاسخ |
یک پست وبلاگ کوتاه و جذاب بر اساس این تصویر بنویسید. این پست باید شامل توضیحی از غذای داخل عکس و نحوه آمادهسازی غذای سفر من باشد. ![]() | آماده کردن وعدههای غذایی راهی عالی برای صرفهجویی در زمان و هزینه است و همچنین میتواند به شما در داشتن تغذیه سالمتر کمک کند. این وعده غذایی نمونهای عالی از یک وعده غذایی سالم و خوشمزه است که میتوان آن را از قبل آماده کرد. این غذا شامل برنج قهوهای، سبزیجات کبابی و مرغ تِریاکی است. برنج قهوهای یک کربوهیدرات سالم و پیچیده است که به شما انرژی پایدار میدهد. سبزیجات کبابی راهی عالی برای دریافت دوز روزانه ویتامینها و مواد معدنی هستند و مرغ تِریاکی یک گزینه خوشمزه و سرشار از پروتئین است. تهیه این غذا نیز ساده است. کافیست برنج قهوهای را بپزید، سبزیجات را کباب کنید و مرغ تِریاکی را بپزید. وقتی همه چیز پخته شد، آن را در ظروف مخصوص غذا تقسیم کنید و در یخچال نگهداری کنید. سپس میتوانید یک ظرف بردارید و صبحهای پرمشغلهتان را شروع کنید! اگر به دنبال یک وعده غذایی سالم و خوشمزه هستید که بتوانید از قبل آن را آماده کنید، این غذا گزینه بسیار خوبی است. این غذا سرشار از مواد مغذی و طعم دهنده است و مطمئناً شما را سیر و راضی نگه میدارد. آمادهسازی وعدههای غذایی سالم و خوشمزه! |
اگر در دریافت خروجی مورد نظر خود از اعلانهایی که از فایلهای رسانهای استفاده میکنند، مشکل دارید، چند استراتژی وجود دارد که میتواند به شما در دستیابی به نتایج مورد نظر کمک کند. بخشهای زیر رویکردهای طراحی و نکات عیبیابی را برای بهبود اعلانهایی که از ورودی چندوجهی استفاده میکنند، ارائه میدهند.
شما میتوانید با دنبال کردن این بهترین شیوهها، پیامهای چندوجهی خود را بهبود بخشید:
اصول طراحی سریع
- در دستورالعملهای خود دقیق باشید : دستورالعملهای واضح و مختصری تهیه کنید که کمترین امکان سوء تعبیر را باقی بگذارد.
- چند مثال به سوالتان اضافه کنید: از مثالهای واقعبینانه و کوتاه برای نشان دادن آنچه میخواهید به دست آورید، استفاده کنید.
- گام به گام آن را تجزیه کنید : وظایف پیچیده را به زیر اهداف قابل مدیریت تقسیم کنید و مدل را در طول فرآیند هدایت کنید.
- قالب خروجی را مشخص کنید : در اعلان خود، فرمت خروجی مورد نظر خود را مانند Markdown، JSON، HTML و موارد دیگر درخواست کنید.
- برای درخواستهای تک تصویری، تصویر خود را در اولویت قرار دهید : اگرچه Gemini میتواند ورودیهای تصویر و متن را به هر ترتیبی مدیریت کند، اما برای درخواستهایی که شامل یک تصویر واحد هستند، اگر آن تصویر (یا ویدیو) قبل از متن قرار گیرد، ممکن است عملکرد بهتری داشته باشد. با این حال، برای درخواستهایی که برای معنادار شدن نیاز به تصاویر با متنهای زیاد دارند، از هر ترتیبی که طبیعیتر است استفاده کنید.
عیبیابی اعلان چندوجهی شما
- اگر مدل اطلاعات را از قسمت مربوط به تصویر استخراج نمیکند: با استفاده از راهنما مشخص کنید که میخواهید از کدام جنبههای تصویر، اطلاعات استخراج شود.
- اگر خروجی مدل خیلی کلی است (به اندازه کافی با ورودی تصویر/ویدئو متناسب نیست): در ابتدای درخواست، قبل از ارائه دستورالعمل کار، از مدل بخواهید تصویر(ها) یا ویدئو را توصیف کند، یا سعی کنید از مدل بخواهید به آنچه در تصویر است اشاره کند.
- برای عیبیابی اینکه کدام بخش دچار مشکل شده است: از مدل بخواهید تصویر را توصیف کند، یا از مدل بخواهید استدلال خود را توضیح دهد تا درک اولیه مدل را بسنجید.
- اگر نتیجهی درخواست شما منجر به محتوای توهمزا شد: سعی کنید تنظیمات دما را کاهش دهید یا از مدل بخواهید توضیحات کوتاهتری ارائه دهد تا احتمال تعمیم جزئیات اضافی کمتر شود.
- تنظیم پارامترهای نمونهبرداری: برای تنظیم خلاقیت مدل، تنظیمات دمایی مختلف و انتخابهای top-k را آزمایش کنید.
در دستورالعملهایتان دقیق باشید
دستورالعملها زمانی بیشترین موفقیت را دارند که واضح و با جزئیات باشند. اگر خروجی خاصی مد نظر دارید، بهتر است آن الزام را در دستورالعمل بگنجانید تا مطمئن شوید خروجی مورد نظر خود را دریافت میکنید.
برای این تصویر از تابلوی فرودگاه، درخواست از مدل برای «توصیف این تصویر» میتواند یک توصیف کلی ایجاد کند. اگر به مدل نیاز دارید که زمان و شهر را از تصویر تجزیه کند، میتوانید این درخواست را مستقیماً در اعلان خود وارد کنید.
| سریع | پاسخ مدل |
|---|---|
![]() این تصویر را توصیف کنید. | تصویر، تابلوی ورود و خروج مسافران فرودگاه را نشان میدهد. |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() زمان و شهر را از روی تابلوی فرودگاه که در این تصویر نشان داده شده است، در یک لیست تجزیه کنید. |
چند مثال اضافه کنید
مدل Gemini میتواند چندین ورودی را بپذیرد که میتواند از آنها به عنوان مثال برای درک خروجی مورد نظر شما استفاده کند. افزودن این مثالها میتواند به مدل کمک کند تا الگوها را شناسایی کرده و رابطه بین تصاویر و پاسخهای داده شده را در مثال جدید اعمال کند. به این روش یادگیری "چند مرحلهای" نیز گفته میشود.
در مثال زیر، خروجی اولیه به صورت جمله نوشته شده است و شامل کشور (برزیل) نیز میشود. فرض کنید میخواهید خروجی با فرمت یا سبک متفاوتی باشد و فقط شهر را میخواهید، نه کشور را. اضافه کردن چند مثال کوتاه به درخواست شما میتواند مدل را به سمتی هدایت کند که شما میخواهید پاسخ دهد.
| سریع | پاسخ مدل |
|---|---|
![]() شهر را به همراه نقطه عطف آن مشخص کنید. | یکی از نمادهای مهم این شهر، مجسمه مسیح منجی در ریودوژانیرو برزیل است. |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
شهر را به همراه نقطه عطف آن مشخص کنید. ![]() | شهر: رم، بنای تاریخی: کولوسئوم. |
![]() | شهر: پکن، جاذبه گردشگری: شهر ممنوعه |
![]() | شهر: ریودوژانیرو، نقطه عطف: مجسمه مسیح منجی |
گام به گام آن را تجزیه کنید
برای کارهای پیچیدهای مانند کارهایی که هم به درک بصری و هم به استدلال نیاز دارند، تقسیم کار به مراحل کوچکتر و سرراستتر میتواند مفید باشد. از طرف دیگر، اگر مستقیماً از مدل بخواهید که در سوال شما «گام به گام فکر کند» نیز میتواند مؤثر باشد.
| سریع | پاسخ مدل |
|---|---|
![]() کی دستمال توالتم تموم میشه؟ | خیلی زود، فقط ۳ رول دیگر باقی مانده است. |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]()
|
|
مسائل ریاضی یا انواع دیگر مسائل کلامی، گزینههای بسیار خوبی برای درخواست از مدل برای تفکر گام به گام هستند.
| سریع | پاسخ |
|---|---|
![]() جمله چهارم دنباله چیست؟ | -۱۳۵ |
پاسخ مدل نادرست است. یکی از راههای بهبود این مشکل این است که از مدل بخواهیم قبل از پاسخ دادن به سوال، مسئله را تجزیه و تحلیل کند.
| سریع | پاسخ |
|---|---|
![]() ابتدا فرمول موجود در تصویر را تجزیه کنید. سپس بر اساس فرمول، به سوال «جمله چهارم در دنباله چیست؟» پاسخ دهید. | برای گسترش نتیجه کلیک کنید$$ b(n) = b(n-1) * (-3) $$ $$ b(1) = 15 $$
بنابراین، جمله چهارم در این دنباله -405 است. |
این پاسخ مدل صحیح است - اکنون برای سادهتر کردن پاسخ، میتوانید از مدل بخواهید که گام به گام فکر کند.
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() جمله چهارم این دنباله چیست؟ گام به گام فکر کنید. | ترم اول ۱۵ است. جمله دوم عبارت است از b(1) * (-3) = 15 * (-3) = -45. جمله سوم عبارت است از b(2) * (-3) = -45 * (-3) = 135. جمله چهارم عبارت است از b(3) * (-3) = 135 * (-3) = -405. |
فرمت خروجی را مشخص کنید
یک مشکل رایج، نیاز به خروجی مدل در قالب خاصی (مثلاً Markdown، JSON، HTML) است، به خصوص اگر خروجی مدل نیاز به استفاده توسط یک وظیفه پاییندستی داشته باشد. میتوانید با دستور دادن به مدل برای انجام این کار در داخل اعلان، سعی کنید خروجی را در آن قالب تولید کنید. در زیر دو مثال آورده شده است:
| سریع | پاسخ مدل |
|---|---|
![]() جدول موجود در این تصویر را به فرمت Markdown تجزیه کنید | ```هیچ | موضوع | وضعیت | زمان | تاریخ شروع | مهلت تحویل | | ------- | ----- | ---- | ---------- | ----- | | ریاضی | انجام شده | ۱.۵ ساعت | ۲۹/۱۱/۲۰۲۳ | ۱/۱۲/۲۰۲۳ | | جغرافیا | انجام شده | ۳۰ دقیقه | ۲/۱۲/۲۰۲۳ | ۴/۱۲/۲۰۲۳ | | فیزیک | در حال انجام | ۲ ساعت | ۳/۱۲/۲۰۲۳ | ۵/۱۲/۲۰۲۳ | | زیست شناسی | شروع نشده | ۶ ساعت | ۲/۱۱/۲۰۱۶ | ۶/۱۲/۲۰۲۳ | ``` |
| سریع | پاسخ مدل |
|---|---|
![]() فهرستی از تمام ویژگیهای زیر ارائه دهید: مواد لازم، نوع غذا، گیاهی یا غیرگیاهی، در قالب JSON | ```json { "مواد لازم": [ "برنج"، "میگو"، "صدف"، "صدف سیاه"، "نخود فرنگی"، "گوجه فرنگی"، "پیاز"، "سیر"، "روغن زیتون"، "پاپریکا"، "نمک"، "فلفل" ]، "نوع غذا": "اسپانیایی"، "گیاهخواری": false } ``` |
برای درخواستهای تکتصویری، تصویر خود را در اولویت قرار دهید
اگرچه Gemini میتواند تصویر و متن را به هر ترتیبی در یک اعلان تفسیر کند، قرار دادن یک تصویر واحد قبل از اعلان متنی ممکن است منجر به نتایج بهتری شود. در نمونههای زیر، متوجه خواهید شد که تصویر در هر اعلان قبل از متن قرار میگیرد.
عیبیابی اعلان چندوجهی شما
اگر پاسخ مفیدی دریافت نمیکنید، ممکن است لازم باشد مشکل درخواست خود را عیبیابی کنید. در اینجا چند استراتژی وجود دارد که میتوانید امتحان کنید.
اگر مدل اطلاعات را از قسمت مربوط به تصویر ترسیم نمیکند
برای دریافت پاسخ دقیقتر، میتوانید مشخص کنید که میخواهید سوال از کدام جنبههای تصویر برای ارائه پاسخ استفاده کند.
| سریع | پاسخ مدل |
|---|---|
![]() این پوشکها برای چند روز برای نوزاد کافی هستند؟ | این پوشکها تا ۱۹۸ روز دوام میآورند و بعد تمام میشوند. |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() این پوشکها قبل از اینکه تمام شوند، چقدر دوام میآورند؟ از وزن نشان داده شده روی جعبه برای تعیین سن کودک استفاده کنید و تعداد کل پوشکهای موجود در جعبه را در نظر بگیرید. عدد کل را بر تعداد پوشکهایی که کودک در روز استفاده میکند تقسیم کنید. | این جعبه حاوی ۱۹۸ پوشک است. روی جعبه ذکر شده که این پوشکها برای کودکی با وزن ۲۲ تا ۳۷ پوند (حدود ۱۰ تا ۱۲ کیلوگرم) مناسب هستند. کودک متوسط در این محدوده وزنی احتمالاً بین ۱ تا ۲ سال سن دارد. یک کودک ۲ ساله معمولاً روزانه ۶ پوشک عوض میکند، بنابراین، پوشکها حدود ۳۳ روز (۱۹۸/۶) دوام میآورند. |
اگر خروجی مدل بیش از حد عمومی باشد و به اندازه کافی با ورودی تصویر متناسب نباشد
برای کمک به مدل در تنظیم پاسخ خود به تصویر(ها)، سعی کنید قبل از انجام وظیفه استدلال، از آن بخواهید تصاویر را توصیف کند.
| سریع | پاسخ مدل |
|---|---|
![]() ![]() ![]() ![]() چه وجه مشترکی بین این تصاویر وجود دارد؟ | هر چهار تصویر نمونههایی از عکاسی منظره هستند. |
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() ![]() ![]() ![]() ابتدا، آنچه در هر تصویر وجود دارد را با جزئیات شرح دهید. چه چیزی بین این تصاویر مشترک است؟ | تصویر اول شخصی را نشان میدهد که در حال بستن چمدان است. تصویر دوم یک راهروی خالی در یک مرکز خرید را نشان میدهد. تصویر سوم یک رول دستمال توالت را نشان میدهد. تصویر چهارم دریایی تاریک و طوفانی را نشان میدهد. وجه مشترک این تصاویر این است که همه آنها نمونههایی از فضاهای آستانهای هستند. فضاهای آستانهای مکانها یا موقعیتهایی هستند که بین دو مکان یا موقعیت دیگر قرار دارند. آنها اغلب با حس عدم قطعیت یا ابهام مشخص میشوند. تصویر اول، فردی را نشان میدهد که بین خانه و سفر قرار دارد. تصویر دوم راهروی بین دو فروشگاه را نشان میدهد. تصویر سوم دستمال توالت است که میتواند نمایانگر حمام باشد. حمام یک فضای انتقالی بین قلمروهای خصوصی و عمومی است. جایی است که ما خود را برای ورود یا خروج از دنیای بیرون آماده میکنیم. تصویر چهارم دریا را در حالتی بین آرام و طوفانی نشان میدهد. فضاهای آستانهای میتوانند هم هیجانانگیز و هم نگرانکننده باشند. آنها میتوانند مکانی برای شروعهای جدید یا مکانی برای پایانها باشند. آنها میتوانند مکانی برای تأمل یا مکانی برای عمل باشند. |
همچنین میتوانید صریحاً از مدل بخواهید که به آنچه در تصویر است اشاره کند.
| اعلان بهروزرسانیشده | پاسخ بهبود یافته |
|---|---|
![]() ![]() ![]() ![]() چه وجه مشترکی بین این تصاویر وجود دارد؟ در پاسخ خود به آنچه در تصاویر وجود دارد اشاره کنید. | همه تصاویر مربوط به سفر هستند. تصویر اول شخصی را در حال بستن چمدان نشان میدهد، تصویر دوم راهروی خالی یک مرکز خرید را نشان میدهد، تصویر سوم یک دسته دستمال توالت را نشان میدهد و تصویر چهارم دریایی تاریک و طوفانی را نشان میدهد. این تصاویر همگی مربوط به سفر هستند، زیرا همگی چیزهایی هستند که مردم هنگام سفر به آنها نیاز دارند یا از آنها استفاده میکنند. تصویر اول شخصی را نشان میدهد که در حال بستن چمدان است، کاری که مردم هنگام رفتن به سفر انجام میدهند. تصویر دوم یک راهروی خالی در یک مرکز خرید را نشان میدهد، جایی که مردم اغلب برای خرید وسایل سفر خود به آنجا میروند. تصویر سوم یک دسته دستمال توالت را نشان میدهد، چیزی که مردم اغلب هنگام سفر از آن استفاده میکنند. تصویر چهارم دریایی تاریک و طوفانی را نشان میدهد، چیزی که مردم اغلب هنگام سفر با آن مواجه میشوند. |
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.
| سریع | Model response |
|---|---|
![]() Can you write me a poem about this image? | Little bunny, so soft and brown, You nibble on the grass, so green and sweet, |
| 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, Is it the ocean blue, Little bunny, tell me true, Perhaps it's the vastness of it all, Little bunny, I wonder what you dream, Whatever it may be, little bunny, |
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 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 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. |
قدم بعدی چیست؟
- سعی کنید با استفاده از 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.
آپلود فایل
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 interactions.create .
پایتون
from google import genai
client = genai.Client()
myfile = client.files.upload(file="path/to/sample.mp3")
interaction = client.interactions.create(
model="gemini-3.8-flash",
input=[
{"type": "text", "text": "Describe this audio clip"},
{"type": "audio", "uri": myfile.uri, "mime_type": myfile.mime_type}
]
)
print(interaction.output_text)
جاوا اسکریپت
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const interaction = await client.interactions.create({
model: "gemini-3.8-flash",
input: [
{ type: "text", text: "Describe this audio clip" },
{ type: "audio", uri: myfile.uri, mime_type: myfile.mimeType }
]
});
console.log(interaction.output_text);
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
log.Fatal(err)
}
defer client.Files.Delete(ctx, file.Name)
interaction, err := client.Interactions.Create(ctx, "gemini-3.8-flash", &genai.InteractionRequest{
Input: []interface{}{
genai.NewPartFromFile(*file),
genai.NewPartFromText("Describe this audio clip"),
},
}, nil)
if err != nil {
log.Fatal(err)
}
// Print the model's text response
for _, step := range interaction.Steps {
if step.Type == "model_output" {
for _, part := range step.Content {
if part.Type == "text" {
fmt.Println(part.Text)
}
}
}
}
استراحت
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 create an interaction using the Interactions API
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3.8-flash",
"input": [
{"type": "text", "text": "Describe this audio clip"},
{"type": "audio", "uri": '$file_uri', "mime_type": "'${MIME_TYPE}'"}
]
}' 2> /dev/null > response.json
cat response.json
echo
jq ".outputs[] | select(.type == \"text\") | .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 .
پایتون
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)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const fileName = myfile.name;
const fetchedFile = await client.files.get({ name: fileName });
console.log(fetchedFile);
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
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)
استراحت
# file_info.json was created in the upload example
name=$(jq -r ".file.name" file_info.json)
# Get the file of interest to check state
curl https://generativelanguage.googleapis.com/v1beta/$name \
-H "x-goog-api-key: $GEMINI_API_KEY" > file_info.json
# Print some information about the file you got
name=$(jq -r ".name" file_info.json)
echo name=$name
file_uri=$(jq -r ".uri" file_info.json)
echo file_uri=$file_uri
List uploaded files
The following code gets a list of all the files uploaded:
پایتون
from google import genai
client = genai.Client()
print('My files:')
for f in client.files.list():
print(' ', f.name)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const listResponse = await client.files.list({ config: { pageSize: 10 } });
for await (const file of listResponse) {
console.log(file.name);
}
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
for file, err := range client.Files.All(ctx) {
if err != nil {
log.Fatal(err)
}
fmt.Println(file.Name)
}
استراحت
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:
پایتون
from google import genai
client = genai.Client()
myfile = client.files.upload(file='path/to/sample.mp3')
client.files.delete(name=myfile.name)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const fileName = myfile.name;
await client.files.delete({ name: fileName });
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
log.Fatal(err)
}
client.Files.Delete(ctx, file.Name)
استراحت
curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/$name \
-H "x-goog-api-key: $GEMINI_API_KEY"
اطلاعات استفاده
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.
| سریع | پاسخ |
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. ![]() | Meal prepping is a great way to save time and money, and it can also help you to eat healthier. This meal is a great example of a healthy and delicious meal that can be prepped ahead of time. This meal features brown rice, roasted vegetables, and chicken teriyaki. The brown rice is a healthy and complex carbohydrate that will give you sustained energy. The roasted vegetables are a great way to get your daily dose of vitamins and minerals, and the chicken teriyaki is a delicious and protein-rich option. This meal is also straightforward to prepare. Simply cook the brown rice, roast the vegetables, and cook the chicken teriyaki. Once everything is cooked, divide it into meal prep containers and store them in the refrigerator. You can then grab a container and go on busy mornings! If you're looking for a healthy and delicious meal that can be prepped ahead of time, this meal is a great option. It's packed with nutrients and flavor, and it's sure to keep you feeling full and satisfied. Here's to healthy and delicious meal prepping! |
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.
| سریع | Model response |
|---|---|
![]() Describe this image. | The image shows an airport arrivals and departures board. |
| Updated prompt | Improved response |
|---|---|
![]() Parse the time and city from the airport board shown in this image into a list. |
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 following example, 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.
| سریع | Model response |
|---|---|
![]() 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. ![]() | city: Rome, landmark: the Colosseum. |
![]() | city: Beijing, landmark: 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.
| سریع | Model response |
|---|---|
![]() When will I run out of toilet paper? | Soon, you only have 3 rolls left. |
| Updated prompt | Improved response |
|---|---|
![]()
|
|
Math problems or other types of word problems are great candidates for asking the model to think step-by-step.
| سریع | پاسخ |
|---|---|
![]() What is the 4th term in the sequence? | -۱۳۵ |
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.
| سریع | پاسخ |
|---|---|
![]() 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 $$
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. The following are two examples:
| سریع | Model response |
|---|---|
![]() Parse the table in this image into Markdown format | ```none | Subject | Status | Time | Start date | Due on | | ------- | ------ | ---- | ---------- | ------ | | Math | Done | 1.5 hrs | 11/29/2023 | 12/1/2023 | | Geography | Done | 30 min | 12/2/2023 | 12/4/2023 | | Physics | In progress | 2 hrs | 12/3/2023 | 12/5/2023 | | Biology | Not started | 6 hrs | 11/2/2016 | 12/6/2023 | ``` |
| سریع | 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.
| سریع | 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.
| سریع | 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.
| سریع | Model response |
|---|---|
![]() Can you write me a poem about this image? | Little bunny, so soft and brown, You nibble on the grass, so green and sweet, |
| 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, Is it the ocean blue, Little bunny, tell me true, Perhaps it's the vastness of it all, Little bunny, I wonder what you dream, Whatever it may be, little bunny, |
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 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 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. |
قدم بعدی چیست؟
- سعی کنید با استفاده از 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.
آپلود فایل
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 interactions.create .
پایتون
from google import genai
client = genai.Client()
myfile = client.files.upload(file="path/to/sample.mp3")
interaction = client.interactions.create(
model="gemini-3.8-flash",
input=[
{"type": "text", "text": "Describe this audio clip"},
{"type": "audio", "uri": myfile.uri, "mime_type": myfile.mime_type}
]
)
print(interaction.output_text)
جاوا اسکریپت
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const interaction = await client.interactions.create({
model: "gemini-3.8-flash",
input: [
{ type: "text", text: "Describe this audio clip" },
{ type: "audio", uri: myfile.uri, mime_type: myfile.mimeType }
]
});
console.log(interaction.output_text);
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
log.Fatal(err)
}
defer client.Files.Delete(ctx, file.Name)
interaction, err := client.Interactions.Create(ctx, "gemini-3.8-flash", &genai.InteractionRequest{
Input: []interface{}{
genai.NewPartFromFile(*file),
genai.NewPartFromText("Describe this audio clip"),
},
}, nil)
if err != nil {
log.Fatal(err)
}
// Print the model's text response
for _, step := range interaction.Steps {
if step.Type == "model_output" {
for _, part := range step.Content {
if part.Type == "text" {
fmt.Println(part.Text)
}
}
}
}
استراحت
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 create an interaction using the Interactions API
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3.8-flash",
"input": [
{"type": "text", "text": "Describe this audio clip"},
{"type": "audio", "uri": '$file_uri', "mime_type": "'${MIME_TYPE}'"}
]
}' 2> /dev/null > response.json
cat response.json
echo
jq ".outputs[] | select(.type == \"text\") | .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 .
پایتون
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)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const fileName = myfile.name;
const fetchedFile = await client.files.get({ name: fileName });
console.log(fetchedFile);
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
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)
استراحت
# file_info.json was created in the upload example
name=$(jq -r ".file.name" file_info.json)
# Get the file of interest to check state
curl https://generativelanguage.googleapis.com/v1beta/$name \
-H "x-goog-api-key: $GEMINI_API_KEY" > file_info.json
# Print some information about the file you got
name=$(jq -r ".name" file_info.json)
echo name=$name
file_uri=$(jq -r ".uri" file_info.json)
echo file_uri=$file_uri
List uploaded files
The following code gets a list of all the files uploaded:
پایتون
from google import genai
client = genai.Client()
print('My files:')
for f in client.files.list():
print(' ', f.name)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const listResponse = await client.files.list({ config: { pageSize: 10 } });
for await (const file of listResponse) {
console.log(file.name);
}
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
for file, err := range client.Files.All(ctx) {
if err != nil {
log.Fatal(err)
}
fmt.Println(file.Name)
}
استراحت
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:
پایتون
from google import genai
client = genai.Client()
myfile = client.files.upload(file='path/to/sample.mp3')
client.files.delete(name=myfile.name)
جاوا اسکریپت
import {
GoogleGenAI,
} from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const myfile = await client.files.upload({
file: "path/to/sample.mp3",
config: { mime_type: "audio/mpeg" },
});
const fileName = myfile.name;
await client.files.delete({ name: fileName });
}
await main();
جاوا
import com.google.genai.Client;
import com.google.genai.types.File;
import com.google.genai.types.UploadFileConfig;
Client client = new Client();
File file = client.files.upload(
new java.io.File("path/to/sample.txt"),
UploadFileConfig.builder().mimeType("text/plain").build()
);
System.out.println("Uploaded file URI: " + file.uri().orElse(""));
برو
file, err := client.Files.UploadFromPath(ctx, "path/to/sample.mp3", nil)
if err != nil {
log.Fatal(err)
}
client.Files.Delete(ctx, file.Name)
استراحت
curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/$name \
-H "x-goog-api-key: $GEMINI_API_KEY"
اطلاعات استفاده
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.
| سریع | پاسخ |
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. ![]() | Meal prepping is a great way to save time and money, and it can also help you to eat healthier. This meal is a great example of a healthy and delicious meal that can be prepped ahead of time. This meal features brown rice, roasted vegetables, and chicken teriyaki. The brown rice is a healthy and complex carbohydrate that will give you sustained energy. The roasted vegetables are a great way to get your daily dose of vitamins and minerals, and the chicken teriyaki is a delicious and protein-rich option. This meal is also straightforward to prepare. Simply cook the brown rice, roast the vegetables, and cook the chicken teriyaki. Once everything is cooked, divide it into meal prep containers and store them in the refrigerator. You can then grab a container and go on busy mornings! If you're looking for a healthy and delicious meal that can be prepped ahead of time, this meal is a great option. It's packed with nutrients and flavor, and it's sure to keep you feeling full and satisfied. Here's to healthy and delicious meal prepping! |
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.
| سریع | Model response |
|---|---|
![]() Describe this image. | The image shows an airport arrivals and departures board. |
| Updated prompt | Improved response |
|---|---|
![]() Parse the time and city from the airport board shown in this image into a list. |
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 following example, 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.
| سریع | Model response |
|---|---|
![]() 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. ![]() | city: Rome, landmark: the Colosseum. |
![]() | city: Beijing, landmark: 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.
| سریع | Model response |
|---|---|
![]() When will I run out of toilet paper? | Soon, you only have 3 rolls left. |
| Updated prompt | Improved response |
|---|---|
![]()
|
|
Math problems or other types of word problems are great candidates for asking the model to think step-by-step.
| سریع | پاسخ |
|---|---|
![]() What is the 4th term in the sequence? | -۱۳۵ |
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.
| سریع | پاسخ |
|---|---|
![]() 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 $$
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. The following are two examples:
| سریع | Model response |
|---|---|
![]() Parse the table in this image into Markdown format | ```none | Subject | Status | Time | Start date | Due on | | ------- | ------ | ---- | ---------- | ------ | | Math | Done | 1.5 hrs | 11/29/2023 | 12/1/2023 | | Geography | Done | 30 min | 12/2/2023 | 12/4/2023 | | Physics | In progress | 2 hrs | 12/3/2023 | 12/5/2023 | | Biology | Not started | 6 hrs | 11/2/2016 | 12/6/2023 | ``` |
| سریع | 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.
| سریع | 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.
| سریع | 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.
| سریع | Model response |
|---|---|
![]() Can you write me a poem about this image? | Little bunny, so soft and brown, You nibble on the grass, so green and sweet, |
| 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, Is it the ocean blue, Little bunny, tell me true, Perhaps it's the vastness of it all, Little bunny, I wonder what you dream, Whatever it may be, little bunny, |
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 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 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. |
قدم بعدی چیست؟
- سعی کنید با استفاده از 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.














