درحال فکر کردن

همه مدل‌های Gemini جدید از «فرایند فکری» داخلی استفاده می‌کنند که توانایی‌های استدلال و برنامه‌ریزی چندمرحله‌ای آن‌ها را به‌طور قابل‌توجهی بهبود می‌بخشد و آن‌ها را برای تکلیف‌های پیچیده مثل کدنویسی، ریاضیات پیشرفته، و تحلیل داده‌ها بسیار مؤثر می‌کند.

مدل‌های «اندیشگر» پیکربندی‌ها و گزینه‌های زیر را ارائه می‌دهند:

  • کنترل مقدار تفکر
    می‌توانید پیکربندی کنید که مدل چقدر «فکر» کند. این پیکربندی به‌ویژه اگر کاهش تأخیر یا هزینه در اولویت باشد مهم است. همچنین، برای تصمیم‌گیری درباره اینکه یک مدل چقدر به قابلیت تفکر خود نیاز دارد، مقایسه دشواری‌های تکلیف را بررسی کنید.

    این پیکربندی را با سطوح اندیشگر (مدل‌های Gemini 3.x و جدیدتر) یا با بودجه‌های اندیشگر (مدل‌های Gemini 2.5) کنترل کنید.

  • دریافت خلاصه افکار
    می‌توانید خلاصه افکار را فعال کنید تا به پاسخ تولیدشده اضافه شود. این خلاصه‌ها نسخه‌های ترکیبی از افکار خام مدل هستند و اطلاعات آماری درباره فرایند استدلال داخلی مدل ارائه می‌دهند.

  • مدیریت امضاهای فکر
    Firebase AI Logic کیت‌های توسعه نرم‌افزار به‌طور خودکار امضاهای فکر را برای شما مدیریت می‌کنند، که تضمین می‌کند مدل به بافت فکر از نوبت‌های قبلی دسترسی داشته باشد، به‌ویژه هنگام استفاده از فراخوانی تابع.

حتماً روال‌های مطلوب و راهنمایی‌های پیام‌واره را برای استفاده از مدل‌های تفکر مرور کنید.



روال‌های مطلوب و راهنمایی برای استفاده از مدل‌های اندیشگر

توصیه می‌کنیم پیام‌واره‌تان را در Google AI Studio یا Agent  Studio آزمایش کنید، در این مکان‌ها می‌توانید فرایند کامل فکر کردن را ببینید. می‌توانید هر ناحیه‌ای را که مدل ممکن است در آن اشتباه کرده باشد شناسایی کنید تا بتوانید پیام‌واره‌هایتان را پالایش کنید و پاسخ‌های دقیق‌تر و یکنواخت‌تری دریافت کنید.

با پیام‌واره‌ای کلی که نتیجه مطلوب را توصیف می‌کند شروع کنید و افکار اولیه مدل درباره نحوه تعیین پاسخ خود را مشاهده کنید. اگر پاسخ آن‌طور که انتظار می‌رود نیست، بااستفاده از هریک از تکنیک‌های پیام‌واره‌نویسی زیر به مدل کمک کنید پاسخ بهتری تولید کند:

  • ارائه دستورالعمل‌های گام‌به‌گام
  • چندین مثال از جفت‌های ورودی-خروجی ارائه دهید
  • راهنمایی‌هایی درباره نحوه عبارت‌بندی و قالب‌بندی برونداد و پاسخ‌ها ارائه دهید
  • ارائه مراحل درستی‌سنجی خاص

علاوه‌بر پیام‌واره، از این توصیه‌ها نیز استفاده کنید:

  • دستورالعمل‌های سیستم را تنظیم کنید، که مانند «مقدمه‌ای» است که قبل‌از اینکه مدل درمعرض هرگونه دستورالعمل دیگری از پیام‌واره یا کاربر نهایی قرار گیرد اضافه می‌کنید. این پارامترها به شما امکان می‌دهند رفتار مدل را براساس نیازها و موارد استفاده خاص خود هدایت کنید.

  • سطح تفکر (یا بودجه تفکر برای مدل‌های Gemini 2.5) تنظیم کنید تا میزان تفکری که مدل می‌تواند انجام دهد را کنترل کنید. اگر آن را بالا تنظیم کنید، درصورت نیاز مدل می‌تواند بیشتر فکر کند. اگر آن را پایین‌تر تنظیم کنید، مدل در پاسخ خود «زیاد فکر نمی‌کند» و همچنین بخش بیشتری از حد مجاز کل برونداد نشان را برای پاسخ واقعی رزرو می‌کند و می‌تواند به کاهش تأخیر و هزینه کمک کند.

  • برای پایش تعداد نشانه‌های فکر کردن و تأخیر درخواست‌هایتان که فکر کردن در آن‌ها فعال است، پایش هوش مصنوعی را در کنسول Firebase فعال کنید. و اگر خلاصه‌های فکری را فعال کرده باشید، در کنسول نمایش داده می‌شوند و می‌توانید استدلال دقیق مدل را بررسی کنید تا به شما در اشکال‌زدایی و پالایش پیام‌واره‌هایتان کمک کند.



