Gemini के सभी मॉडल, "सोचने की प्रोसेस" का इस्तेमाल करते हैं. इससे, तर्क करने और कई चरणों में योजना बनाने की उनकी क्षमता में काफ़ी सुधार होता है. इस वजह से, वे कोडिंग, ऐडवांस मैथ, और डेटा के विश्लेषण जैसे मुश्किल कामों को बेहतर तरीके से कर पाते हैं.
थिंकिंग मॉडल में ये कॉन्फ़िगरेशन और विकल्प उपलब्ध हैं:
सोचने की क्षमता को कंट्रोल करना
सोचने के लेवल को कॉन्फ़िगर करके, यह कंट्रोल किया जा सकता है कि कोई मॉडल कितनी "सोच-विचार" कर सकता है. यह कॉन्फ़िगरेशन खास तौर पर तब ज़रूरी होता है, जब इंतज़ार का समय या लागत कम करना आपकी प्राथमिकता हो. साथ ही, टास्क की कठिनाइयों की तुलना करके देखें कि किसी मॉडल को अपनी सोचने की क्षमता का कितना इस्तेमाल करना पड़ सकता है.सोचने की प्रक्रिया की खास जानकारी पाना
जनरेट किए गए जवाब में सोचने की प्रक्रिया की खास जानकारी को शामिल करने के लिए, इसे चालू किया जा सकता है. ये खास जानकारी, मॉडल के रॉ थॉट का सिंथेसाइज़्ड वर्शन होती हैं. इनसे मॉडल के इंटरनल रीज़निंग प्रोसेस के बारे में अहम जानकारी मिलती है.थॉट सिग्नेचर मैनेज करना
Firebase AI Logic SDK टूल, आपके लिए थॉट सिग्नेचर को अपने-आप मैनेज करते हैं. इससे यह पक्का होता है कि मॉडल के पास, पिछले टर्न के थॉट कॉन्टेक्स्ट का ऐक्सेस हो. खास तौर पर, फ़ंक्शन कॉलिंग का इस्तेमाल करते समय.
थिंकिंग मॉडल इस्तेमाल करने के लिए, सबसे सही तरीके और प्रॉम्प्ट देने से जुड़े दिशा-निर्देश ज़रूर देखें.
रीज़निंग मॉडल इस्तेमाल करने के सबसे सही तरीके और प्रॉम्प्ट देने से जुड़े दिशा-निर्देश
हमारा सुझाव है कि आप अपने प्रॉम्प्ट को Google AI Studio या Agent Studio में आज़माएँ. यहाँ आपको सोचने की पूरी प्रक्रिया देखने को मिलेगी. इससे आपको यह पता चल सकता है कि मॉडल ने कहां गलती की है. इसके बाद, अपने प्रॉम्प्ट को बेहतर बनाया जा सकता है, ताकि आपको ज़्यादा सटीक और बेहतर जवाब मिल सकें.
सबसे पहले, एक सामान्य प्रॉम्प्ट दें जिसमें आपको मनमुताबिक़ नतीजे के बारे में जानकारी देनी होगी. इसके बाद, देखें कि मॉडल अपने जवाब को तय करने के लिए, शुरुआती तौर पर क्या सोचता है. अगर जवाब उम्मीद के मुताबिक़ नहीं है, तो प्रॉम्प्ट देने की इन तकनीकों में से किसी एक का इस्तेमाल करके, मॉडल को बेहतर जवाब जनरेट करने में मदद करें:
- सिलसिलेवार निर्देश दें
- इनपुट-आउटपुट के कई उदाहरण दें
- आउटपुट और जवाबों को किस तरह से तैयार और फ़ॉर्मैट किया जाना चाहिए, इसके बारे में निर्देश दें
- पुष्टि करने के लिए खास चरण बताएं
प्रॉम्प्ट के अलावा, इन सुझावों का भी इस्तेमाल करें:
सिस्टम इंस्ट्रक्शन सेट करें. ये "प्रस्तावना" की तरह होते हैं. इन्हें मॉडल को प्रॉम्प्ट या असली उपयोगकर्ता से मिलने वाले किसी भी अन्य निर्देश से पहले जोड़ा जाता है. इनकी मदद से, अपनी खास ज़रूरतों और इस्तेमाल के उदाहरणों के आधार पर, मॉडल के व्यवहार को कंट्रोल किया जा सकता है.
सोचने का लेवल सेट करें, ताकि यह कंट्रोल किया जा सके कि मॉडल कितना सोच सकता है. अगर इसे ज़्यादा पर सेट किया जाता है, तो ज़रूरत पड़ने पर मॉडल ज़्यादा सोच सकता है. अगर इसे कम पर सेट किया जाता है, तो मॉडल अपने जवाब के बारे में "ज़्यादा नहीं सोचेगा". साथ ही, यह असल जवाब के लिए, कुल टोकन आउटपुट की सीमा को ज़्यादा रिज़र्व रखता है. इससे इंतज़ार का समय और लागत कम करने में मदद मिल सकती है.
थिंकिंग टोकन की संख्या और उन अनुरोधों की इंतज़ार की अवधि को मॉनिटर करने के लिए, Firebase कंसोल में एआई मॉनिटरिंग की सुविधा चालू करें जिनमें थिंकिंग की सुविधा चालू है. अगर आपने सोच-विचार की खास जानकारी दिखाने की सुविधा चालू की है, तो यह जानकारी कंसोल में दिखेगी. यहां मॉडल के तर्क की पूरी जानकारी देखी जा सकती है. इससे आपको अपने प्रॉम्प्ट को डीबग करने और उन्हें बेहतर बनाने में मदद मिलेगी.
एआई के गहराई से विचार करने की प्रोसेस को कंट्रोल करना
सोचने के लेवल को कॉन्फ़िगर किया जा सकता है. इससे यह कंट्रोल किया जा सकता है कि कोई मॉडल, जवाब देने से पहले कितनी "सोच-विचार" और तर्क कर सकता है. यह कॉन्फ़िगरेशन खास तौर पर तब ज़रूरी होता है, जब इंतज़ार का समय या लागत कम करना आपकी प्राथमिकता हो.
टास्क की कठिनाई की तुलना ज़रूर देखें. इससे यह तय करने में मदद मिलेगी कि किसी मॉडल को सोचने की क्षमता की कितनी ज़रूरत पड़ सकती है. यहां कुछ खास दिशा-निर्देश दिए गए हैं:
- कम जटिल टास्क के लिए, थिंकिंग वैल्यू को कम पर सेट करें. इसके अलावा, अगर आपको इंतज़ार का समय या लागत कम करनी है, तो भी ऐसा करें.
- ज़्यादा मुश्किल टास्क के लिए, ज़्यादा सोच-विचार करने की वैल्यू सेट करें.
रीज़निंग के लेवल
कोई मॉडल जवाब जनरेट करने के लिए कितना सोच-विचार कर सकता है, इसे कंट्रोल करने के लिए थिंकिंग लेवल तय किया जा सकता है. इससे यह तय होता है कि मॉडल कितने थिंकिंग टोकन इस्तेमाल कर सकता है.
रीज़निंग का लेवल सेट करना
|
इस पेज पर, Gemini API की सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, सेवा देने वाली कंपनी के नाम पर क्लिक करें. |
GenerativeModel इंस्टेंस बनाने के दौरान, GenerationConfig में गहराई से विचार करने का लेवल सेट करें. कॉन्फ़िगरेशन को इंस्टेंस के लाइफ़टाइम के लिए बनाए रखा जाता है. अगर आपको अलग-अलग अनुरोधों के लिए, अलग-अलग थिंकिंग लेवल का इस्तेमाल करना है, तो हर लेवल के लिए कॉन्फ़िगर किए गए GenerativeModel इंस्टेंस बनाएं.
इस सेक्शन में आगे, रीज़निंग लेवल के लिए इस्तेमाल की जा सकने वाली वैल्यू के बारे में जानें.
Swift
GenerativeModel इंस्टेंस बनाते समय, GenerationConfig में सूझ-बूझ वाले मॉडल का लेवल सेट करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए, GenerationConfig में पैरामीटर की वैल्यू सेट करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए, GenerationConfig में पैरामीटर की वैल्यू सेट करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए, GenerationConfig में पैरामीटर की वैल्यू सेट करें.
// ...
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
GenerativeModel इंस्टेंस बनाने के हिस्से के तौर पर, GenerationConfig में पैरामीटर की वैल्यू सेट करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए, GenerationConfig में पैरामीटर की वैल्यू सेट करें.
// ...
// 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 Argongemini-4-argon
|
1 | (डिफ़ॉल्ट) | ||
Gemini 3.x Progemini-3.1-pro-preview
|
(डिफ़ॉल्ट) | |||
Gemini 3.x Flashgemini-3.8-flashgemini-3.7-flashgemini-3.6-flashgemini-3.5-flash
|
gemini-3.8-flashgemini-3.7-flash |
(डिफ़ॉल्ट) | ||
Gemini 3.x Flash‑Litegemini-3.5-flash-litegemini-3.1-flash-lite
|
(डिफ़ॉल्ट) | |||
Gemini Nano Banana 2.1gemini-nano-banana-2.1
|
(डिफ़ॉल्ट) | |||
Gemini Nano Banana 2gemini-3.1-flash-image |
(डिफ़ॉल्ट) | |||
Gemini Nano Banana 2 Litegemini-3.1-flash-lite-image |
(डिफ़ॉल्ट) | |||
Gemini Nano Banana Progemini-3-pro-image
|
(डिफ़ॉल्ट) |
1 gemini-4-argon, gemini-3.8-flash,
और gemini-3.7-flash में MINIMAL थिंकिंग लेवल की सुविधा नहीं है. अगर आपने सूझ-बूझ वाले लेवल को MINIMAL पर सेट किया है, तो अनुरोध पूरा नहीं होगा और 400 गड़बड़ी का कोड दिखेगा.
थिंकिंग बजट (Gemini 2.5 मॉडल)
कोई Gemini 2.5 मॉडल, जवाब जनरेट करने के लिए कितनी गहराई से विश्लेषण करे, इसे कंट्रोल किया जा सकता है. इसके लिए, थिंकिंग बजट तय करें. इससे यह तय होता है कि मॉडल कितने थिंकिंग टोकन इस्तेमाल कर सकता है.
सूझ-बूझ वाले सभी मॉडल के लिए टास्क की जटिलता
आसान टास्क — ज़्यादा सोचने की ज़रूरत नहीं है
ऐसे आसान अनुरोध जिनके लिए मुश्किल रीज़निंग की ज़रूरत नहीं होती. जैसे, तथ्यों को ढूंढना या कैटगरी तय करना. उदाहरण:- "DeepMind की स्थापना कहां हुई थी?"
- "क्या इस ईमेल में मीटिंग के लिए कहा गया है या सिर्फ़ जानकारी दी गई है?"
सामान्य टास्क — इनके लिए कुछ हद तक सोच-विचार करने की ज़रूरत पड़ सकती है
ऐसे सामान्य अनुरोध जिनके लिए सिलसिलेवार तरीक़े से प्रोसेसिंग या ज़्यादा जानकारी की ज़रूरत होती है. उदाहरण:- "प्रकाश संश्लेषण और बड़े होने के बीच समानता बताओ."
- "इलेक्ट्रिक कारों और हाइब्रिड कारों की तुलना करें और उनके बीच अंतर बताएं."
मुश्किल टास्क — इनके लिए, ज़्यादा से ज़्यादा सोच-विचार करने की ज़रूरत पड़ सकती है
बहुत मुश्किल टास्क, जैसे कि गणित की मुश्किल समस्याओं को हल करना या कोडिंग से जुड़े टास्क. इस तरह के टास्क के लिए, मॉडल को अपनी पूरी रीज़निंग और प्लानिंग की क्षमताओं का इस्तेमाल करना पड़ता है. अक्सर, जवाब देने से पहले कई इंटरनल स्टेप शामिल होते हैं. उदाहरण:- "AIME 2025 में मौजूद पहली समस्या को हल करो: उन सभी पूर्णांक बेस b > 9 का योग पता करो जिनके लिए 17b, 97b का भाजक है."
- "एक ऐसे वेब ऐप्लिकेशन के लिए Python कोड लिखो जो रीयल-टाइम में शेयर बाज़ार का डेटा दिखाता हो. इसमें उपयोगकर्ता की पुष्टि करने की सुविधा भी शामिल होनी चाहिए. इसे जितना हो सके उतना कुशल बनाएं."
सूझ-बूझ से बनाई गई खास जानकारी
सोच-विचार की खास जानकारी, मॉडल के रॉ थॉट का सिंथेसाइज़ किया गया वर्शन होती है. इससे मॉडल के इंटरनल रीज़निंग प्रोसेस के बारे में अहम जानकारी मिलती है.
जवाबों में सोच-विचार की खास जानकारी शामिल करने की कुछ वजहें यहां दी गई हैं:
आपके पास अपने ऐप्लिकेशन के यूज़र इंटरफ़ेस (यूआई) में, सोच-विचार की खास जानकारी दिखाने या उसे अपने उपयोगकर्ताओं के लिए उपलब्ध कराने का विकल्प होता है. सोचने की प्रोसेस की खास जानकारी, जवाब में एक अलग हिस्से के तौर पर दिखती है. इससे आपको यह कंट्रोल करने में मदद मिलती है कि आपके ऐप्लिकेशन में इसका इस्तेमाल कैसे किया जाए.
अगर आपने Firebase कंसोल में एआई मॉनिटरिंग की सुविधा भी चालू की है, तो कंसोल में थॉट प्रोसेस की खास जानकारी दिखती है. यहां मॉडल की पूरी रीज़निंग देखी जा सकती है. इससे आपको अपने प्रॉम्प्ट को डीबग करने और उन्हें बेहतर बनाने में मदद मिलती है.
सोच-विचार की खास जानकारी के बारे में कुछ ज़रूरी बातें यहां दी गई हैं:
सोच-विचार की खास जानकारी को सोच-विचार के बजट से कंट्रोल नहीं किया जाता. बजट सिर्फ़ मॉडल के रॉ थॉट पर लागू होते हैं. हालांकि, अगर सोचने की सुविधा बंद है, तो मॉडल, सोच-विचार की खास जानकारी नहीं दिखाएगा.
Thought summaries को मॉडल के जनरेट किए गए टेक्स्ट रिस्पॉन्स का हिस्सा माना जाता है. साथ ही, इन्हें आउटपुट टोकन के तौर पर गिना जाता है.
सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करना
|
इस पेज पर, Gemini API की सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, सेवा देने वाली कंपनी के नाम पर क्लिक करें. |
मॉडल कॉन्फ़िगरेशन में includeThoughts को true पर सेट करके, सोच-विचार की खास जानकारी पाने की सुविधा चालू की जा सकती है. इसके बाद, जवाब में मौजूद thoughtSummary फ़ील्ड को देखकर, खास जानकारी को ऐक्सेस किया जा सकता है.
यहाँ एक उदाहरण दिया गया है, जिसमें बताया गया है कि जवाब के साथ, सोच-विचार की प्रक्रिया की खास जानकारी को कैसे चालू किया जाए और उसे कैसे हासिल किया जाए:
Swift
GenerativeModel इंस्टेंस बनाने के लिए,
GenerationConfig
में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए,
GenerationConfig
में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए,
GenerationConfig
में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए,
GenerationConfig
में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
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
GenerativeModel इंस्टेंस बनाने के दौरान, GenerationConfig में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए,
GenerationConfig
में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए,
GenerationConfig
में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए,
GenerationConfig
में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए,
GenerationConfig
में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए,
GenerationConfig
में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
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
GenerativeModel इंस्टेंस बनाने के दौरान, GenerationConfig में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
// 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
GenerativeModel इंस्टेंस बनाने के लिए,
GenerationConfig
में सोच-विचार की खास जानकारी दिखाने की सुविधा चालू करें.
// ...
// 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 SDK टूल, स्टेट को मैनेज करके और आपके लिए थॉट सिग्नेचर को अपने-आप हैंडल करके, इस प्रोसेस को आसान बनाते हैं. SDK टूल, जनरेट किए गए किसी भी थॉट सिग्नेचर को Chat सेशन में, sendMessage या sendMessageStream के बाद होने वाले कॉल के बीच अपने-आप पास कर देते हैं.
थिंकिंग टोकन की कीमत और गिनती
थिंकिंग टोकन के लिए, टेक्स्ट-आउटपुट टोकन वाली कीमत ही लागू होती है. सोच-विचार की खास जानकारी जनरेट करने की सुविधा चालू करने पर, इन्हें थिंकिंग टोकन माना जाता है और इनकी कीमत भी उसी हिसाब से तय की जाती है.
जिन अनुरोधों के लिए थिंकिंग की सुविधा चालू है उनके लिए थिंकिंग टोकन की संख्या को मॉनिटर किया जा सकता है. इसके लिए, Firebase कंसोल में एआई मॉनिटरिंग की सुविधा चालू करें.
रिस्पॉन्स के usageMetadata एट्रिब्यूट में मौजूद thoughtsTokenCount फ़ील्ड से, थिंकिंग टोकन की कुल संख्या देखी जा सकती है:
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}");
}
टोकन की गिनती करने की गाइड में, टोकन के बारे में ज़्यादा जानें.