تفکر جوزا

مدل‌های سری Gemini 3 و 2.5 از یک «فرآیند تفکر» استفاده می‌کنند که به طور قابل توجهی توانایی‌های استدلال و برنامه‌ریزی چند مرحله‌ای آنها را بهبود می‌بخشد و آنها را برای کارهای پیچیده‌ای مانند کدنویسی، ریاضیات پیشرفته و تجزیه و تحلیل داده‌ها بسیار مؤثر می‌کند.

وقتی از یک مدل تفکر استفاده می‌کنید، Gemini قبل از پاسخ دادن، استدلال درونی می‌کند. API تعاملات این استدلال را از طریق مراحل thought ، مراحل اختصاصی که به ترتیب زمانی در کنار فراخوانی‌های تابع، ورودی‌های کاربر یا خروجی‌های مدل در آرایه steps ظاهر می‌شوند، آشکار می‌کند.

هر گام فکری شامل دو فیلد است:

میدان مورد نیاز توضیحات
signature ✅ بله یک نمایش رمزگذاری‌شده از وضعیت استدلال داخلی مدل. همیشه وجود دارد، حتی زمانی که مدل کمترین استدلال را انجام می‌دهد.
summary ❌ خیر آرایه‌ای از محتوا (متن و/یا تصاویر) که خلاصه‌ای از استدلال را ارائه می‌دهد. بسته به پیکربندی thinking_summaries ، اینکه آیا مدل به اندازه کافی استدلال انجام داده است یا خیر، یا نوع محتوا (برای مثال، تصاویر نهفته ممکن است خلاصه متنی نداشته باشند)، ممکن است خالی باشد.

تعاملات با تفکر

شروع تعامل با یک مدل متفکر مشابه هر درخواست تعامل دیگری است. یکی از مدل‌های دارای پشتیبانی تفکر را در فیلد model مشخص کنید:

پایتون

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.7-flash",
    input="Explain the concept of Occam's Razor and provide a simple, everyday example."
)
print(interaction.output_text)

جاوا اسکریپت

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3.7-flash",
    input: "Explain the concept of Occam's Razor and provide a simple, everyday example."
});
console.log(interaction.output_text);

استراحت

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3.7-flash",
    "input": "Explain the concept of Occam'\''s Razor and provide a simple example."
  }'

خلاصه‌های فکری

خلاصه‌های تفکر، بینش‌هایی در مورد فرآیند استدلال داخلی مدل ارائه می‌دهند. به طور پیش‌فرض، فقط خروجی نهایی بازگردانده می‌شود. می‌توانید خلاصه‌های تفکر را با thinking_summaries فعال کنید:

پایتون

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.7-flash",
    input="What is the sum of the first 50 prime numbers?",
    generation_config={
        "thinking_summaries": "auto"
    }
)

for step in interaction.steps:
    if step.type == "thought":
        print("Thought summary:")
        if step.summary:
            for content_block in step.summary:
                if content_block.type == "text":
                    print(content_block.text)
        print()
    elif step.type == "model_output":
        for content_block in step.content:
            if content_block.type == "text":
                print("Answer:")
                print(content_block.text)
                print()

جاوا اسکریپت

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3.7-flash",
    input: "What is the sum of the first 50 prime numbers?",
    generation_config: {
        thinking_summaries: "auto"
    }
});

for (const step of interaction.steps) {
    if (step.type === "thought") {
        console.log("Thought summary:");
        if (step.summary) {
            for (const contentBlock of step.summary) {
                if (contentBlock.type === "text") console.log(contentBlock.text);
            }
        }
    } else if (step.type === "model_output") {
        for (const contentBlock of step.content) {
            if (contentBlock.type === "text") {
                console.log("Answer:");
                console.log(contentBlock.text);
            }
        }
    }
}

استراحت

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3.7-flash",
    "input": "What is the sum of the first 50 prime numbers?",
    "generation_config": {
      "thinking_summaries": "auto"
    }
  }'

یک انسداد فکری ممکن است در این موارد فقط شامل یک امضا باشد و خلاصه‌ای نداشته باشد :

  • درخواست‌های ساده، که در آن‌ها مدل دلیل کافی برای تولید خلاصه نداشت
  • thinking_summaries: "none" ، که در آن خلاصه‌ها به صراحت غیرفعال هستند
  • برخی از انواع محتوای فکری، مانند تصاویر، ممکن است خلاصه متنی نداشته باشند.

کد شما باید همیشه بلوک‌های فکری را که در آن‌ها summary خالی است یا وجود ندارد، مدیریت کند.

جریان‌سازی با تفکر

از جریان‌سازی برای دریافت خلاصه‌های تدریجی افکار در طول تولید استفاده کنید. بلوک‌های فکری با استفاده از رویدادهای ارسالی از سرور (SSE) با دو نوع دلتای متمایز ارائه می‌شوند:

نوع دلتا شامل هنگام ارسال
thought_summary محتوای خلاصه متن یا تصویر یک یا چند دلتا با خلاصه افزایشی
thought_signature امضای رمزنگاری شده آخرین دلتا قبل از step.stop

پایتون

from google import genai

client = genai.Client()

prompt = """
Alice, Bob, and Carol each live in a different house on the same street: red, green, and blue.
Alice does not live in the red house.
Bob does not live in the green house.
Carol does not live in the red or green house.
Which house does each person live in?
"""

thoughts = ""
answer = ""

stream = client.interactions.create(
    model="gemini-3.7-flash",
    input=prompt,
    generation_config={
        "thinking_summaries": "auto"
    },
    stream=True
)

for event in stream:
    if event.event_type == "step.delta":
        if event.delta.type == "thought_summary":
            if not thoughts:
                print("Thinking...")
            summary_text = event.delta.content.text
            print(f"[Thought] {summary_text}", end="")
            thoughts += summary_text
        elif event.delta.type == "text" and event.delta.text:
            if not answer:
                print("\nAnswer:")
            print(event.delta.text, end="")
            answer += event.delta.text

جاوا اسکریپت

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const prompt = `Alice, Bob, and Carol each live in a different house on the same
street: red, green, and blue. Alice does not live in the red house.
Bob does not live in the green house.
Carol does not live in the red or green house.
Which house does each person live in?`;

let thoughts = "";
let answer = "";

const stream = await client.interactions.create({
    model: "gemini-3.7-flash",
    input: prompt,
    generation_config: {
        thinking_summaries: "auto"
    },
    stream: true
});

for await (const event of stream) {
    if (event.event_type === "step.delta") {
        if (event.delta.type === "thought_summary")