تستخدم نماذج Gemini "عملية تفكير" تحسّن بشكل كبير قدراتها على الاستدلال والتخطيط المتعدّد الخطوات، ما يجعلها فعّالة للغاية في المهام المعقّدة، مثل الترميز والرياضيات المتقدّمة وتحليل البيانات.
عند استخدام نموذج التفكير، يحلّل Gemini طلبك داخليًا قبل الردّ. تعرض Interactions API هذا المنطق من خلال thought خطوات، وهي خطوات مخصّصة تظهر بترتيب زمني إلى جانب استدعاءات الدوال أو إدخالات المستخدم أو مخرجات النموذج في مصفوفة steps.
تحتوي كل خطوة تفكير على حقلَين:
| الحقل | مطلوب أو اختياري | الوصف |
|---|---|---|
signature |
✅ نعم | تمثيل مشفّر لحالة الاستدلال الداخلي للنموذج تظهر دائمًا، حتى عندما ينفّذ النموذج الحد الأدنى من الاستدلال. |
summary |
❌ لا | مصفوفة من المحتوى (نص و/أو صور) تلخّص الاستدلال. قد يكون هذا الحقل فارغًا استنادًا إلى إعدادات thinking_summaries، أو ما إذا كان النموذج قد قدّم أسبابًا كافية، أو نوع المحتوى (على سبيل المثال، قد لا تتضمّن الصور الكامنة ملخّصات نصية). |
التفاعلات مع ميزة "المفكّر"
تشبه عملية بدء تفاعل مع نموذج تفكير أي طلب تفاعل آخر. حدِّد أحد النماذج التي تتضمّن ميزة التفكير في حقل model:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Explain the concept of Occam's Razor and provide a simple, everyday example."
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3.8-flash",
input: "Explain the concept of Occam's Razor and provide a simple, everyday example."
});
console.log(interaction.output_text);
جافا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(
InteractionsInput.of(
"Explain the concept of Occam's Razor and provide a simple, everyday example."))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.8-flash"),
Input: interactions.NewInteractionsInput("Explain the concept of Occam's Razor and provide a simple, everyday example."),
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
REST
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.8-flash",
"input": "Explain the concept of Occam'\''s Razor and provide a simple example."
}'
ملخّصات الأفكار
تقدّم ملخّصات الأفكار إحصاءات حول عملية الاستدلال الداخلية للنموذج.
يتم تلقائيًا عرض الناتج النهائي فقط. يمكنك تفعيل ملخّصات التفكير
باستخدام thinking_summaries:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-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()
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3.8-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);
}
}
}
}
جافا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.Content;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.GenerationConfig;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ModelOutputStep;
import com.google.genai.gaos.models.interactions.Step;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.interactions.ThinkingSummaries;
import com.google.genai.gaos.models.interactions.ThoughtStep;
import com.google.genai.gaos.models.interactions.ThoughtSummaryContent;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Collections;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(InteractionsInput.of("What is the sum of the first 50 prime numbers?"))
.generationConfig(
GenerationConfig.builder().thinkingSummaries(ThinkingSummaries.AUTO).build())
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
for (Step step : interaction.steps().orElse(Collections.emptyList())) {
if (step instanceof ThoughtStep thoughtStep) {
System.out.println("Thought summary:");
for (ThoughtSummaryContent contentBlock : thoughtStep.summary().orElse(Collections.emptyList())) {
if (contentBlock instanceof TextContent textContent) {
System.out.println(textContent.text().orElse(""));
}
}
System.out.println();
} else if (step instanceof ModelOutputStep outputStep) {
for (Content contentBlock : outputStep.content().orElse(Collections.emptyList())) {
if (contentBlock instanceof TextContent textContent) {
System.out.println("Answer:");
System.out.println(textContent.text().orElse(""));
System.out.println();
}
}
}
}
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.8-flash"),
Input: interactions.NewInteractionsInput("Provide a list of 3 famous physicists and their key contributions"),
GenerationConfig: &interactions.GenerationConfig{
ThinkingLevel: interactions.ThinkingLevelLow.ToPointer(),
},
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
REST
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.8-flash",
"input": "What is the sum of the first 50 prime numbers?",
"generation_config": {
"thinking_summaries": "auto"
}
}'
قد تحتوي مجموعة الأفكار على توقيع فقط بدون ملخّص في الحالات التالية:
- الطلبات البسيطة التي لم يقدّم فيها النموذج أسبابًا كافية لإنشاء ملخّص
-
thinking_summaries: "none"، حيث يتم إيقاف الملخّصات بشكل صريح - قد لا تتوفّر ملخّصات نصية لبعض أنواع محتوى الأفكار، مثل الصور
يجب أن يتعامل الرمز البرمجي دائمًا مع كتل الأفكار التي يكون فيها summary فارغًا أو غير متوفّر.
البث مع التفكير
استخدِم ميزة البث لتلقّي ملخّصات الأفكار التزايدية أثناء إنشائها. يتم عرض "فقرات الأفكار" باستخدام أحداث Server-Sent Events (SSE) مع نوعَين مختلفَين من التغييرات التفاضلية:
| نوع التغيير | يحتوي على | وقت الإرسال |
|---|---|---|
thought_summary |
محتوى ملخّص نصي أو مرئي | تغيير واحد أو أكثر مع ملخّص تزايدي |
thought_signature |
التوقيع المشفّر | آخر فرق قبل step.stop |
Python
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.8-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
JavaScript
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.8-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") {
if (!thoughts) console.log("Thinking...");
const text = event.delta.content?.text || "";
process.stdout.write(`[Thought] ${text}`);
thoughts += text;
} else if (event.delta.type === "text" && event.delta.text) {
if (!answer) console.log("\nAnswer:");
process.stdout.write(event.delta.text);
answer += event.delta.text;
}
}
}
جافا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.Content;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.GenerationConfig;
import com.google.genai.gaos.models.interactions.InteractionSSEEvent;
import com.google.genai.gaos.models.interactions.InteractionSSEStreamEvent;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.StepDelta;
import com.google.genai.gaos.models.interactions.StepDeltaData;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.interactions.TextDelta;
import com.google.genai.gaos.models.interactions.ThinkingSummaries;
import com.google.genai.gaos.models.interactions.ThoughtSummaryDelta;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import com.google.genai.gaos.models.operations.CreateInteractionResponse;
import com.google.genai.gaos.utils.EventStream;
Client client = new Client();
String prompt =
"Alice, Bob, and Carol each live in a different house on the same street: red, green, and blue.\n"
+ "Alice does not live in the red house.\n"
+ "Bob does not live in the green house.\n"
+ "Carol does not live in the red or green house.\n"
+ "Which house does each person live in?";
StringBuilder thoughts = new StringBuilder();
StringBuilder answer = new StringBuilder();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(InteractionsInput.of(prompt))
.generationConfig(
GenerationConfig.builder().thinkingSummaries(ThinkingSummaries.AUTO).build())
.stream(true)
.build();
CreateInteractionResponse response =
client.interactions.create(CreateInteractionRequestBody.of(params));
try (EventStream<InteractionSSEStreamEvent> stream = response.events()) {
for (InteractionSSEStreamEvent streamEvent : stream) {
InteractionSSEEvent event = streamEvent.data().orElse(null);
if (event instanceof StepDelta stepDelta) {
StepDeltaData delta = stepDelta.delta().orElse(null);
if (delta instanceof ThoughtSummaryDelta thoughtDelta) {
Content content = thoughtDelta.content().orElse(null);
if (content instanceof TextContent textContent) {
if (thoughts.length() == 0) {
System.out.println("Thinking...");
}
String summaryText = textContent.text().orElse("");
System.out.print("[Thought] " + summaryText);
thoughts.append(summaryText);
}
} else if (delta instanceof TextDelta textDelta) {
String text = textDelta.text().orElse("");
if (!text.isEmpty()) {
if (answer.length() == 0) {
System.out.println("\nAnswer:");
}
System.out.print(text);
answer.append(text);
}
}
}
}
}
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.8-flash"),
Input: interactions.NewInteractionsInput("What is the sum of the first 50 prime numbers?"),
GenerationConfig: &interactions.GenerationConfig{
ThinkingLevel: interactions.ThinkingLevelHigh.ToPointer(),
ThinkingSummaries: interactions.ThinkingSummariesAuto.ToPointer(),
},
}),
})
if err != nil {
log.Fatal(err)
}
for _, step := range res.Interaction.Steps {
if thought := step.ThoughtStep; thought != nil {
for _, part := range thought.Summary {
if part.TextContent != nil {
fmt.Printf("Thought summary:\n%s\n\n", part.TextContent.Text)
}
}
}
}
if res.Interaction.OutputText != nil {
fmt.Printf("Answer:\n%s\n", *res.Interaction.OutputText)
}
}
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
--no-buffer \
-d '{
"model": "gemini-3.8-flash",
"input": "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?",
"generation_config": {
"thinking_summaries": "auto"
},
"stream": true
}'
تستخدم الاستجابة المتسلسلة أحداث Server-Sent Events (SSE) وتتألف من خطوات وأحداث، على سبيل المثال:
event: interaction.created
data: {"interaction":{"id":"v1_xxx","status":"in_progress","object":"interaction","model":"gemini-3.8-flash"},"event_type":"interaction.created"}
event: step.start
data: {"index":0,"step":{"signature":"","summary":[{"text":"**Evaluating the clues**\n\nI'm considering...","type":"text"}],"type":"thought"},"event_type":"step.start"}
event: step.delta
data: {"index":0,"delta":{"signature":"EpoGCpcGAXLI2nx/...","type":"thought_signature"},"event_type":"step.delta"}
event: step.stop
data: {"index":0,"event_type":"step.stop"}
event: step.start
data: {"index":1,"step":{"content":[{"text":"Based on the clues provided, here","type":"text"}],"type":"model_output"},"event_type":"step.start"}
event: step.delta
data: {"index":1,"delta":{"text":" is the answer to your question...","type":"text"},"event_type":"step.delta"}
event: step.stop
data: {"index":1,"event_type":"step.stop"}
event: interaction.completed
data: {"interaction":{"id":"v1_xxx","status":"completed","usage":{"total_tokens":530,"total_input_tokens":62,"total_output_tokens":171,"total_thought_tokens":297}},"event_type":"interaction.completed"}
event: done
data: [DONE]
التحكّم في التفكير
تعتمد نماذج Gemini التفكير الديناميكي تلقائيًا، ما يعني أنّها تعدّل تلقائيًا مقدار الجهد المبذول في الاستدلال استنادًا إلى مدى تعقيد الطلب. يمكنك التحكّم في هذا السلوك باستخدام المَعلمة thinking_level.
| الطراز | التفكير التلقائي | المستويات المتاحة |
|---|---|---|
| gemini-4-argon | مفعَّل (متوسط) | منخفض، متوسط، مرتفع |
| gemini-3.8-flash | مفعَّل (متوسط) | منخفض، متوسط، مرتفع |
| gemini-3.6-flash | مفعَّل (متوسط) | الحد الأدنى، منخفض، متوسط، مرتفع |
| gemini-3.5-flash-lite | مفعَّل (بشكل مبسَّط) | الحد الأدنى، منخفض، متوسط، مرتفع |
| gemini-3.1-pro-preview | مفعَّل (مرتفع) | منخفض، متوسط، مرتفع |
| gemini-3.1-flash-lite-image | مفعَّل (بشكل مبسَّط) | بسيطة، عالية |
| gemini-3-flash-preview | مفعَّل (مرتفع) | أدنى، منخفض، متوسط، مرتفع |
| gemini-3-pro-preview | مفعَّل (عالي) | منخفضة، عالية |
| gemini-2.5-pro | مفعّل | منخفض، متوسط، مرتفع |
| gemini-2.5-flash | مفعّل | منخفض، متوسط، مرتفع |
| gemini-2.5-flash-lite | إيقاف | منخفض، متوسط، مرتفع |
| gemini-robotics-er-2-preview | مفعَّل (مرتفع) | الحد الأدنى، منخفض، متوسط، مرتفع |
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Provide a list of 3 famous physicists and their key contributions",
generation_config={
"thinking_level": "low"
}
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3.8-flash",
input: "Provide a list of 3 famous physicists and their key contributions",
generation_config: {
thinking_level: "low"
}
});
console.log(interaction.output_text);
جافا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.GenerationConfig;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ThinkingLevel;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(
InteractionsInput.of(
"Provide a list of 3 famous physicists and their key contributions"))
.generationConfig(GenerationConfig.builder().thinkingLevel(ThinkingLevel.LOW).build())
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.8-pro"),
Input: interactions.NewInteractionsInput("What is the sum of the first 50 prime numbers?"),
GenerationConfig: &interactions.GenerationConfig{
ThinkingLevel: interactions.ThinkingLevelHigh.ToPointer(),
ThinkingSummaries: interactions.ThinkingSummariesAuto.ToPointer(),
},
Stream: genai.Ptr(true),
}),
})
if err != nil {
log.Fatal(err)
}
stream := res.InteractionSSEStreamEvent
defer stream.Close()
for stream.Next() {
event := stream.Value()
if stepDelta := event.GetDataStepDelta(); stepDelta != nil {
if thoughtDelta := stepDelta.GetDeltaThoughtSummary(); thoughtDelta != nil {
if textContent := thoughtDelta.GetContentText(); textContent != nil {
fmt.Printf("[Thought Summary] %s\n", textContent.Text)
}
}
if textDelta := stepDelta.GetDeltaText(); textDelta != nil {
fmt.Print(textDelta.GetText())
}
}
}
if err := stream.Err(); err != nil {
log.Fatal(err)
}
}
REST
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.8-flash",
"input": "Provide a list of 3 famous physicists and their key contributions",
"generation_config": {
"thinking_level": "low"
}
}'
حدود الرموز المميّزة وmax_output_tokens
تحدّد مَعلمة إنشاء الردود max_output_tokens الحد الأقصى لعدد الرموز المميّزة التي يمكن أن ينشئها الردّ، بما في ذلك رموز التفكير المميّزة.
عند ضبط هذه المَعلمة، تعمل كحدّ أقصى صارم تفرضه البنية الأساسية
بدون تغيير طريقة تخصيص النموذج لميزانية التفكير
(thinking_level).
إذا بلغ النموذج هذا الحدّ أثناء الاستدلال، سيتوقف عن إنشاء الرد مع ظهور الحالة "incomplete" وسيعرض ناتجًا مقتضبًا أو فارغًا (مع استمرار تحصيل الرسوم مقابل أي رموز مميّزة للتفكير تم إنشاؤها). لتقليل التكلفة أو وقت الاستجابة بدون اقتطاع الردود، يمكنك خفض قيمة thinking_level (low أو medium) بدلاً من ضبط قيمة صغيرة لـ max_output_tokens.
بالنسبة إلى نماذج Gemini 4 (gemini-4-argon)، يُرجى مراعاة حدود السياق والمخرجات التالية:
- قدرة استيعاب مشتركة تبلغ مليون رمز مميّز: تشترك رموز الإدخال والتفكير والإخراج في قدرة استيعاب واحدة تبلغ مليون رمز مميّز (
1,048,576رمز مميّز). إذا تجاوز مجموع الرموز المميّزة للإدخال وmax_output_tokens1,048,576 رمزًا مميّزًا، ستضع واجهة برمجة التطبيقات تلقائيًا حدًا أقصى لعدد الرموز المميّزة للإخراج يساوي المساحة المتبقية في قدرة الاستيعاب (1,048,576ناقص الرموز المميّزة للإدخال). - الحدّ الأقصى التلقائي لعدد الرموز المميّزة في المخرجات المتزامنة (64 ألف): عند استخدام
background=False(لكل من طلبات البث والطلبات غير المتعلّقة بالبث)، يكون الحدّ الأقصى التلقائي لعدد الرموز المميّزة في المخرجاتmax_output_tokensهو65,536رمز مميّز. يؤدي ضبطmax_output_tokens > 65536باستخدامbackground=Falseإلى ظهور الخطأ400. - فك الترميز الطويل (ما يصل إلى مليون رمز مميّز): للسماح لـ Gemini 4 بالاستدلال وإنشاء أكثر من
65,536رمز مميّز (ما يصل إلى1,048,576رمز مميّز)، اضبطbackground=Trueواضبطmax_output_tokensعلى قيمة أكبر من65,536. لمزيد من التفاصيل، يُرجى الاطّلاع على فك الترميز الطويل.
توقيعات الأفكار
توقيعات الأفكار هي تمثيلات مشفّرة للاستدلال الداخلي للنموذج. ويجب أن تحافظ على استمرارية عملية الاستدلال في التفاعلات المتعددة الأدوار.
تسهّل Interactions API التعامل مع توقيعات الأفكار مقارنةً بواجهة generateContent API.
وضع Stateful (يُنصح به)
بشكل تلقائي، عند استخدام Interactions API في وضع Stateful (من خلال ضبط store: true وتمرير previous_interaction_id في الأدوار اللاحقة)، يدير الخادم تلقائيًا حالة المحادثة، بما في ذلك جميع مجموعات الأفكار والتوقيعات. في هذا الوضع، ليس عليك اتّخاذ أي إجراء بشأن التواقيع. ويتم التعامل معها بالكامل من جهة الخادم.
وضع "عدم حفظ السياق"
إذا كنت تدير حالة المحادثة بنفسك (وضع بدون حالة) وتمرّر السجلّ الكامل للإدخالات والمخرجات في كل طلب:
- يجب دائمًا إعادة إرسال جميع مجموعات بيانات
thoughtكما تم تلقّيها من النموذج تمامًا. - لا تزِل أو تعدِّل "كتل الأفكار" من السجلّ، لأنّها تحتوي على التوقيعات المطلوبة ليواصل النموذج عملية الاستنتاج.
- عند التبديل بين النماذج ضمن جلسة واحدة، يجب إعادة إرسال كتل الأفكار الخاصة بالنموذج السابق. وتتولى الخلفية إدارة التوافق.
الأسعار
عند تفعيل ميزة التفكير، يتم احتساب سعر الردود من خلال جمع الرموز المميّزة للمخرجات
والرموز المميّزة للتفكير. يمكنك الحصول على إجمالي عدد الرموز المميّزة للتفكير التي تم إنشاؤها من الحقل total_thought_tokens.
Python
print("Thoughts tokens:", interaction.usage.total_thought_tokens)
print("Output tokens:", interaction.usage.total_output_tokens)
JavaScript
console.log(`Thoughts tokens: ${interaction.usage.total_thought_tokens}`);
console.log(`Output tokens: ${interaction.usage.total_output_tokens}`);
جافا
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.Usage;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(InteractionsInput.of("Explain the concept of Occam's Razor."))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
if (interaction.usage().isPresent()) {
Usage usage = interaction.usage().get();
System.out.println("Thoughts tokens: " + usage.totalThoughtTokens().orElse(0));
System.out.println("Output tokens: " + usage.totalOutputTokens().orElse(0));
}
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
// Turn 1: Execute a reasoning + tool use interaction
turn1, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.8-pro"),
Input: interactions.NewInteractionsInput("Compare the GDP growth of Japan and Germany in 2025."),
Tools: []interactions.Tool{
interactions.NewTool(interactions.GoogleSearch{}),
},
GenerationConfig: &interactions.GenerationConfig{
ThinkingLevel: interactions.ThinkingLevelHigh.ToPointer(),
},
}),
})
if err != nil {
log.Fatal(err)
}
// Turn 2: Pass PreviousInteractionID so thought signatures are automatically preserved
turn2, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.8-pro"),
PreviousInteractionID: turn1.Interaction.ID,
Input: interactions.NewInteractionsInput("Now summarize that comparison in a 3-row markdown table."),
}),
})
if err != nil {
log.Fatal(err)
}
if turn2.Interaction.OutputText != nil {
fmt.Println(*turn2.Interaction.OutputText)
}
}
تنشئ نماذج التفكير أفكارًا كاملة لتحسين جودة الرد النهائي، ثم تعرض ملخّصات لتقديم نظرة ثاقبة حول عملية التفكير. تستند الأسعار إلى الرموز المميزة الكاملة التي يحتاج إليها النموذج لإنشاء الأفكار، على الرغم من أنّ الملخّص فقط هو الناتج من واجهة برمجة التطبيقات.
يمكنك الاطّلاع على مزيد من المعلومات حول الرموز المميّزة في دليل احتساب الرموز المميّزة.
أفضل الممارسات
يمكنك استخدام النماذج المفكِّرة بكفاءة من خلال اتّباع الإرشادات التالية.
- مراجعة الاستدلال: يمكنك تحليل ملخّصات التفكير لفهم الأخطاء وتحسين الطلبات.
- التحكّم في ميزانية التفكير: يمكنك توجيه النموذج للتفكير بشكل أقل في الردود الطويلة لتوفير الرموز المميّزة.
- المهام البسيطة: استخدام الحد الأدنى من التفكير أو التفكير البسيط لاسترجاع الحقائق أو تصنيفها (مثل "أين تأسست شركة DeepMind؟")
- المهام المعتدلة: استخدِم التفكير التلقائي لمقارنة المفاهيم أو التفكير الإبداعي (مثلاً، مقارنة السيارات الكهربائية والسيارات الهجينة).
- المهام المعقّدة: يمكنك استخدام الحد الأقصى من التفكير في الترميز المتقدّم أو الرياضيات أو التخطيط المتعدّد الخطوات (مثلاً، حلّ مسائل الرياضيات في مسابقة AIME).
الخطوات التالية
- إنشاء النص: الردود النصية الأساسية
- استدعاء الدالة: الربط بالأدوات
- دليل Gemini 4: الميزات الجديدة في Gemini 4
- دليل Gemini 3: ميزات خاصة بالنموذج