Gemini 2.5 मॉडल, "सोचने की प्रोसेस" का इस्तेमाल कर सकते हैं. इससे, उनकी तर्क करने और कई चरणों वाली प्लानिंग करने की क्षमता बेहतर होती है. इसलिए, ये मॉडल कोडिंग, गणित के मुश्किल सवालों को हल करने, और डेटा के विश्लेषण जैसे मुश्किल कामों को आसानी से कर सकते हैं.
सोचने वाले मॉडल में ये कॉन्फ़िगरेशन और विकल्प उपलब्ध होते हैं:
थिंकिंग बजट: थिंकिंग बजट का इस्तेमाल करके, यह कॉन्फ़िगर किया जा सकता है कि कोई मॉडल "सोचने" में कितना समय ले सकता है. अगर कम लेटेंसी या कम लागत आपकी प्राथमिकता है, तो यह कॉन्फ़िगरेशन खास तौर पर ज़रूरी है. इसके अलावा, टास्क की मुश्किलों की तुलना करके देखें. इससे यह तय करने में मदद मिलेगी कि किसी मॉडल को सोचने-समझने की क्षमता की कितनी ज़रूरत पड़ सकती है.
सोच के बारे में खास जानकारी: जनरेट किए गए जवाब में सोच के बारे में खास जानकारी को शामिल करने के लिए, इसे चालू किया जा सकता है. ये खास जानकारी, मॉडल के रॉ थॉट के सिंथेसाइज़ किए गए वर्शन होते हैं. इनसे मॉडल की इंटरनल रीज़निंग प्रोसेस के बारे में अहम जानकारी मिलती है.
सोच के सिग्नेचर: Firebase AI Logic SDK टूल, आपके लिए सोच के सिग्नेचर को अपने-आप मैनेज करते हैं. इससे यह पक्का होता है कि मॉडल के पास पिछले टर्न से सोच के कॉन्टेक्स्ट का ऐक्सेस है. ऐसा खास तौर पर तब होता है, जब फ़ंक्शन कॉलिंग का इस्तेमाल किया जा रहा हो.
सोचने वाले मॉडल का इस्तेमाल करने के लिए, सबसे सही तरीके और प्रॉम्प्ट से जुड़े दिशा-निर्देश ज़रूर देखें.
सोच-समझकर जवाब देने वाले मॉडल का इस्तेमाल करना
सोचने वाले मॉडल का इस्तेमाल ठीक उसी तरह करें जिस तरह किसी अन्य Gemini मॉडल का इस्तेमाल किया जाता है
(अपनी चुनी गई Gemini API सेवा देने वाली कंपनी को शुरू करें, GenerativeModel
इंस्टेंस बनाएं वगैरह).
इन मॉडल का इस्तेमाल, टेक्स्ट या कोड जनरेट करने से जुड़े टास्क के लिए किया जा सकता है. जैसे, स्ट्रक्चर्ड आउटपुट जनरेट करना या मल्टीमॉडल इनपुट (जैसे, इमेज, वीडियो, ऑडियो या पीडीएफ़) का विश्लेषण करना.
आउटपुट स्ट्रीम करते समय, थिंकिंग मॉडल का भी इस्तेमाल किया जा सकता है.
इस सुविधा के साथ काम करने वाले मॉडल
सिर्फ़ Gemini 2.5 मॉडल में यह सुविधा काम करती है.
gemini-2.5-pro
gemini-2.5-flash
gemini-2.5-flash-lite
सोचने वाले मॉडल का इस्तेमाल करने के सबसे सही तरीके और प्रॉम्प्ट से जुड़े दिशा-निर्देश
हमारा सुझाव है कि आप अपने प्रॉम्प्ट को Google AI Studio या Vertex AI Studio में टेस्ट करें. यहां आपको जवाब जनरेट करने की पूरी प्रोसेस दिखेगी. इससे आपको यह पता चल सकता है कि मॉडल ने किन विषयों पर सही जानकारी नहीं दी है. इससे आपको अपने प्रॉम्प्ट को बेहतर बनाने में मदद मिलेगी, ताकि आपको ज़्यादा सटीक और भरोसेमंद जवाब मिल सकें.
सबसे पहले, एक सामान्य प्रॉम्प्ट लिखें, जिसमें आपको मिलने वाले नतीजे के बारे में बताया गया हो. इसके बाद, मॉडल के शुरुआती विचारों को देखें कि वह जवाब कैसे तय करता है. अगर जवाब आपकी उम्मीद के मुताबिक नहीं है, तो यहाँ दी गई प्रॉम्प्ट देने की तकनीकों का इस्तेमाल करके, मॉडल को बेहतर जवाब जनरेट करने में मदद करें:
- सिलसिलेवार तरीके से निर्देश देना
- इनपुट-आउटपुट पेयर के कई उदाहरण देना
- आउटपुट और जवाबों को किस तरह से फ़ॉर्मैट किया जाना चाहिए, इसके बारे में दिशा-निर्देश देना
- पुष्टि करने के लिए खास चरण उपलब्ध कराना
प्रॉम्प्ट के अलावा, इन सुझावों का इस्तेमाल करें:
सिस्टम के निर्देश सेट करें. ये निर्देश, "प्रीएम्बल" की तरह होते हैं. इन्हें मॉडल को प्रॉम्प्ट या असली उपयोगकर्ता से मिलने वाले किसी भी अन्य निर्देश से पहले जोड़ा जाता है. इनकी मदद से, अपनी ज़रूरतों और इस्तेमाल के उदाहरणों के आधार पर मॉडल के व्यवहार को कंट्रोल किया जा सकता है.
सोचने के लिए बजट सेट करें, ताकि यह कॉन्फ़िगर किया जा सके कि मॉडल कितना सोच सकता है. अगर आपने कम बजट सेट किया है, तो मॉडल अपने जवाब के बारे में "ज़्यादा नहीं सोचेगा". अगर आपने ज़्यादा बजट सेट किया है, तो मॉडल ज़रूरत पड़ने पर ज़्यादा सोच सकता है. सोचने के लिए बजट सेट करने से, जवाब के लिए ज़्यादा टोकन आउटपुट लिमिट भी रिज़र्व हो जाती है.
Firebase कंसोल में एआई मॉनिटरिंग की सुविधा चालू करें. इससे, आपको यह मॉनिटर करने में मदद मिलेगी कि थिंकिंग टोकन की संख्या कितनी है. साथ ही, थिंकिंग की सुविधा चालू होने पर, आपके अनुरोधों में कितना समय लग रहा है. अगर आपने सोच के बारे में जानकारी देने वाली सुविधा चालू की है, तो यह जानकारी कंसोल में दिखेगी. यहां मॉडल के जवाब देने की वजह के बारे में ज़्यादा जानकारी देखी जा सकती है. इससे आपको अपने प्रॉम्प्ट को डीबग करने और बेहतर बनाने में मदद मिलेगी.
सोचने के लिए बजट को कंट्रोल करना
जवाब जनरेट करने के लिए, मॉडल को कितना सोचने की अनुमति है, यह कंट्रोल करने के लिए, थिंकिंग बजट टोकन की संख्या तय की जा सकती है.
उन स्थितियों में मैन्युअल तरीके से थिंकिंग बजट सेट किया जा सकता है जहां आपको डिफ़ॉल्ट थिंकिंग बजट से ज़्यादा या कम टोकन की ज़रूरत हो सकती है. इस सेक्शन में, टास्क की मुश्किलों और सुझाए गए बजट के बारे में ज़्यादा जानकारी पाएं. यहां कुछ सामान्य दिशा-निर्देश दिए गए हैं:
- अगर लेटेंसी कम रखना ज़रूरी है या टास्क कम जटिल हैं, तो सोचने के लिए कम बजट सेट करें
- ज़्यादा मुश्किल कामों के लिए, सोचने-समझने का बजट ज़्यादा सेट करें
सोचने के लिए बजट सेट करना
इस पेज पर, Gemini API उपलब्ध कराने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, उस कंपनी पर क्लिक करें. |
GenerationConfig
इंस्टेंस बनाते समय, थिंकिंग बजट को GenerationConfig
में सेट करें.GenerativeModel
कॉन्फ़िगरेशन, इंस्टेंस के लाइफ़टाइम के लिए सेव रहता है. अगर आपको अलग-अलग अनुरोधों के लिए, अलग-अलग थिंकिंग बजट का इस्तेमाल करना है, तो हर बजट के साथ कॉन्फ़िगर किए गए GenerativeModel
इंस्टेंस बनाएं.
इस सेक्शन में, सोचने के लिए इस्तेमाल किए जा सकने वाले बजट की वैल्यू के बारे में बाद में जानें.
Swift
GenerativeModel
इंस्टेंस बनाते समय, GenerationConfig
में थिंकिंग बजट सेट करें.
// ...
// 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_MODEL_NAME",
generationConfig: generationConfig
)
// ...
Kotlin
GenerativeModel
इंस्टेंस बनाते समय, GenerationConfig
में पैरामीटर की वैल्यू सेट करें.
// ...
// 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_MODEL_NAME",
generationConfig,
)
// ...
Java
GenerativeModel
इंस्टेंस बनाते समय, GenerationConfig
में पैरामीटर की वैल्यू सेट करें.
// ...
// 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_MODEL_NAME",
/* generationConfig */ generationConfig
);
);
// ...
Web
GenerativeModel
इंस्टेंस बनाते समय, GenerationConfig
में पैरामीटर की वैल्यू सेट करें.
// ...
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_MODEL_NAME", generationConfig });
// ...
Dart
GenerativeModel
इंस्टेंस बनाते समय, GenerationConfig
में पैरामीटर की वैल्यू सेट करें.
// ...
// Set the thinking configuration
// Use a thinking budget value appropriate for your model (example value shown here)
final thinkingConfig = ThinkingConfig(thinkingBudget: 1024);
final generationConfig = GenerationConfig(
thinkingConfig: thinkingConfig
);
// Specify the config as part of creating the `GenerativeModel` instance
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
config: generationConfig,
);
// ...
Unity
GenerativeModel
इंस्टेंस बनाते समय, GenerationConfig
में पैरामीटर की वैल्यू सेट करें.
// ...
// 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_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 |
प्रोसेस छिपाएं
कुछ आसान टास्क के लिए, सोचने-समझने की क्षमता की ज़रूरत नहीं होती. इसके लिए, सामान्य अनुमान लगाने की तकनीक काफ़ी होती है. इसके अलावा, अगर लेटेन्सी को कम करना आपकी प्राथमिकता है, तो हो सकता है कि आपको मॉडल को जवाब जनरेट करने में ज़रूरत से ज़्यादा समय न लेने देना हो.
इन स्थितियों में, 'सोच-विचार' सुविधा को बंद किया जा सकता है:
- Gemini 2.5 Pro: सोचने की सुविधा को बंद नहीं किया जा सकता
- Gemini 2.5 Flash:
thinkingBudget
को0
टोकन पर सेट किया गया - Gemini 2.5 Flash‑Lite: सोचने की सुविधा डिफ़ॉल्ट रूप से बंद होती है
डाइनैमिक थिंकिंग की सुविधा चालू करना
thinkingBudget
एट्रिब्यूट की वैल्यू -1
पर सेट करके, मॉडल को यह तय करने की अनुमति दी जा सकती है कि कब और कितना सोचना है. इसे डाइनैमिक थिंकिंग कहा जाता है. मॉडल, ऊपर दी गई टोकन की ज़्यादा से ज़्यादा वैल्यू तक, जितने चाहें उतने टोकन इस्तेमाल कर सकता है.
टास्क की मुश्किल का लेवल
आसान टास्क — सोचने की सुविधा बंद की जा सकती है
ऐसे अनुरोध जिनमें जटिल तर्क की ज़रूरत नहीं होती. जैसे, तथ्यों को ढूंढना या उन्हें कैटगरी में बांटना. उदाहरण:- "DeepMind की स्थापना कहाँ हुई थी?"
- "क्या इस ईमेल में मीटिंग के लिए कहा गया है या सिर्फ़ जानकारी दी गई है?"
मीडियम टास्क — डिफ़ॉल्ट बजट या कुछ अतिरिक्त थिंकिंग बजट की ज़रूरत होती है
सामान्य अनुरोध, जिन्हें चरण-दर-चरण प्रोसेस करने या ज़्यादा समझने से फ़ायदा मिलता है. उदाहरण:- "प्रकाश संश्लेषण और बड़े होने के बीच समानताएं बताओ."
- "इलेक्ट्रिक कारों और हाइब्रिड कारों की तुलना करो."
मुश्किल टास्क — इसके लिए, ज़्यादा से ज़्यादा थिंकिंग बजट की ज़रूरत पड़ सकती है
बेहद मुश्किल चुनौतियाँ, जैसे कि गणित की मुश्किल समस्याओं को हल करना या कोडिंग के टास्क पूरे करना. इस तरह के टास्क के लिए, मॉडल को अपनी पूरी तर्क क्षमता और प्लानिंग की क्षमताओं का इस्तेमाल करना होता है. जवाब देने से पहले, अक्सर इसमें कई इंटरनल चरण शामिल होते हैं. उदाहरण:- "AIME 2025 में पहली समस्या हल करें: उन सभी पूर्णांक आधारों b > 9 का योग ज्ञात करें जिनके लिए 17b, 97b का भाजक है."
- "एक वेब ऐप्लिकेशन के लिए Python कोड लिखो, जो शेयर बाज़ार के रीयल-टाइम डेटा को विज़ुअलाइज़ करता हो. इसमें उपयोगकर्ता की पुष्टि करने की सुविधा भी शामिल हो. इसे ज़्यादा से ज़्यादा असरदार बनाओ."
जवाबों में सोच की खास जानकारी शामिल करना
सोच के बारे में खास जानकारी, मॉडल की ओर से की गई शुरुआती सोच का सिंथेसाइज़ किया गया वर्शन होती है. इससे मॉडल की इंटरनल रीज़निंग प्रोसेस के बारे में अहम जानकारी मिलती है.
जवाबों में सोच के बारे में खास जानकारी शामिल करने की कुछ वजहें यहां दी गई हैं:
आपके पास अपने ऐप्लिकेशन के यूज़र इंटरफ़ेस (यूआई) में सोच के साथ जवाब दिखाने या उन्हें उपयोगकर्ताओं के लिए उपलब्ध कराने का विकल्प होता है. सोच के बारे में जानकारी को जवाब के अलग हिस्से के तौर पर दिखाया जाता है, ताकि आपके पास यह कंट्रोल रहे कि आपके ऐप्लिकेशन में इसका इस्तेमाल कैसे किया जाए.
अगर आपने Firebase कंसोल में एआई मॉनिटरिंग की सुविधा भी चालू की है, तो आपको कंसोल में थॉट समरी दिखेगी. यहां मॉडल के जवाब देने की वजह के बारे में ज़्यादा जानकारी देखी जा सकती है. इससे आपको अपने प्रॉम्प्ट को डीबग करने और उन्हें बेहतर बनाने में मदद मिलेगी.
सोच के बारे में खास जानकारी देने वाली सुविधा के बारे में कुछ ज़रूरी बातें यहां दी गई हैं:
सोचने के लिए तय किए गए बजट से, जवाब तैयार करने की सुविधा को कंट्रोल नहीं किया जाता. बजट सिर्फ़ मॉडल के ओरिजनल जवाबों पर लागू होते हैं. हालांकि, अगर सोचने की सुविधा बंद है, तो मॉडल, जवाब के बारे में जानकारी नहीं देगा.
सोच के बारे में जानकारी को, मॉडल के जनरेट किए गए टेक्स्ट वाले जवाब का हिस्सा माना जाता है. साथ ही, इसे आउटपुट टोकन के तौर पर गिना जाता है.
सोच के बारे में खास जानकारी पाने की सुविधा चालू करना
इस पेज पर, 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('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('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 टूल, स्थिति को मैनेज करके प्रोसेस को आसान बनाते हैं. साथ ही, ये आपके लिए थॉट सिग्नेचर को अपने-आप हैंडल करते हैं. एसडीके, जनरेट किए गए किसी भी थॉट सिग्नेचर को 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}");
}
टोकन गिनने से जुड़ी गाइड में टोकन के बारे में ज़्यादा जानें.