کنترل میزان تفکر

می‌توانید پیکربندی کنید که مدل قبل‌از برگرداندن پاسخ چقدر «فکر» و استدلال کند. این پیکربندی به‌ویژه اگر کاهش تأخیر یا هزینه در اولویت باشد مهم است.

حتماً مقایسه دشواری‌های تکلیف را بررسی کنید تا تصمیم بگیرید یک مدل چقدر ممکن است به قابلیت تفکر خود نیاز داشته باشد. در اینجا چند راهنمایی سطح بالا ارائه شده است:

  • برای کارهای کمتر پیچیده یا اگر کاهش تأخیر یا هزینه برایتان در اولویت است، مقدار تفکر پایین‌تری تنظیم کنید.
  • برای تکالیف پیچیده‌تر، مقدار تفکر بالاتری تنظیم کنید.

این پیکربندی را با سطوح اندیشگر (مدل‌های Gemini 3.x و جدیدتر) یا با بودجه‌های اندیشگر (مدل‌های Gemini 2.5) کنترل کنید.

سطوح اندیشیدن (مدل‌های Gemini 3.x و جدیدتر)

برای کنترل میزان تفکری که مدل Gemini 3.x و مدل‌های جدیدتر می‌توانند برای تولید پاسخ خود انجام دهند، می‌توانید سطح تفکر را برای مقدار نشانه‌های تفکری که مجاز به استفاده از آن‌ها است مشخص کنید.

سطح اندیشیدن را تنظیم کنید

روی ارائه‌دهنده Gemini API خود کلیک کنید تا محتوا و کد مخصوص ارائه‌دهنده را در این صفحه مشاهده کنید.

سطح تفکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید. پیکربندی برای طول عمر نمونه حفظ می‌شود. اگر می‌خواهید برای درخواست‌های مختلف از سطوح تفکر متفاوتی استفاده کنید، GenerativeModel نمونه پیکربندی‌شده با هر سطح ایجاد کنید.

در ادامه این بخش، درباره مقادیر پشتیبانی‌شده برای سطح تفکر بیشتر بدانید.

Swift

سطح اندیشیدن را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

// Set the thinking configuration.
// Use a thinking level value appropriate for your model (example value shown here).
let generationConfig = GenerationConfig(
  thinkingConfig: ThinkingConfig(thinkingLevel: .low)
)

// Specify the config as part of creating the `GenerativeModel` instance.
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
  modelName: "GEMINI_3.x_MODEL_NAME",
  generationConfig: generationConfig
)

// ...

Kotlin

مقادیر پارامترها را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

// Set the thinking configuration.
// Use a thinking level value appropriate for your model (example value shown here).
val generationConfig = generationConfig {
  thinkingConfig = thinkingConfig {
      thinkingLevel = ThinkingLevel.LOW
  }
}

// Specify the config as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
  modelName = "GEMINI_3.x_MODEL_NAME",
  generationConfig,
)

// ...

Java

مقادیر پارامترها را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

// Set the thinking configuration.
// Use a thinking level value appropriate for your model (example value shown here).
ThinkingConfig thinkingConfig = new ThinkingConfig.Builder()
    .setThinkingLevel(ThinkingLevel.LOW)
    .build();

GenerationConfig generationConfig = GenerationConfig.builder()
    .setThinkingConfig(thinkingConfig)
    .build();

// Specify the config as part of creating the `GenerativeModel` instance.
GenerativeModelFutures model = GenerativeModelFutures.from(
        FirebaseAI.getInstance(GenerativeBackend.googleAI())
                .generativeModel(
                  /* modelName */ "GEMINI_3.x_MODEL_NAME",
                  /* generationConfig */ generationConfig
                );
);

// ...

Web

مقادیر پارامترها را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Set the thinking configuration.
// Use a thinking level value appropriate for your model (example value shown here).
const generationConfig = {
  thinkingConfig: {
    thinkingLevel: ThinkingLevel.LOW
  }
};

