جارٍ التفكير

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

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

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

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

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

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

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



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

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

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

النماذج التي تتوافق مع هذه الإمكانية

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

  • gemini-3.1-pro-preview
  • gemini-3.5-flash
  • gemini-3.1-flash-lite
  • gemini-3-pro-image-preview (المعروف أيضًا باسم "Nano Banana Pro")
  • gemini-3.1-flash-image-preview (المعروف أيضًا باسم "Nano Banana 2")
  • gemini-2.5-pro
  • gemini-2.5-flash
  • gemini-2.5-flash-lite

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

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

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

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

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

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

  • يمكنك ضبط مستوى التفكير (أو مدة الاستدلال في نماذج Gemini 2.5) للتحكّم في مقدار التفكير الذي يمكن أن يقوم به النموذج. إذا ضبطت المستوى على قيمة عالية، يمكن للنموذج التفكير أكثر إذا لزم الأمر. وإذا ضبطت المستوى على قيمة منخفضة، لن "يفرط" النموذج في التفكير في رده، كما أنّه سيحتفظ بمزيد من الحد الأقصى لإجمالي عدد الرموز المميزة المخرَجة للرد الفعلي، ويمكن أن يساعد ذلك في تقليل وقت الاستجابة والتكلفة.

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



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

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

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

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

يمكنك التحكّم في هذا الإعداد باستخدام مستويات التفكير (الإصدارات Gemini 3 والإصدارات الأحدث) أو باستخدام ميزانيات التفكير (الإصدارات 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_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.1-pro-preview (تلقائي)
gemini-3.5-flash (تلقائي)
gemini-3.1-flash-lite (تلقائي)
gemini-3-pro-image-preview ("Nano Banana Pro") (تلقائي)
gemini-3.1-flash-image-preview ("Nano Banana 2") (تلقائي)



ميزانيات التفكير (نماذج 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}");
}

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