جارٍ التفكير

يمكن لنماذج Gemini 3 وGemini 2.5 استخدام "عملية تفكير" داخلية تعمل على تحسين قدراتها بشكل كبير في ما يتعلق بالاستنتاج والتخطيط المتعدّد الخطوات، ما يجعلها فعّالة للغاية في المهام المعقّدة، مثل الترميز والرياضيات المتقدّمة وتحليل البيانات.

تقدّم نماذج التفكير الإعدادات والخيارات التالية:

  • التحكّم في مقدار التفكير
    يمكنك ضبط مقدار "التفكير" الذي يمكن أن يجريه النموذج، وهذا الإعداد مهم بشكل خاص إذا كانت الأولوية هي تقليل وقت الاستجابة أو التكلفة. يمكنك أيضًا مراجعة مقارنة بين صعوبات المهام لتحديد مدى حاجة النموذج إلى قدراته الفكرية.

    يمكنك التحكّم في هذا الإعداد باستخدام مستويات التفكير (طُرز Gemini 3 والإصدارات الأحدث) أو باستخدام ميزانيات التفكير (طُرز Gemini 2.5).

  • الحصول على ملخّصات الأفكار
    يمكنك تفعيل ملخّصات الأفكار لتضمينها في الردّ الذي تم إنشاؤه. هذه الملخّصات هي إصدارات مركّزة من الأفكار الأولية التي يطرحها النموذج، وتقدّم إحصاءات حول عملية الاستدلال الداخلية التي يجريها النموذج.

  • التعامل مع توقيعات الأفكار
    تتعامل حِزم تطوير البرامج (SDK) في Firebase AI Logic تلقائيًا مع توقيعات الأفكار، ما يضمن أنّ النموذج يمكنه الوصول إلى سياق الأفكار من الأدوار السابقة، خاصةً عند استخدام ميزة "استدعاء الدوال".

احرص على مراجعة أفضل الممارسات وإرشادات الطلبات لاستخدام نماذج التفكير.



استخدام نموذج للتفكير

استخدِم نموذجًا مفكِّرًا تمامًا كما تستخدم أي نموذج آخر من نماذج Gemini.

للاستفادة إلى أقصى حدّ من نماذج التفكير، راجِع أفضل الممارسات وإرشادات الطلبات لاستخدام نماذج التفكير في وقت لاحق من هذه الصفحة.

الطُرز التي تتيح هذه الإمكانية

تتيح هذه الإمكانية استخدام الطرازَين Gemini 3 وGemini 2.5 فقط.

  • gemini-3-pro-preview
  • gemini-3-pro-image-preview (المعروف أيضًا باسم "nano banana pro")
  • gemini-3-flash-preview
  • gemini-2.5-pro
  • gemini-2.5-flash
  • gemini-2.5-flash-lite

أفضل الممارسات والإرشادات حول استخدام نماذج التفكير

ننصحك باختبار طلبك في Google AI Studio أو Vertex AI Studio حيث يمكنك الاطّلاع على عملية التفكير الكاملة. يمكنك تحديد أي جوانب قد يكون النموذج قد أخطأ فيها، ما يتيح لك تحسين طلباتك للحصول على ردود أكثر اتساقًا ودقة.

ابدأ بطلب عام يصف النتيجة المطلوبة، ولاحظ الأفكار الأولية التي يطرحها النموذج حول كيفية تحديد استجابته. إذا لم يكن الردّ على المستوى المطلوب، يمكنك مساعدة النموذج في إنشاء ردّ أفضل باستخدام أي من تقنيات الطلبات التالية:

  • تقديم تعليمات مفصّلة
  • تقديم عدة أمثلة على أزواج المدخلات والمخرجات
  • قدِّم إرشادات حول كيفية صياغة النتائج والردود وتنسيقها
  • تقديم خطوات تحقّق محدّدة