// Specify the config as part of creating the `GenerativeModel` instance.
const model = getGenerativeModel(ai, { model: "GEMINI_3.x_MODEL_NAME", generationConfig });

// ...

Dart

مقادیر پارامترها را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

// Set the thinking configuration.
// Use a thinking level value appropriate for your model (example value shown here).
final thinkingConfig = ThinkingConfig.withThinkingLevel(ThinkingLevel.low);

final generationConfig = GenerationConfig(
  thinkingConfig: thinkingConfig
);

// Specify the config as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.googleAI().generativeModel(
  model: 'GEMINI_3.x_MODEL_NAME',
  config: generationConfig,
);

// ...

Unity

مقادیر پارامترها را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

// Set the thinking configuration.
// Use a thinking level value appropriate for your model (example value shown here).
var thinkingConfig = new ThinkingConfig(thinkingLevel: ThinkingLevel.Low);

var generationConfig = new GenerationConfig(
  thinkingConfig: thinkingConfig
);

// Specify the config as part of creating the `GenerativeModel` instance.
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
  modelName: "GEMINI_3.x_MODEL_NAME",
  generationConfig: generationConfig
);

// ...

مقادیر سطح اندیشگر پشتیبانی‌شده

جدول زیر مقادیر سطح تفکری را که می‌توانید برای هر مدل با پیکربندی مدل thinkingLevel تنظیم کنید فهرست می‌کند.

MINIMAL LOW MEDIUM HIGH

مدل از کمترین تعداد نشان ممکن استفاده می‌کند؛ تقریباً بدون فکر کردن

تکالیف با پیچیدگی پایین

مدل از نشانه‌های کمتری استفاده می‌کند؛ تأخیر و هزینه را به حداقل می‌رساند

تکالیف ساده و تکالیف با توان عملیاتی بالا

مدل از رویکردی متعادل استفاده می‌کند

تکالیف با پیچیدگی متوسط

مدل از نشانه‌ها تا حداکثر سطح خود استفاده می‌کند

پیام‌واره‌های پیچیده‌ای که به استدلال عمیق نیاز دارند

Gemini 3.x Pro
gemini-3.1-pro-preview
(پیش‌فرض)
Gemini 3.x Flash
gemini-3.8-flash
gemini-3.7-flash
gemini-3.6-flash
gemini-3.5-flash

توسط gemini-3.8-flash یا gemini-3.7-flash 1 پشتیبانی نمی‌شود
(پیش‌فرض)
Gemini 3.x Flash‑Lite
gemini-3.5-flash-lite
gemini-3.1-flash-lite
(پیش‌فرض)
Gemini 3.x Pro Image
gemini-3-pro-image
("Nano Banana Pro")
(پیش‌فرض)
Gemini 3.x Flash Image
gemini-3.1-flash-image
‏("Nano Banana 2")
(پیش‌فرض)
Gemini 3.x Flash‑Lite Image
gemini-3.1-flash-lite-image
(«Nano Banana 2 Lite»)
(پیش‌فرض)

۱ gemini-3.8-flash و gemini-3.7-flash از سطح تفکر MINIMAL پشتیبانی نمی‌کنند. اگر سطح تفکر را روی MINIMAL تنظیم کنید، درخواست با خطای ۴۰۰ ناموفق خواهد بود.



درحال فکر کردن درباره بودجه‌ها (Gemini 2.5 مدل)

برای کنترل میزان تفکری که مدل Gemini 2.5 می‌تواند برای تولید پاسخ خود انجام دهد، می‌توانید بودجه تفکر را برای مقدار نشانه‌های تفکری که مجاز به استفاده از آن‌ها است مشخص کنید.

تنظیم بودجه تفکر

روی ارائه‌دهنده Gemini API خود کلیک کنید تا محتوا و کد مخصوص ارائه‌دهنده را در این صفحه مشاهده کنید.

بودجه اندیشیدن را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel برای مدل Gemini 2.5 تنظیم کنید. پیکربندی برای طول عمر نمونه حفظ می‌شود. اگر می‌خواهید از بودجه‌های تفکر متفاوت برای درخواست‌های مختلف استفاده کنید، GenerativeModel نمونه پیکربندی‌شده با هر بودجه ایجاد کنید.

در ادامه این بخش، درباره مقادیر پشتیبانی‌شده برای بودجه فکری بیشتر بدانید.

Swift

