การคิดของ Gemini
โมเดลในซีรีส์ Gemini 3 และ 2.5 ใช้ "กระบวนการคิด" ซึ่งช่วยปรับปรุงความสามารถในการใช้เหตุผลและการวางแผนหลายขั้นตอนได้อย่างมาก ทำให้โมเดลมีประสิทธิภาพสูงสำหรับงานที่ซับซ้อน เช่น การเขียนโค้ด คณิตศาสตร์ขั้นสูง และการวิเคราะห์ข้อมูล
เมื่อคุณใช้โมเดลการคิด Gemini จะใช้เหตุผลภายในก่อนที่จะตอบ Interactions API จะแสดงเหตุผลนี้ผ่านขั้นตอน thought ซึ่งเป็นขั้นตอนเฉพาะที่ปรากฏตามลำดับเวลาควบคู่ไปกับการเรียกใช้ฟังก์ชัน อินพุตของผู้ใช้ หรือเอาต์พุตของโมเดลในอาร์เรย์ steps
ขั้นตอนการคิดแต่ละขั้นตอนจะมี 2 ช่อง ดังนี้
| ช่อง | ต้องระบุ | คำอธิบาย |
|---|---|---|
signature |
✅ ใช่ | การแสดงผลที่เข้ารหัสของสถานะการใช้เหตุผลภายในของโมเดล จะปรากฏอยู่เสมอ แม้ว่าโมเดลจะใช้เหตุผลเพียงเล็กน้อยก็ตาม |
summary |
❌ ไม่ | อาร์เรย์ของเนื้อหา (ข้อความและ/หรือรูปภาพ) ที่สรุปการใช้เหตุผล อาจว่างเปล่า ทั้งนี้ขึ้นอยู่กับการกำหนดค่า thinking_summaries โมเดลใช้การให้เหตุผลเพียงพอหรือไม่ หรือประเภทเนื้อหา (เช่น รูปภาพที่ซ่อนอยู่อาจไม่มีข้อมูลสรุปที่เป็นข้อความ) |
การโต้ตอบกับการคิด
การเริ่มการโต้ตอบกับโมเดลการคิดจะคล้ายกับการส่งคำขอโต้ตอบอื่นๆ ระบุหนึ่งใน โมเดลที่รองรับการคิด ในช่อง model ดังนี้
Python
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Explain the concept of Occam's Razor and provide a simple, everyday example."
)
print(interaction.steps[-1].content[0].text)
JavaScript
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: "Explain the concept of Occam's Razor and provide a simple, everyday example."
});
console.log(interaction.steps.at(-1).content[0].text);
REST
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": "Explain the concept of Occam'\''s Razor and provide a simple example."
}'
คุณสามารถสตรีมการโต้ตอบการคิดเพื่อรับข้อมูลสรุปและลายเซ็นการคิดที่เพิ่มขึ้นระหว่างการสร้าง ดูคำแนะนำที่ครอบคลุมประเภทเหตุการณ์ ประเภทเดลต้า และตัวอย่างโค้ดได้ที่คำแนะนำการโต้ตอบแบบสตรีมมิง Streaming interactions
ข้อมูลสรุปการคิด
ข้อมูลสรุปการคิดจะให้ข้อมูลเชิงลึกเกี่ยวกับกระบวนการให้เหตุผลภายในของโมเดล
โดยค่าเริ่มต้น ระบบจะแสดงเฉพาะเอาต์พุตสุดท้าย คุณสามารถเปิดใช้ข้อมูลสรุปการคิดด้วย thinking_summaries ได้ดังนี้
Python
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
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
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
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
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": "What is the sum of the first 50 prime numbers?",
"generation_config": {
"thinking_summaries": "auto"
}
}'
บล็อกการคิดอาจมีเฉพาะลายเซ็นที่ไม่มีข้อมูลสรุป ในกรณีต่อไปนี้
- คำขออย่างง่ายที่โมเดลใช้เหตุผลไม่เพียงพอที่จะสร้างข้อมูลสรุป
thinking_summaries: "none"ซึ่งปิดใช้ข้อมูลสรุปอย่างชัดแจ้ง- เนื้อหาการคิดบางประเภท เช่น รูปภาพ อาจไม่มีข้อมูลสรุปที่เป็นข้อความ
โค้ดของคุณควรจัดการบล็อกการคิดที่ summary ว่างเปล่าหรือไม่มีอยู่เสมอ
การควบคุมการคิด
โมเดล Gemini จะคิดแบบไดนามิกโดยค่าเริ่มต้น โดยจะปรับความพยายามในการใช้เหตุผลโดยอัตโนมัติตามความซับซ้อนของคำขอ คุณสามารถควบคุมลักษณะการทำงานนี้ได้โดยใช้พารามิเตอร์ thinking_level
| โมเดล | การคิดเริ่มต้น | ระดับที่รองรับ |
|---|---|---|
| gemini-3.1-pro-preview | เปิด (สูง) | ต่ำ ปานกลาง สูง |
| gemini-3-flash-preview | เปิด (สูง) | น้อย ต่ำ ปานกลาง สูง |
| gemini-3-pro-preview | เปิด (สูง) | ต่ำ สูง |
| gemini-2.5-pro | เปิด | ต่ำ ปานกลาง สูง |
| gemini-2.5-flash | เปิด | ต่ำ ปานกลาง สูง |
| gemini-2.5-flash-lite | ปิด | ต่ำ ปานกลาง สูง |
Python
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Provide a list of 3 famous physicists and their key contributions",
generation_config={
"thinking_level": "low"
}
)
print(interaction.steps[-1].content[0].text)
JavaScript
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: "Provide a list of 3 famous physicists and their key contributions",
generation_config: {
thinking_level: "low"
}
});
console.log(interaction.steps.at(-1).content[0].text);
REST
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": "Provide a list of 3 famous physicists and their key contributions",
"generation_config": {
"thinking_level": "low"
}
}'
ลายเซ็นการคิด
ลายเซ็นการคิดเป็นการแสดงผลที่เข้ารหัสของการใช้เหตุผลภายในของโมเดล จำเป็นต้องใช้ลายเซ็นการคิดเพื่อรักษาความต่อเนื่องของการใช้เหตุผลในการโต้ตอบหลายรอบ
Interactions API ช่วยให้การจัดการลายเซ็นการคิดง่ายกว่า generateContent API มาก
โหมด Stateful (แนะนำ)
โดยค่าเริ่มต้น เมื่อคุณใช้ Interactions API ในโหมด Stateful (โดยตั้งค่า store: true และส่ง previous_interaction_id ในรอบถัดไป) เซิร์ฟเวอร์จะจัดการสถานะการสนทนาโดยอัตโนมัติ ซึ่งรวมถึงบล็อกการคิดและลายเซ็นทั้งหมด ในโหมดนี้ คุณไม่จำเป็นต้องดำเนินการใดๆ เกี่ยวกับลายเซ็น เนื่องจากเซิร์ฟเวอร์จะจัดการลายเซ็นทั้งหมด
โหมด Stateless
หากคุณจัดการสถานะการสนทนาด้วยตนเอง (โหมด Stateless) และส่งประวัติอินพุตและเอาต์พุตทั้งหมดในแต่ละคำขอ
- คุณต้อง ส่งบล็อก
thoughtทั้งหมดอีกครั้งตามที่ได้รับจากโมเดลทุกประการ - คุณไม่ควร นำบล็อกการคิดออกจากประวัติหรือแก้ไขบล็อกการคิด เนื่องจากบล็อกการคิดมีลายเซ็นที่โมเดลต้องใช้เพื่อใช้เหตุผลต่อไป
- เมื่อเปลี่ยนโมเดลภายในเซสชัน คุณควรส่งบล็อกการคิดของโมเดลก่อนหน้าอีกครั้ง แบ็กเอนด์จะจัดการความเข้ากันได้
ราคา
เมื่อเปิดการคิด ราคาคำตอบจะเป็นผลรวมของโทเค็นเอาต์พุตและโทเค็นการคิด คุณสามารถดูจำนวนโทเค็นการคิดทั้งหมดที่สร้างขึ้นได้จากช่อง total_thought_tokens
Python
# This will only work for SDK newer than 2.0.0
# ...
print("Thoughts tokens:", interaction.usage.total_thought_tokens)
print("Output tokens:", interaction.usage.total_output_tokens)
JavaScript
// This will only work for SDK newer than 2.0.0
// ...
console.log(`Thoughts tokens: ${interaction.usage.total_thought_tokens}`);
console.log(`Output tokens: ${interaction.usage.total_output_tokens}`);
โมเดลการคิดจะสร้างการคิดแบบเต็มเพื่อปรับปรุงคุณภาพของคำตอบสุดท้าย แล้วแสดงข้อมูลสรุปเพื่อแสดงข้อมูลเชิงลึกเกี่ยวกับกระบวนการคิด ราคาจะอิงตามโทเค็นการคิดแบบเต็มที่โมเดลต้องสร้าง แม้ว่า API จะแสดงเฉพาะข้อมูลสรุปก็ตาม
ดูข้อมูลเพิ่มเติมเกี่ยวกับโทเค็นได้ในคำแนะนำการนับโทเค็น
แนวทางปฏิบัติแนะนำ
ใช้โมเดลการคิดอย่างมีประสิทธิภาพโดยทำตามหลักเกณฑ์ต่อไปนี้
- ตรวจสอบการใช้เหตุผล: วิเคราะห์ข้อมูลสรุปการคิดเพื่อทำความเข้าใจข้อผิดพลาดและปรับปรุงพรอมต์
- ควบคุมงบประมาณการคิด: แจ้งให้โมเดลคิดน้อยลงสำหรับเอาต์พุตที่ยาวเพื่อประหยัดโทเค็น
- งานง่ายๆ: ใช้การคิดน้อยที่สุดสำหรับการดึงข้อมูลข้อเท็จจริงหรือการจัดประเภท (เช่น "DeepMind ก่อตั้งขึ้นที่ไหน")
- งานปานกลาง: ใช้การคิดเริ่มต้นสำหรับการเปรียบเทียบแนวคิดหรือการใช้เหตุผลเชิงสร้างสรรค์ (เช่น เปรียบเทียบรถยนต์ไฟฟ้าและรถยนต์ไฮบริด)
- งานที่ซับซ้อน: ใช้การคิดสูงสุดสำหรับการเขียนโค้ด คณิตศาสตร์ หรือการวางแผนหลายขั้นตอนขั้นสูง (เช่น แก้ปัญหาคณิตศาสตร์ AIME)
ขั้นตอนถัดไป
- การสร้างข้อความ: คำตอบที่เป็นข้อความพื้นฐาน
- การเรียกใช้ฟังก์ชัน: เชื่อมต่อกับเครื่องมือ
- คำแนะนำ Gemini 3: ฟีเจอร์เฉพาะของโมเดล