โมเดลในซีรีส์ Gemini 3 และ 2.5 ใช้ "กระบวนการคิด" ซึ่งช่วยปรับปรุงความสามารถในการใช้เหตุผลและการวางแผนหลายขั้นตอนได้อย่างมาก ทำให้โมเดลมีประสิทธิภาพสูงสำหรับงานที่ซับซ้อน เช่น การเขียนโค้ด คณิตศาสตร์ขั้นสูง และการวิเคราะห์ข้อมูล
เมื่อคุณใช้โมเดลการคิด Gemini จะใช้เหตุผลภายในก่อนที่จะตอบ Interactions API จะแสดงเหตุผลนี้ผ่านขั้นตอน thought ซึ่งเป็นขั้นตอนเฉพาะที่ปรากฏตามลำดับเวลาควบคู่ไปกับการเรียกใช้ฟังก์ชัน อินพุตของผู้ใช้ หรือเอาต์พุตของโมเดลในอาร์เรย์ steps
ขั้นตอนการคิดแต่ละขั้นตอนจะมี 2 ช่อง ดังนี้
| ช่อง | ต้องระบุ | คำอธิบาย |
|---|---|---|
signature |
✅ ใช่ | การแสดงสถานะการให้เหตุผลภายในของโมเดลในรูปแบบที่เข้ารหัส จะปรากฏอยู่เสมอ แม้ว่าโมเดลจะใช้เหตุผลเพียงเล็กน้อยก็ตาม |
summary |
❌ ไม่ | อาร์เรย์ของเนื้อหา (ข้อความและ/หรือรูปภาพ) ที่สรุปเหตุผล อาจว่างเปล่า ทั้งนี้ขึ้นอยู่กับการกำหนดค่า thinking_summaries โมเดลใช้การให้เหตุผลเพียงพอหรือไม่ หรือประเภทเนื้อหา (เช่น รูปภาพที่ซ่อนอยู่อาจไม่มีข้อมูลสรุปที่เป็นข้อความ) |
การโต้ตอบกับการคิด
การเริ่มการโต้ตอบกับโมเดลการคิดจะคล้ายกับการขอโต้ตอบอื่นๆ ระบุหนึ่งใน โมเดลที่รองรับการคิด ในช่อง model ดังนี้
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.6-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.6-flash",
input: "Explain the concept of Occam's Razor and provide a simple, everyday example."
});
console.log(interaction.output_text);
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.6-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.6-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.6-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);
}
}
}
}
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.6-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) ที่มีเดลต้า 2 ประเภทที่แตกต่างกัน ดังนี้
| ประเภทเดลต้า | มี | เวลาที่ส่ง |
|---|---|---|
thought_summary |
เนื้อหาข้อมูลสรุปที่เป็นข้อความหรือรูปภาพ | เดลต้าอย่างน้อย 1 รายการที่มีข้อมูลสรุปแบบเพิ่มทีละน้อย |
thought_signature |
ลายเซ็นการเข้ารหัส | เดลต้าสุดท้ายก่อน step.stop |