بودجه تفکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

// Set the thinking configuration.
// Use a thinking budget value appropriate for your model (example value shown here).
let generationConfig = GenerationConfig(
  thinkingConfig: ThinkingConfig(thinkingBudget: 1024)
)

// Specify the config as part of creating the `GenerativeModel` instance.
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
  modelName: "GEMINI_2.5_MODEL_NAME",
  generationConfig: generationConfig
)

// ...

Kotlin

مقادیر پارامترها را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

// Set the thinking configuration.
// Use a thinking budget value appropriate for your model (example value shown here).
val generationConfig = generationConfig {
  thinkingConfig = thinkingConfig {
      thinkingBudget = 1024
  }
}

// Specify the config as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
  modelName = "GEMINI_2.5_MODEL_NAME",
  generationConfig,
)

// ...

Java

مقادیر پارامترها را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

// Set the thinking configuration.
// Use a thinking budget value appropriate for your model (example value shown here).
ThinkingConfig thinkingConfig = new ThinkingConfig.Builder()
    .setThinkingBudget(1024)
    .build();

GenerationConfig generationConfig = GenerationConfig.builder()
    .setThinkingConfig(thinkingConfig)
    .build();

// Specify the config as part of creating the `GenerativeModel` instance.
GenerativeModelFutures model = GenerativeModelFutures.from(
        FirebaseAI.getInstance(GenerativeBackend.googleAI())
                .generativeModel(
                  /* modelName */ "GEMINI_2.5_MODEL_NAME",
                  /* generationConfig */ generationConfig
                );
);

// ...

Web

مقادیر پارامترها را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Set the thinking configuration.
// Use a thinking budget value appropriate for your model (example value shown here).
const generationConfig = {
  thinkingConfig: {
    thinkingBudget: 1024
  }
};

// Specify the config as part of creating the `GenerativeModel` instance.
const model = getGenerativeModel(ai, { model: "GEMINI_2.5_MODEL_NAME", generationConfig });

// ...

Dart

مقادیر پارامترها را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

// Set the thinking configuration.
// Use a thinking budget value appropriate for your model (example value shown here).
final thinkingConfig = ThinkingConfig.withThinkingBudget(1024);

final generationConfig = GenerationConfig(
  thinkingConfig: thinkingConfig
);

// Specify the config as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.googleAI().generativeModel(
  model: 'GEMINI_2.5_MODEL_NAME',
  config: generationConfig,
);

// ...

Unity

مقادیر پارامترها را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel تنظیم کنید.


// ...

// Set the thinking configuration.
// Use a thinking budget value appropriate for your model (example value shown here).
var thinkingConfig = new ThinkingConfig(thinkingBudget: 1024);

var generationConfig = new GenerationConfig(
  thinkingConfig: thinkingConfig
);

// Specify the config as part of creating the `GenerativeModel` instance.
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
  modelName: "GEMINI_2.5_MODEL_NAME",
  generationConfig: generationConfig
);

// ...

مقادیر بودجه فکری پشتیبانی‌شده

جدول زیر مقادیر بودجه تفکر را که می‌توانید برای هر مدل با پیکربندی thinkingBudget مدل تنظیم کنید فهرست می‌کند.

مدل مقدار پیش‌فرض محدوده دردسترس برای بودجه اندیشگر مقدار برای
غیرفعال کردن فکر کردن
مقدار برای
فعال کردن تفکر پویا
حداقل مقدار بیشترین مقدار
Gemini 2.5 Pro 8,192 128 32,768 غیرفعال نمی‌شود -1
Gemini 2.5 Flash 8,192 1 24,576 0 -1
Gemini 2.5 Flash‑Lite 0
(به‌طور پیش‌فرض، فکر کردن غیرفعال است)
512 24,576 0
(یا اصلاً بودجه فکری را پیکربندی نکنید)
-1