بالإضافة إلى تقديم الطلبات، ننصحك باتّباع الاقتراحات التالية:

  • اضبط تعليمات النظام، وهي بمثابة "مقدمة" تضيفها قبل أن يتلقّى النموذج أي تعليمات أخرى من الطلب أو المستخدم النهائي. تتيح لك هذه المعلمات توجيه سلوك النموذج استنادًا إلى احتياجاتك وحالات الاستخدام المحدّدة.

  • اضبط مستوى التفكير (أو مدة الاستدلال في نماذج Gemini 2.5) للتحكّم في مقدار التفكير الذي يمكن للنموذج إجراؤه. إذا ضبطت المستوى على قيمة عالية، يمكن للنموذج التفكير بشكل أكبر، إذا لزم الأمر. إذا ضبطت القيمة على مستوى أقل، لن يبالغ النموذج في التفكير في الردّ، وسيحتفظ أيضًا بمزيد من إجمالي حدّ الرموز المميزة المسموح بها للردّ الفعلي، ما يساعد في تقليل وقت الاستجابة والتكلفة.

  • فعِّل مراقبة الذكاء الاصطناعي في Firebase console لتتبُّع عدد الرموز المميزة التي يتم إنشاؤها أثناء التفكير ووقت الاستجابة لطلباتك التي تم تفعيل ميزة "التفكير" فيها. وفي حال تفعيل ملخّصات الأفكار، ستظهر في وحدة التحكّم حيث يمكنك الاطّلاع على تفاصيل أسباب النموذج لمساعدتك في تصحيح الأخطاء وتحسين طلباتك.



التحكّم في مقدار التفكير

يمكنك ضبط مقدار "التفكير" والاستدلال المنطقي الذي يمكن للنموذج تنفيذه قبل عرض ردّ. ويكون هذا الإعداد مهمًا بشكل خاص إذا كانت الأولوية هي تقليل وقت الاستجابة أو التكلفة.

احرص على مراجعة مقارنة بين صعوبات المهام لتحديد مدى حاجة النموذج إلى قدرته على التفكير. في ما يلي بعض الإرشادات العامة:

  • اضبط قيمة تفكير أقل للمهام الأقل تعقيدًا أو إذا كانت الأولوية بالنسبة إليك هي تقليل وقت الاستجابة أو التكلفة.
  • اضبط قيمة تفكير أعلى للمهام الأكثر تعقيدًا.

يمكنك التحكّم في هذا الإعداد باستخدام مستويات التفكير (طُرز Gemini 3 والإصدارات الأحدث) أو باستخدام ميزانيات التفكير (طُرز Gemini 2.5).

مستويات التفكير (طُرز Gemini 3)

للتحكّم في مقدار التفكير الذي يمكن أن يجريه نموذج Gemini 3 لإنشاء رده، يمكنك تحديد مستوى التفكير لمقدار الرموز المميزة الخاصة بالتفكير التي يُسمح له باستخدامها.

ضبط مستوى التفكير

انقر على موفّر Gemini API لعرض المحتوى والرمز الخاصين بالموفّر على هذه الصفحة.

اضبط مستوى التفكير في GenerationConfig كجزء من إنشاء GenerativeModel مثيل لنموذج Gemini 3. ويتم الاحتفاظ بالإعدادات طوال مدة تشغيل الجهاز الافتراضي. إذا كنت تريد استخدام مستويات تفكير مختلفة لطلبات مختلفة، يمكنك إنشاء مثيلات 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_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_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_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_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_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_MODEL_NAME",
  generationConfig: generationConfig
);

// ...

القيم المسموح بها لمستوى التفكير

يسرد الجدول التالي قيم مستوى التفكير التي يمكنك ضبطها لكل نموذج من خلال ضبط thinkingLevel الخاص بالنموذج.

MINIMAL LOW MEDIUM HIGH
  • يستخدم النموذج أقل عدد ممكن من الرموز المميزة، أي لا يتطلّب التفكير كثيرًا
  • المهام البسيطة
  • يستخدم النموذج عددًا أقل من الرموز المميزة، ويقلّل من وقت الاستجابة والتكلفة
  • المهام البسيطة والمهام ذات الإنتاجية العالية
  • يستخدم النموذج نهجًا متوازنًا
  • مهام معقّدة بشكل معتدل
  • يستخدم النموذج الرموز المميزة حتى الحد الأقصى
  • طلبات معقّدة تتطلّب استدلالاً معمّقًا
Gemini 3 Pro (تلقائي)
Gemini 3 Pro Image ("nano banana pro") (تلقائي)
Gemini 3 Flash (تلقائي)



