Gemini 2.5 सीरीज़ के मॉडल, एक इंटरनल "थिंकिंग प्रोसेस" का इस्तेमाल करते हैं. इससे, इनकी रीज़निंग और कई चरणों वाली प्लानिंग की क्षमताओं में काफ़ी सुधार होता है. इस वजह से, ये कोडिंग, ऐडवांस मैथमैटिक्स, और डेटा विश्लेषण जैसे मुश्किल टास्क को बेहतर तरीके से पूरा कर पाते हैं.
इस गाइड में, Gemini API का इस्तेमाल करके, Gemini की सोचने की सुविधाओं के साथ काम करने का तरीका बताया गया है.
शुरू करने से पहले
पक्का करें कि आपने थिंकिंग के लिए, 2.5 सीरीज़ के मॉडल का इस्तेमाल किया हो. एपीआई का इस्तेमाल करने से पहले, AI Studio में इन मॉडल को एक्सप्लोर करना आपके लिए फ़ायदेमंद हो सकता है:
सोच-विचार करके कॉन्टेंट जनरेट करना
थिंकिंग मॉडल की मदद से अनुरोध करना, कॉन्टेंट जनरेट करने के लिए किए जाने वाले किसी भी दूसरे अनुरोध जैसा ही है. मुख्य अंतर यह है कि model
फ़ील्ड में, सोचने-समझने की सुविधा वाले मॉडल में से किसी एक को तय करना होता है. इस बारे में, टेक्स्ट जनरेशन के इस उदाहरण में बताया गया है:
from google import genai
client = genai.Client(api_key="GOOGLE_API_KEY")
prompt = "Explain the concept of Occam's Razor and provide a simple, everyday example."
response = client.models.generate_content(
model="gemini-2.5-flash-preview-05-20",
contents=prompt
)
print(response.text)
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: "GOOGLE_API_KEY" });
async function main() {
const prompt = "Explain the concept of Occam's Razor and provide a simple, everyday example.";
const response = await ai.models.generateContent({
model: "gemini-2.5-flash-preview-05-20",
contents: prompt,
});
console.log(response.text);
}
main();
// import packages here
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, option.WithAPIKey(os.Getenv("GOOGLE_API_KEY")))
if err != nil {
log.Fatal(err)
}
defer client.Close()
model := client.GenerativeModel("gemini-2.5-flash-preview-05-20")
resp, err := model.GenerateContent(ctx, genai.Text("Explain the concept of Occam's Razor and provide a simple, everyday example."))
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Text())
}
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [
{
"parts": [
{
"text": "Explain the concept of Occam\''s Razor and provide a simple, everyday example."
}
]
}
]
}'
```
थिंक स्मार्ट की खास जानकारी (एक्सपेरिमेंट के तौर पर उपलब्ध)
'विचार की खास जानकारी' से, मॉडल की अंदरूनी तर्क करने की प्रोसेस के बारे में अहम जानकारी मिलती है. यह सुविधा, मॉडल के तरीके की पुष्टि करने और लंबे टास्क के दौरान उपयोगकर्ताओं को जानकारी देने के लिए अहम हो सकती है. खास तौर पर, जब इसे स्ट्रीमिंग के साथ जोड़ा जाता है.
अपने अनुरोध कॉन्फ़िगरेशन में includeThoughts
को true
पर सेट करके, थिंकिंग की खास जानकारी वाली सुविधा चालू की जा सकती है. इसके बाद, response
पैरामीटर के parts
को दोहराकर और thought
बूलियन की जांच करके, खास जानकारी को ऐक्सेस किया जा सकता है.
यहां एक उदाहरण दिया गया है, जिसमें स्ट्रीमिंग के बिना, 'विचारों की खास जानकारी' सुविधा को चालू करने और उससे जानकारी पाने का तरीका बताया गया है. इस सुविधा से, जवाब के साथ एक ही 'विचारों की खास जानकारी' मिलती है:
from google import genai
from google.genai import types
client = genai.Client(api_key="GOOGLE_API_KEY")
prompt = "What is the sum of the first 50 prime numbers?"
response = client.models.generate_content(
model="gemini-2.5-flash-preview-05-20",
contents=prompt,
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(
include_thoughts=True
)
)
)
for part in response.candidates[0].content.parts:
if not part.text:
continue
if part.thought:
print("Thought summary:")
print(part.text)
print()
else:
print("Answer:")
print(part.text)
print()
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: "GOOGLE_API_KEY" });
async function main() {
const response = await ai.models.generateContent({
model: "gemini-2.5-flash-preview-05-20",
contents: "What is the sum of the first 50 prime numbers?",
config: {
thinkingConfig: {
includeThoughts: true,
},
},
});
for (const part of response.candidates[0].content.parts) {
if (!part.text) {
continue;
}
else if (part.thought) {
console.log("Thoughts summary:");
console.log(part.text);
}
else {
console.log("Answer:");
console.log(part.text);
}
}
}
main();
package main
import (
"context"
"fmt"
"google.golang.org/genai"
"os"
)
func main() {
ctx := context.Background()
client, _ := genai.NewClient(ctx, &genai.ClientConfig{
APIKey: os.Getenv("GOOGLE_API_KEY"),
Backend: genai.BackendGeminiAPI,
})
contents := genai.Text("What is the sum of the first 50 prime numbers?")
model := "gemini-2.5-flash-preview-05-20"
resp, _ := client.Models.GenerateContent(ctx, model, contents, &genai.GenerateContentConfig{
ThinkingConfig: &genai.ThinkingConfig{
IncludeThoughts: true,
},
})
for _, part := range resp.Candidates[0].Content.Parts {
if part.Text != "" {
if part.Thought {
fmt.Println("Thoughts Summary:")
fmt.Println(part.Text)
} else {
fmt.Println("Answer:")
fmt.Println(part.Text)
}
}
}
}
यहां स्ट्रीमिंग के साथ सोचने की सुविधा का इस्तेमाल करने का उदाहरण दिया गया है. यह सुविधा, जनरेट करने के दौरान रोलिंग और बढ़ती हुई खास जानकारी दिखाती है:
from google import genai
from google.genai import types
client = genai.Client(api_key="GOOGLE_API_KEY")
prompt = """
Alice, Bob, and Carol each live in a different house on the same street: red, green, and blue.
The person who lives in the red house owns a cat.
Bob does not live in the green house.
Carol owns a dog.
The green house is to the left of the red house.
Alice does not own a cat.
Who lives in each house, and what pet do they own?
"""
thoughts = ""
answer = ""
for chunk in client.models.generate_content_stream(
model="gemini-2.5-flash-preview-05-20",
contents=prompt,
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(
include_thoughts=True
)
)
):
for part in chunk.candidates[0].content.parts:
if not part.text:
continue
elif part.thought:
if not thoughts:
print("Thoughts summary:")
print(part.text)
thoughts += part.text
else:
if not answer:
print("Thoughts summary:")
print(part.text)
answer += part.text
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: "GOOGLE_API_KEY" });
const prompt = `Alice, Bob, and Carol each live in a different house on the same
street: red, green, and blue. The person who lives in the red house owns a cat.
Bob does not live in the green house. Carol owns a dog. The green house is to
the left of the red house. Alice does not own a cat. Who lives in each house,
and what pet do they own?`;
let thoughts = "";
let answer = "";
async function main() {
const response = await ai.models.generateContentStream({
model: "gemini-2.5-flash-preview-05-20",
contents: prompt,
config: {
thinkingConfig: {
includeThoughts: true,
},
},
});
for await (const chunk of response) {
for (const part of chunk.candidates[0].content.parts) {
if (!part.text) {
continue;
} else if (part.thought) {
if (!thoughts) {
console.log("Thoughts summary:");
}
console.log(part.text);
thoughts = thoughts + part.text;
} else {
if (!answer) {
console.log("Answer:");
}
console.log(part.text);
answer = answer + part.text;
}
}
}
}
await main();
बजट के बारे में सोचना
thinkingBudget
पैरामीटर की मदद से, मॉडल को यह बताया जा सकता है कि जवाब जनरेट करते समय, वह कितने थिंकिंग टोकन का इस्तेमाल कर सकता है. आम तौर पर, ज़्यादा टोकन की संख्या से ज़्यादा जानकारी मिलती है. इससे ज़्यादा मुश्किल टास्क को हल करने में मदद मिलती है.
अगर thinkingBudget
को सेट नहीं किया जाता है, तो अनुरोध की जटिलता के आधार पर मॉडल, बजट में डाइनैमिक तौर पर बदलाव करेगा.
thinkingBudget
,0
से24576
के बीच का पूर्णांक होना चाहिए.- थिंकिंग बजट को
0
पर सेट करने पर, थिंकिंग की सुविधा बंद हो जाती है. - प्रॉम्प्ट के आधार पर, मॉडल टोकन बजट को ओवरफ़्लो या अंडरफ़्लो कर सकता है.
from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash-preview-05-20",
contents="Provide a list of 3 famous physicists and their key contributions",
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_budget=1024)
),
)
print(response.text)
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: "GOOGLE_API_KEY" });
async function main() {
const response = await ai.models.generateContent({
model: "gemini-2.5-flash-preview-05-20",
contents: "Provide a list of 3 famous physicists and their key contributions",
config: {
thinkingConfig: {
thinkingBudget: 1024,
},
},
});
console.log(response.text);
}
main();
package main
import (
"context"
"fmt"
"google.golang.org/genai"
"os"
)
func main() {
ctx := context.Background()
client, _ := genai.NewClient(ctx, &genai.ClientConfig{
APIKey: os.Getenv("GOOGLE_API_KEY"),
Backend: genai.BackendGeminiAPI,
})
thinkingBudgetVal := int32(1024)
contents := genai.Text("Provide a list of 3 famous physicists and their key contributions")
model := "gemini-2.5-flash-preview-05-20"
resp, _ := client.Models.GenerateContent(ctx, model, contents, &genai.GenerateContentConfig{
ThinkingConfig: &genai.ThinkingConfig{
ThinkingBudget: &thinkingBudgetVal,
},
})
fmt.Println(resp.Text())
}
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [
{
"parts": [
{
"text": "Provide a list of 3 famous physicists and their key contributions"
}
]
}
],
"generationConfig": {
"thinkingConfig": {
"thinkingBudget": 1024
}
}
}'
कीमत
सोचने की सुविधा चालू होने पर, जवाब की कीमत, आउटपुट टोकन और सोचने के टोकन का कुल योग होती है. thoughtsTokenCount
फ़ील्ड से, जनरेट किए गए थिंकिंग टोकन की कुल संख्या देखी जा सकती है.
# ...
print("Thoughts tokens:",response.usage_metadata.thoughts_token_count)
print("Output tokens:",response.usage_metadata.candidates_token_count)
// ...
console.log(`Thoughts tokens: ${response.usageMetadata.thoughtsTokenCount}`);
console.log(`Output tokens: ${response.usageMetadata.candidatesTokenCount}`);
// ...
usageMetadata, err := json.MarshalIndent(response.UsageMetadata, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println("Thoughts tokens:", string(usageMetadata.thoughts_token_count))
fmt.Println("Output tokens:", string(usageMetadata.candidates_token_count))
आखिरी जवाब की क्वालिटी को बेहतर बनाने के लिए, थिंकिंग मॉडल पूरी जानकारी जनरेट करते हैं. इसके बाद, सोचने की प्रोसेस के बारे में अहम जानकारी देने के लिए, खास जानकारी दिखाते हैं. इसलिए, कीमत उन सभी टोकन पर आधारित होती है जिन्हें एपीआई से सिर्फ़ खास जानकारी के तौर पर आउटपुट मिलने के बावजूद, खास जानकारी बनाने के लिए मॉडल को जनरेट करना पड़ता है.
टोकन की गिनती के बारे में ज़्यादा जानने के लिए, गाइड देखें.
काम करने वाले मॉडल
मॉडल की खास जानकारी पेज पर, मॉडल की सभी सुविधाएं देखी जा सकती हैं.
मॉडल | सोचने की प्रक्रिया की खास जानकारी | थिंकिंग बजट |
---|---|---|
Gemini 2.5 Flash | ✔️ | ✔️ |
Gemini 2.5 Pro | ✔️ | X |
सबसे सही तरीके
इस सेक्शन में, थिंकिंग मॉडल को बेहतर तरीके से इस्तेमाल करने के लिए कुछ दिशा-निर्देश दिए गए हैं. हमेशा की तरह, प्रॉम्प्ट के लिए दिए गए दिशा-निर्देशों और सबसे सही तरीकों का पालन करने पर, आपको बेहतर नतीजे मिलेंगे.
डीबग करना और स्टीयर करना
तर्क की समीक्षा करना: जब आपको सोचने-समझने वाले मॉडल से अपनी उम्मीद के मुताबिक जवाब नहीं मिल रहा है, तो Gemini के तर्क की प्रोसेस का ध्यान से विश्लेषण करने से मदद मिल सकती है. आपके पास यह देखने का विकल्प होता है कि टास्क को कैसे बांटा गया और उससे क्या नतीजा मिला. साथ ही, सही नतीजे पाने के लिए, उस जानकारी का इस्तेमाल किया जा सकता है.
तर्क के लिए दिशा-निर्देश दें: अगर आपको लंबा आउटपुट चाहिए, तो अपने प्रॉम्प्ट में दिशा-निर्देश दें. इससे, मॉडल को ज़्यादा सोचने से रोका जा सकता है. इससे, अपने जवाब के लिए टोकन आउटपुट का ज़्यादा हिस्सा रिज़र्व किया जा सकता है.
टास्क की जटिलता
- आसान टास्क (सोचने की ज़रूरत नहीं है): ऐसे आसान अनुरोधों के लिए, जहां तर्क की ज़रूरत नहीं होती, जैसे कि तथ्यों को वापस पाना या उन्हें अलग-अलग कैटगरी में बांटना. उदाहरण के लिए:
- "DeepMind की स्थापना कहां हुई थी?"
- "क्या इस ईमेल में मीटिंग का अनुरोध किया गया है या सिर्फ़ जानकारी दी गई है?"
- मध्यम टास्क (डिफ़ॉल्ट/कुछ सोच-विचार): कई सामान्य अनुरोधों को सिलसिलेवार तरीके से प्रोसेस करने या बेहतर तरीके से समझने से फ़ायदा मिलता है. Gemini, इन कामों के लिए, सोचने-समझने की सुविधा का इस्तेमाल कर सकता है:
- प्रकाश संश्लेषण और बड़े होने की प्रक्रिया की तुलना करें.
- इलेक्ट्रिक और हाइब्रिड कारों की तुलना करना.
- मुश्किल टास्क (ज़्यादा से ज़्यादा सोचने की क्षमता): मुश्किल चुनौतियों के लिए, मॉडल को पूरी तरह से तर्क करने और प्लान बनाने की अपनी क्षमताओं का इस्तेमाल करना पड़ता है. अक्सर, जवाब देने से पहले कई इंटरनल चरण पूरे करने पड़ते हैं. उदाहरण के लिए:
- AIME 2025 में पहला सवाल हल करें: उन सभी पूर्णांक के आधारों का योग ज्ञात करें जिनके लिए 17b, 97b का भाजक है और b > 9 है.
- ऐसे वेब ऐप्लिकेशन के लिए Python कोड लिखें जो उपयोगकर्ता की पुष्टि करने के साथ-साथ, रीयल-टाइम स्टॉक मार्केट डेटा को विज़ुअलाइज़ करता हो. इसे ज़्यादा से ज़्यादा असरदार बनाएं.
टूल और सुविधाओं के बारे में सोचना
थिंकिंग मॉडल, Gemini के सभी टूल और सुविधाओं के साथ काम करते हैं. इससे मॉडल, बाहरी सिस्टम के साथ इंटरैक्ट कर सकते हैं, कोड को लागू कर सकते हैं या रीयल-टाइम में जानकारी ऐक्सेस कर सकते हैं. साथ ही, नतीजों को अपनी वजह और आखिरी जवाब में शामिल कर सकते हैं.
खोज टूल की मदद से, मॉडल Google Search से क्वेरी कर सकता है. इससे, मॉडल को अप-टू-डेट जानकारी या ट्रेनिंग डेटा के अलावा अन्य जानकारी मिलती है. यह हाल ही के इवेंट या बहुत खास विषयों के बारे में सवाल पूछने के लिए मददगार है.
कोड चलाने वाला टूल, मॉडल को Python कोड जनरेट और चलाने की सुविधा देता है. इससे, कैलकुलेशन करने, डेटा में बदलाव करने या उन समस्याओं को हल करने में मदद मिलती है जिन्हें एल्गोरिदम की मदद से सबसे बेहतर तरीके से मैनेज किया जा सकता है. मॉडल को कोड का आउटपुट मिलता है और वह इसका इस्तेमाल अपने जवाब में कर सकता है.
स्ट्रक्चर्ड आउटपुट की मदद से, Gemini को JSON फ़ॉर्मैट में जवाब देने के लिए कहा जा सकता है. यह खास तौर पर, ऐप्लिकेशन में मॉडल के आउटपुट को इंटिग्रेट करने के लिए मददगार है.
फ़ंक्शन कॉलिंग, थिंकिंग मॉडल को बाहरी टूल और एपीआई से कनेक्ट करती है, ताकि यह तय किया जा सके कि सही फ़ंक्शन को कब कॉल किया जाए और कौनसे पैरामीटर देने हैं.
थिंकिंग कुकबुक में, थिंकिंग मॉडल के साथ टूल इस्तेमाल करने के उदाहरण देखे जा सकते हैं.
आगे क्या करना है?
ज़्यादा जानकारी वाले उदाहरणों के लिए, जैसे:
- सोच-समझकर टूल इस्तेमाल करना
- स्ट्रीमिंग के दौरान सोच-विचार करना
- अलग-अलग नतीजों के लिए, थिंकिंग बजट में बदलाव करना
और ऐसी ही अन्य चीज़ों के लिए, Thinking cookbook आज़माएं.
थिंकिंग कवरेज की जानकारी, अब OpenAI के साथ काम करने की सुविधा वाली गाइड में उपलब्ध है.
Gemini 2.5 Pro की झलक और Gemini Flash 2.5 Thinking के बारे में ज़्यादा जानने के लिए, मॉडल पेज पर जाएं.