پیچیدگی تکلیف برای همه مدل‌های اندیشگر

  • تکالیف آسان — فکر کردن چندان ضروری نیست
    درخواست‌های ساده که در آن‌ها استدلال پیچیده لازم نیست، مثل بازیابی یا طبقه‌بندی حقایق. مثال‌ها:

    • «DeepMind کجا تأسیس شد؟»
    • «آیا این ایمیل درخواست جلسه می‌کند یا فقط اطلاعات ارائه می‌دهد؟»
  • تکالیف متوسط — احتمالاً به مقداری فکر کردن نیاز است
    درخواست‌های رایجی که از پردازش گام‌به‌گام یا درک عمیق‌تر بهره می‌برند. مثال‌ها:

    • «بین فتوسنتز و بزرگ شدن قیاس ایجاد کن.»
    • «مقایسه و هم‌سنجی خودروهای برقی و خودروهای هیبریدی.»
  • تکالیف دشوار — ممکن است نیاز به حداکثر تفکر باشد
    چالش‌های واقعاً پیچیده، مانند حل مسائل پیچیده ریاضی یا تکالیف کدنویسی. این نوع تکالیف نیازمند این است که مدل از تمام توانایی‌های استدلال و برنامه‌ریزی خود استفاده کند، و اغلب شامل مراحل داخلی زیادی قبل‌از ارائه پاسخ است. مثال‌ها:

    • «مسئله ۱ در AIME 2025 را حل کن: مجموع همه پایه‌های صحیح b > 9 را پیدا کن که برای آن‌ها 17b مقسوم 97b است.»
    • «برای یک برنامه وب که داده‌های بازار سهام را به‌صورت هم‌زمان به‌تصویر می‌کشد، ازجمله اصالت‌سنجی کاربر، کد پایتون بنویس. تا حد امکان کارآمد باشد.»



خلاصه‌های فکر

خلاصه‌های فکر نسخه‌های ترکیبی از افکار خام مدل هستند و اطلاعات آماری درباره فرایند استدلال داخلی مدل ارائه می‌دهند.

در اینجا چند دلیل برای افزودن خلاصه افکار در پاسخ‌ها آورده شده است:

  • می‌توانید خلاصه فکر را در واسط کاربر برنامه‌تان نمایش دهید یا آن را برای کاربران دردسترس قرار دهید. خلاصه فکر به‌عنوان بخشی جداگانه در پاسخ برگردانده می‌شود تا کنترل بیشتری بر نحوه استفاده از آن در برنامه‌تان داشته باشید.

  • اگر پایش هوش مصنوعی را در کنسول Firebase نیز فعال کنید، خلاصه‌های فکر در کنسول نمایش داده می‌شود و می‌توانید استدلال دقیق مدل را بررسی کنید تا به شما در اشکال‌زدایی و پالایش پیام‌واره‌هایتان کمک کند.

در اینجا چند نکته کلیدی درباره خلاصه افکار آورده شده است:

  • خلاصه‌های فکر تحت کنترل بودجه‌های فکری نیستند (بودجه‌ها فقط برای افکار خام مدل اعمال می‌شوند). بااین‌حال، اگر تفکر غیرفعال باشد، مدل خلاصه فکری برنمی‌گرداند.

  • خلاصه‌های فکر بخشی از پاسخ نوشتاری تولیدشده معمولی مدل درنظر گرفته می‌شوند و به‌عنوان نشان‌های خروجی محسوب می‌شوند.

فعال کردن خلاصه‌های فکر

روی ارائه‌دهنده Gemini API خود کلیک کنید تا محتوا و کد مخصوص ارائه‌دهنده را در این صفحه مشاهده کنید.

با تنظیم includeThoughts روی درست در پیکربندی مدل، می‌توانید خلاصه افکار را فعال کنید. سپس می‌توانید با بررسی فیلد thoughtSummary در پاسخ، به خلاصه دسترسی پیدا کنید.

در اینجا مثالی از نحوه فعال کردن و بازیابی خلاصه افکار با پاسخ آورده شده است:

Swift

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
let generationConfig = GenerationConfig(
  thinkingConfig: ThinkingConfig(includeThoughts: true)
)

// Specify the config as part of creating the `GenerativeModel` instance.
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
  modelName: "GEMINI_MODEL_NAME",
  generationConfig: generationConfig
)

let response = try await model.generateContent("solve x^2 + 4x + 4 = 0")

// Handle the response that includes thought summaries.
if let thoughtSummary = response.thoughtSummary {
  print("Thought Summary: \(thoughtSummary)")
}
guard let text = response.text else {
  fatalError("No text in response.")
}
print("Answer: \(text)")

Kotlin

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
val generationConfig = generationConfig {
  thinkingConfig = thinkingConfig {
      includeThoughts = true
  }
}

// Specify the config as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
  modelName = "GEMINI_MODEL_NAME",
  generationConfig,
)

val response = model.generateContent("solve x^2 + 4x + 4 = 0")

// Handle the response that includes thought summaries.
response.thoughtSummary?.let {
    println("Thought Summary: $it")
}
response.text?.let {
    println("Answer: $it")
}

