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

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

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

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

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

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

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



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

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

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

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

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

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

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

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



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

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

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

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

سطوح «اندیشگر»

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

تنظیم سطح «اندیشگر»

روی ارائه‌دهنده 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',
  generationConfig: 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 4 Argon
gemini-4-argon
۱ (پیش‌فرض)
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-4-argon،‏ gemini-3.8-flash، و gemini-3.7-flash از سطح تفکر MINIMAL پشتیبانی نمی‌کنند. اگر سطح «اندیشگر» را روی MINIMAL تنظیم کنید، درخواست با خطای ۴۰۰ ناموفق خواهد بود.



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

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



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

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

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

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

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



خلاصه افکار

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

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

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

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

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

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

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

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

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

می‌توانید با تنظیم includeThoughts روی true در پیکربندی مدل، خلاصه‌های فکری را فعال کنید. سپس می‌توانید با بررسی فیلد 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([Content.text('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([Content.text('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}");
}

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