ميزانيات التفكير (نماذج 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؟"
    • "هل تطلب هذه الرسالة الإلكترونية عقد اجتماع أم أنّها تقدّم معلومات فقط؟"
  • المهام المتوسطة — من المحتمل أن يكون بعض التفكير ضروريًا
    الطلبات الشائعة التي تستفيد من درجة من المعالجة خطوة بخطوة أو فهم أعمق. أمثلة:

    • "أريد تشبيهًا بين عملية التمثيل الضوئي ومرحلة النمو".
    • "قارِن بين السيارات الكهربائية والسيارات الهجينة".
  • المهام الصعبة التي تتطلّب أقصى قدر من التفكير
    التحديات المعقّدة حقًا، مثل حلّ مسائل رياضية معقّدة أو مهام متعلقة بالبرمجة تتطلّب هذه الأنواع من المهام أن يستخدم النموذج جميع قدراته في التفكير والتخطيط، وغالبًا ما تتضمّن العديد من الخطوات الداخلية قبل تقديم إجابة. أمثلة:

    • "حلّ المسألة 1 في مسابقة AIME لعام 2025: أوجد مجموع كل الأعداد الصحيحة الأساسية b > 9 التي يكون فيها 17b قاسمًا لـ 97b".
    • "أريد كتابة رمز Python لتطبيق ويب يعرض بيانات سوق الأسهم في الوقت الفعلي، بما في ذلك مصادقة المستخدم. يجب أن تكون هذه العملية فعّالة قدر الإمكان".



ملخّصات الأفكار

ملخّصات الأفكار هي نُسخ مركّبة من الأفكار الأولية التي يطرحها النموذج، وتقدّم إحصاءات حول عملية الاستدلال الداخلية التي يجريها النموذج.

في ما يلي بعض الأسباب التي تدفع إلى تضمين ملخّصات الأفكار في الردود:

  • يمكنك عرض ملخّصات الأفكار في واجهة مستخدم تطبيقك أو إتاحتها للمستخدمين. يتم عرض ملخّص الفكرة كجزء منفصل في الردّ، ما يتيح لك التحكّم بشكل أكبر في كيفية استخدامه في تطبيقك.

  • إذا فعّلت أيضًا ميزة مراقبة الذكاء الاصطناعي في Firebase console، ستظهر ملخّصات الأفكار في وحدة التحكّم حيث يمكنك فحص الاستدلال المفصّل للنموذج لمساعدتك في تصحيح الأخطاء وتحسين طلباتك.

في ما يلي بعض الملاحظات الرئيسية حول ملخّصات الأفكار:

  • لا يتم التحكّم في ملخّصات الأفكار من خلال ميزانيات التفكير (تنطبق الميزانيات فقط على الأفكار الأولية التي يقدّمها النموذج). ومع ذلك، إذا كانت ميزة التفكير غير مفعّلة، لن يعرض النموذج ملخّصًا للأفكار.

  • تُعدّ ملخّصات الأفكار جزءًا من الردود العادية التي ينشئها النموذج، ويتم احتسابها كرموز مميّزة في الرد.

تفعيل ملخّصات الأفكار

انقر على موفّر 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;
    }
}



توقيعات الأفكار

عند استخدام ميزة "التفكير" في التفاعلات المتعددة الأدوار، لا يمكن للنموذج الوصول إلى سياق التفكير من الأدوار السابقة. ومع ذلك، إذا كنت تستخدم ميزة استدعاء الدوال، يمكنك الاستفادة من توقيعات الأفكار للحفاظ على سياق الأفكار في مختلف المحادثات. توقيعات التفكير هي تمثيلات مشفّرة لعملية التفكير الداخلية الخاصة بالنموذج، وهي متاحة عند استخدام ميزة "التفكير و استدعاء الدوال". على وجه التحديد، يتم إنشاء توقيعات الأفكار في الحالات التالية:

  • تم تفعيل ميزة "التفكير" وتم إنشاء الأفكار.
  • يتضمّن الطلب تعريفات للدوال.

للاستفادة من توقيعات الأفكار، استخدِم ميزة "استدعاء الدوال" كالمعتاد. تسهّل حِزم تطوير البرامج (SDK) في Firebase AI Logic هذه العملية من خلال إدارة الحالة والتعامل تلقائيًا مع توقيعات الأفكار نيابةً عنك. تنقل حِزم تطوير البرامج (SDK) تلقائيًا أي توقيعات أفكار تم إنشاؤها بين طلبات sendMessage أو sendMessageStream اللاحقة في جلسة Chat.



التسعير واحتساب الرموز المميزة

تخضع الرموز المميزة الخاصة بنموذج "المفكِّر" للتسعير نفسه الذي تخضع له الرموز المميزة الخاصة بالنتائج النصية. في حال تفعيل ملخّصات الأفكار، يتم اعتبارها رموزًا مميّزة للتفكير ويتم تحديد سعرها وفقًا لذلك.

يمكنك تفعيل ميزة مراقبة الذكاء الاصطناعي في Firebase Console لتتبُّع عدد الرموز المميزة التي تشير إلى التفكير في الطلبات التي تم تفعيل ميزة التفكير فيها.

يمكنك الحصول على إجمالي عدد الرموز المميزة للتفكير من الحقل 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}");
}

يمكنك الاطّلاع على مزيد من المعلومات حول الرموز المميزة في دليل رموز العدّ.