Java

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
ThinkingConfig thinkingConfig = new ThinkingConfig.Builder()
    .setIncludeThoughts(true)
    .build();

GenerationConfig generationConfig = GenerationConfig.builder()
    .setThinkingConfig(thinkingConfig)
    .build();

// Specify the config as part of creating the `GenerativeModel` instance.
GenerativeModelFutures model = GenerativeModelFutures.from(
        FirebaseAI.getInstance(GenerativeBackend.googleAI())
                .generativeModel(
                  /* modelName */ "GEMINI_MODEL_NAME",
                  /* generationConfig */ generationConfig
                );
);

// Handle the response that includes thought summaries.
ListenableFuture responseFuture = model.generateContent("solve x^2 + 4x + 4 = 0");
Futures.addCallback(responseFuture, new FutureCallback() {
    @Override
    public void onSuccess(GenerateContentResponse response) {
        if (response.getThoughtSummary() != null) {
            System.out.println("Thought Summary: " + response.getThoughtSummary());
        }
        if (response.getText() != null) {
            System.out.println("Answer: " + response.getText());
        }
    }

    @Override
    public void onFailure(Throwable t) {
        // Handle error
    }
}, MoreExecutors.directExecutor());

Web

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
const generationConfig = {
  thinkingConfig: {
    includeThoughts: true
  }
};

// Specify the config as part of creating the `GenerativeModel` instance.
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", generationConfig });

const result = await model.generateContent("solve x^2 + 4x + 4 = 0");
const response = result.response;

// Handle the response that includes thought summaries.
if (response.thoughtSummary()) {
    console.log(`Thought Summary: ${response.thoughtSummary()}`);
}
const text = response.text();
console.log(`Answer: ${text}`);

Dart

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
final thinkingConfig = ThinkingConfig(includeThoughts: true);

final generationConfig = GenerationConfig(
  thinkingConfig: thinkingConfig
);

// Specify the config as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.googleAI().generativeModel(
  model: 'GEMINI_MODEL_NAME',
  generationConfig: generationConfig,
);

final response = await model.generateContent('solve x^2 + 4x + 4 = 0');

// Handle the response that includes thought summaries.
if (response.thoughtSummary != null) {
  print('Thought Summary: ${response.thoughtSummary}');
}
if (response.text != null) {
  print('Answer: ${response.text}');
}

Unity

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
var thinkingConfig = new ThinkingConfig(includeThoughts: true);

var generationConfig = new GenerationConfig(
  thinkingConfig: thinkingConfig
);

// Specify the config as part of creating the `GenerativeModel` instance.
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
  modelName: "GEMINI_MODEL_NAME",
  generationConfig: generationConfig
);

var response = await model.GenerateContentAsync("solve x^2 + 4x + 4 = 0");

// Handle the response that includes thought summaries.
if (response.ThoughtSummary != null) {
    Debug.Log($"Thought Summary: {response.ThoughtSummary}");
}
if (response.Text != null) {
    Debug.Log($"Answer: {response.Text}");
}

خلاصه‌های فکر جاری‌سازی

همچنین می‌توانید خلاصه‌های فکر را مشاهده کنید اگر انتخاب کنید که بااستفاده از generateContentStream پاسخ را جاری‌سازی کنید. با این کار، خلاصه افزایشی و چرخشی درطول تولید پاسخ برگردانده می‌شود.

Swift

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
let generationConfig = GenerationConfig(
  thinkingConfig: ThinkingConfig(includeThoughts: true)
)

// Specify the config as part of creating the `GenerativeModel` instance.
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
  modelName: "GEMINI_MODEL_NAME",
  generationConfig: generationConfig
)

let stream = try model.generateContentStream("solve x^2 + 4x + 4 = 0")

// Handle the streamed response that includes thought summaries.
var thoughts = ""
var answer = ""
for try await response in stream {
  if let thought = response.thoughtSummary {
    if thoughts.isEmpty {
      print("--- Thoughts Summary ---")
    }
    print(thought)
    thoughts += thought
  }

  if let text = response.text {
    if answer.isEmpty {
      print("--- Answer ---")
    }
    print(text)
    answer += text
  }
}

Kotlin

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
val generationConfig = generationConfig {
  thinkingConfig = thinkingConfig {
      includeThoughts = true
  }
}

// Specify the config as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
  modelName = "GEMINI_MODEL_NAME",
  generationConfig,
)

// Handle the streamed response that includes thought summaries.
var thoughts = ""
var answer = ""
model.generateContentStream("solve x^2 + 4x + 4 = 0").collect { response ->
    response.thoughtSummary?.let {
        if (thoughts.isEmpty()) {
            println("--- Thoughts Summary ---")
        }
        print(it)
        thoughts += it
    }
    response.text?.let {
        if (answer.isEmpty()) {
            println("--- Answer ---")
        }
        print(it)
        answer += it
    }
}

Java

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
ThinkingConfig thinkingConfig = new ThinkingConfig.Builder()
    .setIncludeThoughts(true)
    .build();

GenerationConfig generationConfig = GenerationConfig.builder()
    .setThinkingConfig(thinkingConfig)
    .build();

// Specify the config as part of creating the `GenerativeModel` instance.
GenerativeModelFutures model = GenerativeModelFutures.from(
        FirebaseAI.getInstance(GenerativeBackend.googleAI())
                .generativeModel(
                  /* modelName */ "GEMINI_MODEL_NAME",
                  /* generationConfig */ generationConfig
                );
);

// Streaming with Java is complex and depends on the async library used.
// This is a conceptual example using a reactive stream.
Flowable responseStream = model.generateContentStream("solve x^2 + 4x + 4 = 0");

// Handle the streamed response that includes thought summaries
StringBuilder thoughts = new StringBuilder();
StringBuilder answer = new StringBuilder();

responseStream.subscribe(response -> {
    if (response.getThoughtSummary() != null) {
        if (thoughts.length() == 0) {
            System.out.println("--- Thoughts Summary ---");
        }
        System.out.print(response.getThoughtSummary());
        thoughts.append(response.getThoughtSummary());
    }
    if (response.getText() != null) {
        if (answer.length() == 0) {
            System.out.println("--- Answer ---");
        }
        System.out.print(response.getText());
        answer.append(response.getText());
    }
}, throwable -> {
    // Handle error
});

Web

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
const generationConfig = {
  thinkingConfig: {
    includeThoughts: true
  }
};

// Specify the config as part of creating the `GenerativeModel` instance.
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", generationConfig });

const result = await model.generateContentStream("solve x^2 + 4x + 4 = 0");

// Handle the streamed response that includes thought summaries.
let thoughts = "";
let answer = "";
for await (const chunk of result.stream) {
  if (chunk.thoughtSummary()) {
    if (thoughts === "") {
      console.log("--- Thoughts Summary ---");
    }
    // In Node.js, process.stdout.write(chunk.thoughtSummary()) could be used
    // to avoid extra newlines.
    console.log(chunk.thoughtSummary());
    thoughts += chunk.thoughtSummary();
  }

  const text = chunk.text();
  if (text) {
    if (answer === "") {
      console.log("--- Answer ---");
    }
    // In Node.js, process.stdout.write(text) could be used.
    console.log(text);
    answer += text;
  }
}

Dart

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
final thinkingConfig = ThinkingConfig(includeThoughts: true);

final generationConfig = GenerationConfig(
  thinkingConfig: thinkingConfig
);

// Specify the config as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.googleAI().generativeModel(
  model: 'GEMINI_MODEL_NAME',
  generationConfig: generationConfig,
);

final responses = model.generateContentStream('solve x^2 + 4x + 4 = 0');

// Handle the streamed response that includes thought summaries.
var thoughts = '';
var answer = '';
await for (final response in responses) {
  if (response.thoughtSummary != null) {
    if (thoughts.isEmpty) {
      print('--- Thoughts Summary ---');
    }
    thoughts += response.thoughtSummary!;
  }
  if (response.text != null) {
    if (answer.isEmpty) {
      print('--- Answer ---');
    }
    answer += response.text!;
  }
}

Unity

خلاصه‌های فکر را در GenerationConfig به‌عنوان بخشی از ایجاد نمونه GenerativeModel فعال کنید.


// ...

// Set the thinking configuration.
// Optionally enable thought summaries in the generated response (default is false).
var thinkingConfig = new ThinkingConfig(includeThoughts: true);

var generationConfig = new GenerationConfig(
  thinkingConfig: thinkingConfig
);

// Specify the config as part of creating the `GenerativeModel` instance.
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
  modelName: "GEMINI_MODEL_NAME",
  generationConfig: generationConfig
);

var stream = model.GenerateContentStreamAsync("solve x^2 + 4x + 4 = 0");

// Handle the streamed response that includes thought summaries.
var thoughts = "";
var answer = "";
await foreach (var response in stream)
{
    if (response.ThoughtSummary != null)
    {
        if (string.IsNullOrEmpty(thoughts))
        {
            Debug.Log("--- Thoughts Summary ---");
        }
        Debug.Log(response.ThoughtSummary);
        thoughts += response.ThoughtSummary;
    }
    if (response.Text != null)
    {
        if (string.IsNullOrEmpty(answer))
        {
            Debug.Log("--- Answer ---");
        }
        Debug.Log(response.Text);
        answer += response.Text;
    }
}



امضاهای فکری

هنگام استفاده از تفکر در تعاملات چند نوبتی، مدل به بافت فکری نوبت‌های قبلی دسترسی ندارد. بااین‌حال، اگر از فراخوانی تابع استفاده می‌کنید، می‌توانید از امضاهای فکری برای حفظ بافت فکری در نوبت‌ها استفاده کنید. امضاهای اندیشه نمایانگرهای رمزگذاری‌شده فرایند اندیشه داخلی مدل هستند، و هنگام استفاده از تابع‌های اندیشیدن و فراخوانی دردسترس هستند. به‌طور خاص، امضاهای فکری در موارد زیر تولید می‌شوند:

  • «اندیشیدن» فعال است و فکرها تولید می‌شود.
  • درخواست شامل بیانیه‌های تابع است.

برای بهره‌مندی از امضاهای فکری، طبق معمول از فراخوانی تابع استفاده کنید. ‫Firebase AI Logic کیت‌های توسعه نرم‌افزار با مدیریت وضعیت و رسیدگی خودکار به امضاهای فکری برای شما، این فرایند را ساده می‌کنند. «کیت‌های توسعه نرم‌افزار» به‌طور خودکار امضاهای فکری تولیدشده را بین تماس‌های بعدی sendMessage یا sendMessageStream در جلسه Chat منتقل می‌کنند.



قیمت‌گذاری و شمارش داده‌واحدهای اندیشیدن

نشانه‌های «اندیشگر» از همان قیمت‌گذاری نشانه‌های برونداد نوشتاری استفاده می‌کنند. اگر خلاصه‌های فکر را فعال کنید، این خلاصه‌ها به‌عنوان نشان‌های فکر درنظر گرفته می‌شوند و قیمت آن‌ها براین اساس تعیین می‌شود.

می‌توانید پایش هوش مصنوعی را در کنسول Firebase فعال کنید تا تعداد نشانه‌های تفکر را برای درخواست‌هایی که تفکر در آن‌ها فعال است پایش کنید.

می‌توانید تعداد کل نشانه‌های فکر کردن را از فیلد thoughtsTokenCount در مشخصه usageMetadata پاسخ دریافت کنید:

Swift

// ...

let response = try await model.generateContent("Why is the sky blue?")

if let usageMetadata = response.usageMetadata {
  print("Thoughts Token Count: \(usageMetadata.thoughtsTokenCount)")
}

Kotlin

// ...

val response = model.generateContent("Why is the sky blue?")

response.usageMetadata?.let { usageMetadata ->
    println("Thoughts Token Count: ${usageMetadata.thoughtsTokenCount}")
}

Java

// ...

ListenableFuture<GenerateContentResponse> response =
    model.generateContent("Why is the sky blue?");

Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
    @Override
    public void onSuccess(GenerateContentResponse result) {
        String usageMetadata = result.getUsageMetadata();
        if (usageMetadata != null) {
            System.out.println("Thoughts Token Count: " +
                usageMetadata.getThoughtsTokenCount());
        }
    }

    @Override
    public void onFailure(Throwable t) {
        t.printStackTrace();
    }
}, executor);

Web

// ...

const response = await model.generateContent("Why is the sky blue?");

if (response?.usageMetadata?.thoughtsTokenCount != null) {
    console.log(`Thoughts Token Count: ${response.usageMetadata.thoughtsTokenCount}`);
}

Dart

// ...

final response = await model.generateContent(
  Content.text("Why is the sky blue?"),
]);

if (response?.usageMetadata case final usageMetadata?) {
  print("Thoughts Token Count: ${usageMetadata.thoughtsTokenCount}");
}

Unity

// ...

var response = await model.GenerateContentAsync("Why is the sky blue?");

if (response.UsageMetadata != null)
{
    UnityEngine.Debug.Log($"Thoughts Token Count: {response.UsageMetadata?.ThoughtsTokenCount}");
}

درباره نشان‌ها در راهنمای شمارش نشان‌ها بیشتر بدانید.