Gemini 3.5 Flash (gemini-3.5-flash) เป็นโมเดล Flash รุ่นก่อนหน้าในซีรีส์ Gemini 3 ที่เลิกใช้งานแล้ว
ระบบจะกำหนดเส้นทางคำขอไปยัง gemini-3.5-flash โดยอัตโนมัติ
ไปยัง Gemini 3.6 Flash สำหรับโมเดล Flash
ล่าสุด โปรดดู Gemini 3.8 Flash
เราเก็บคู่มือนี้ไว้เพื่อใช้อ้างอิงในอดีตและบันทึกการเปลี่ยนแปลง API ของ Gemini 3.x พื้นฐานและคำแนะนำเกี่ยวกับพารามิเตอร์
ภาพรวมรูปแบบ
| รุ่น | รหัสโมเดล | สถานะ |
|---|---|---|
| Gemini 3.5 Flash | gemini-3.5-flash |
เลิกใช้งาน (เปลี่ยนเส้นทางไปยัง gemini-3.6-flash โดยอัตโนมัติ) |
Gemini 3.5 Flash รองรับหน้าต่างบริบทขนาด 1 ล้านโทเค็น, โทเค็นเอาต์พุตสูงสุด 65,000 รายการ การคิด และชุดเครื่องมือและฟีเจอร์แพลตฟอร์มเดียวกันกับ Gemini 3 Flash รวมถึงการใช้คอมพิวเตอร์ (ตัวอย่าง)
ดูข้อมูลจำเพาะทั้งหมดได้ที่ภาพรวมของโมเดล
คู่มือเริ่มใช้งานฉบับย่อ
ตัวอย่างทั้งหมดในคู่มือนี้ใช้ Interactions API นอกจากนี้ ระบบยังรองรับ GenerateContent API ด้วย โดยจะใช้ตัวเลือกการกำหนดค่าและคำแนะนำเดียวกัน
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.5-flash",
input="Explain how parallel agentic execution works in three sentences."
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const interaction = await client.interactions.create({
model: "gemini-3.5-flash",
input: "Explain how parallel agentic execution works in three sentences.",
});
console.log(interaction.output_text);
}
main();
Java
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.5-flash"))
.input(
InteractionsInput.of(
"Explain how parallel agentic execution works in three sentences."))
.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.5-flash"),
Input: interactions.NewInteractionsInput("Explain how parallel agentic execution works in three sentences."),
}),
})
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.5-flash",
"input": "Explain how parallel agentic execution works in three sentences."
}'
มีอะไรใหม่
- ประสิทธิภาพที่สม่ำเสมอ: ปรับแต่งมาสำหรับงานที่ต้องใช้เอเจนต์และการเขียนโค้ดในวงกว้าง
- การดำเนินการแบบ Agentic: การติดตั้งใช้งาน Agent ย่อย การแก้ปัญหา และลูปแบบ Agentic ที่รวดเร็วในวงกว้าง
- การเขียนโค้ด: วงจรการเขียนโค้ดแบบวนซ้ำ การสำรวจอย่างรวดเร็ว และการสร้างต้นแบบเพื่อ ทดสอบเส้นทางอื่นและสำรวจโซลูชันแบบไดนามิก
- ระยะยาว: เวิร์กโฟลว์แบบหลายขั้นตอนและการใช้เครื่องมือในวงกว้าง
- การเก็บรักษาองค์ความรู้: โมเดลจะคงการให้เหตุผลระดับกลางในการสนทนาไปมาโดยอัตโนมัติ ไม่ต้องเปลี่ยนแปลง API
- ระดับความพยายามเริ่มต้นใหม่: เปลี่ยนการประมวลผลความคิดเริ่มต้นจาก
highเป็นmediumดูรายละเอียดได้ที่ระดับความพยายามเริ่มต้นใหม่ lowการคิดที่ได้รับการปรับปรุง:lowได้รับการปรับปรุงอย่างมากสำหรับโค้ด และงานแบบ Agent ที่ต้องใช้ขั้นตอนน้อยลง โดยมีคุณภาพสูงที่เวลาในการตอบสนองและต้นทุนที่ต่ำลง
การเลือกโมเดล Flash ที่เหมาะสม
เนื่องจากgemini-3.5-flashเลิกใช้งานแล้วและระบบจะเปลี่ยนเส้นทางไปยัง
gemini-3.6-flashโดยอัตโนมัติ เราขอแนะนำให้ย้ายข้อมูลไปยังโมเดลที่ใช้งานอยู่ต่อไปนี้
- Gemini 3.8 Flash: โมเดล Flash ล่าสุดและชาญฉลาดที่สุดของเราสำหรับเวิร์กโฟลว์การเขียนโค้ดและการเป็นตัวแทนที่ซับซ้อน ดูคู่มือ Gemini 3.8 Flash
- Gemini 3.6 Flash: แทนที่
gemini-3.5-flashโดยตรงพร้อมการใช้โทเค็นที่ลดลงและราคาเอาต์พุตที่ต่ำลง ดูคู่มือ Gemini 3.6 Flash และ 3.5 Flash-Lite - Gemini 3.5 Flash-Lite / Gemini 3.1 Flash-Lite: สำหรับงานที่มีปริมาณมากและต้นทุนต่ำซึ่งไม่จำเป็นต้องใช้ความลึกในการให้เหตุผลของ Flash แบบเต็ม ให้ใช้ Gemini 3.5 Flash-Lite หรือ Gemini 3.1 Flash-Lite
การเปลี่ยนแปลงพฤติกรรม
ระดับความพยายามเริ่มต้นใหม่: medium
ตอนนี้การประมวลผลความคิดเริ่มต้นคือ medium ซึ่งเปลี่ยนจาก high ใน Gemini 3 Flash เวอร์ชันตัวอย่าง medium ให้ผลลัพธ์ที่ดีมากในงานที่หลากหลาย
ขณะเดียวกันก็รวดเร็วและประหยัดค่าใช้จ่ายมากขึ้น สำหรับปัญหาที่ซับซ้อน high
จะกระตุ้นให้โมเดลคิดอย่างลึกซึ้งยิ่งขึ้น
| ระดับความพยายาม | กรณีที่ควรใช้ |
|---|---|
minimal |
เพิ่มประสิทธิภาพเพื่อความเร็วในการตอบสนอง กรณีการใช้งานคล้ายแชท คำตอบข้อเท็จจริงแบบรวดเร็ว การเรียกใช้เครื่องมือที่ง่ายขึ้น |
low |
งานด้านโค้ดและงานที่ต้องใช้เอเจนต์ซึ่งต้องมีเวลาในการตอบสนองที่ต่ำกว่าและมีขั้นตอนน้อยกว่า นอกจากนี้ยังเหมาะกับงานวิเคราะห์และงานเขียนที่ต้องใช้ความคิด |
medium (ค่าเริ่มต้น) |
คุณภาพดีที่สุดสำหรับงานส่วนใหญ่ แนะนำสำหรับโค้ดที่ซับซ้อนและกรณีการใช้งานแบบเอเจนต์ |
high |
เพิ่มความสามารถของโมเดลในการคิดและใช้เครื่องมือให้ได้สูงสุด เหมาะที่สุดสำหรับการให้เหตุผลที่ซับซ้อน คณิตศาสตร์ที่ยาก และงานโค้ดหรือเอเจนต์ที่ยากที่สุด อนุญาตให้ใช้ความคิดที่ยาวขึ้นและการเรียกใช้ฟังก์ชัน |
หากต้องการลบล้างค่าเริ่มต้น ให้ตั้งค่า thinking_level ในการกำหนดค่า ดังนี้
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.5-flash",
input="Prove that the square root of 2 is irrational.",
generation_config={"thinking_level": "high"},
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const interaction = await client.interactions.create({
model: "gemini-3.5-flash",
input: "Prove that the square root of 2 is irrational.",
generationConfig: { thinkingLevel: "high" },
});
console.log(interaction.output_text);
}
main();
Java
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.5-flash"))
.input(InteractionsInput.of("Prove that the square root of 2 is irrational."))
.generationConfig(GenerationConfig.builder().thinkingLevel(ThinkingLevel.HIGH).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.5-flash"),
Input: interactions.NewInteractionsInput("Prove that the square root of 2 is irrational."),
GenerationConfig: &interactions.GenerationConfig{
ThinkingLevel: interactions.ThinkingLevelHigh.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.5-flash",
"input": "Prove that the square root of 2 is irrational.",
"generation_config": {"thinking_level": "high"}
}'
ตารางต่อไปนี้แสดงระดับการคิดที่โมเดลแต่ละรายการรองรับ
| ระดับการคิด | Gemini 3.5 Flash | Gemini 3.1 Pro | Gemini 3.1 Flash-Lite | Gemini 3 Flash | คำอธิบาย |
|---|---|---|---|---|---|
minimal |
สิ่งที่ทำได้ | สิ่งที่ทำไม่ได้ | รองรับ (ค่าเริ่มต้น) | สิ่งที่ทำได้ | ตรงกับการตั้งค่า "ไม่ต้องคิด" สำหรับคำค้นหาส่วนใหญ่ โปรดทราบว่า minimal ไม่รับประกันว่าจะปิดการคิด โมเดลอาจให้เหตุผลน้อยมากสำหรับงานที่ซับซ้อน |
low |
สิ่งที่ทำได้ | สิ่งที่ทำได้ | สิ่งที่ทำได้ | สิ่งที่ทำได้ | ลดเวลาในการตอบสนองและค่าใช้จ่าย |
medium |
รองรับ (ค่าเริ่มต้น) | สิ่งที่ทำได้ | สิ่งที่ทำได้ | สิ่งที่ทำได้ | การคิดแบบสมดุลสำหรับงานส่วนใหญ่ |
high |
รองรับ (ไดนามิก) | รองรับ (ค่าเริ่มต้น, ไดนามิก) | รองรับ (ไดนามิก) | รองรับ (ค่าเริ่มต้น, ไดนามิก) | เพิ่มความลึกของการให้เหตุผลสูงสุด |
การเก็บรักษาองค์ความรู้
โมเดลจะคงการให้เหตุผลระดับกลางในการสนทนาไปมาโดยอัตโนมัติ เมื่ออยู่ในประวัติการสนทนา บริบทการให้เหตุผล จะส่งต่อ ซึ่งจะช่วยปรับปรุงประสิทธิภาพในงานที่ซับซ้อนแบบหลายขั้นตอน เช่น การแก้ไขข้อบกพร่องแบบวนซ้ำและการปรับโครงสร้างโค้ด ไม่ต้องเปลี่ยนแปลง API
- Interactions API: ระบบจะเก็บความคิดเห็นไว้โดยอัตโนมัติอยู่แล้ว ไม่มี การเปลี่ยนแปลงลักษณะการทำงาน
- GenerateContent API: ตั้งแต่ Gemini 3.5 Flash เป็นต้นไป โมเดลจะใช้
บริบทการให้เหตุผลจากทุกช่วงก่อนหน้าเมื่อมีลายเซ็นความคิด
ในประวัติการสนทนา หากต้องการเปิดใช้ ให้ส่งประวัติการสนทนาแบบเต็มที่ยังไม่ได้แก้ไข (รวมถึงลายเซ็นความคิด) ใน
contentsSDK จะจัดการเรื่องนี้โดยอัตโนมัติ
การอัปเดตพารามิเตอร์และแนวทางปฏิบัติแนะนำใน Gemini 3.x
ข้อความต่อไปนี้มีผลกับโมเดล Gemini 3.x ทั้งหมด ซึ่งรวมถึง Gemini 3.5 Flash
temperature,top_p,top_k: เราขอแนะนำอย่างยิ่งว่าไม่ควรเปลี่ยน ค่าเริ่มต้น ความสามารถในการให้เหตุผลของ Gemini 3 ได้รับการเพิ่มประสิทธิภาพสำหรับการ การตั้งค่าเริ่มต้น- ให้ใช้
thinking_levelแทนthinking_budget - การจับคู่การตอบกลับการเรียกใช้ฟังก์ชัน:
id,nameและจำนวนการตอบกลับ ต้องตรงกับการเรียกก่อนหน้า - การตอบกลับฟังก์ชันมัลติโมดอล: ใส่เนื้อหามัลติโมดอลไว้ภายใน การตอบกลับฟังก์ชัน ไม่ใช่นอกการตอบกลับ
- วิธีการในบรรทัดในคำตอบของฟังก์ชัน: ต่อท้ายข้อความคำตอบของฟังก์ชัน ไม่ใช่เป็นส่วนแยกต่างหาก
- ลดการเรียกใช้เครื่องมือที่ไม่จำเป็น: ใช้ระดับการคิดที่ต่ำลงหรือทดลอง กับคำสั่งของระบบเพื่อลดการเรียกใช้เครื่องมือในเวิร์กโฟลว์ของเอเจนต์
ดูวิธีอัปเดตโค้ดได้ในส่วนต่างๆ ด้านล่าง
พารามิเตอร์การสุ่มตัวอย่าง (ไม่แนะนำอีกต่อไป)
เราไม่แนะนำให้ใช้ temperature, top_p และ top_k กับโมเดล Gemini 3.x ทั้งหมดอีกต่อไป
ความสามารถในการให้เหตุผลของ Gemini 3 ได้รับการเพิ่มประสิทธิภาพสำหรับการตั้งค่าเริ่มต้น
นำพารามิเตอร์เหล่านี้ออกจากคำขอทั้งหมด
# ⚠️ Remove these parameters (not recommended)
generation_config = {
"temperature": 0.7,
"top_p": 0.9,
"top_k": 40,
}
เราขอแนะนำให้กำหนดคำสั่งของระบบด้วยกฎที่ชัดเจนสำหรับกรณีการใช้งานเฉพาะของคุณเพื่อให้มั่นใจถึงความแน่นอน
thinking_budget (ไม่แนะนำอีกต่อไป)
เราไม่แนะนำให้ใช้พารามิเตอร์ตัวเลขดิบ thinking_budget ในโมเดล Gemini 3.x ทั้งหมดอีกต่อไป
ให้ใช้สตริง Enum thinking_level แทน
# ⚠️ Before (not recommended)
generation_config = {
"thinking": {"thinking_budget": 7500},
}
# ✅ After
generation_config = {
"thinking": {"thinking_level": "medium"},
}
ค่าที่ใช้ได้: minimal, low, medium (ค่าเริ่มต้น) และ high
การเรียกใช้ฟังก์ชัน: การจับคู่คำตอบที่เข้มงวด
ปัจจุบัน Interactions API จะแสดงข้อผิดพลาดเมื่อการตอบกลับฟังก์ชันไม่ตรงกัน API ของ GenerateContent ยังไม่แสดงข้อผิดพลาด แต่การตอบกลับที่ไม่ตรงกันจะทำให้โมเดล
แสดงการตอบกลับที่ว่างเปล่าพร้อม finish_reason: STOP ในกรณีส่วนใหญ่ โปรดปฏิบัติตาม
รูปแบบต่อไปนี้เสมอ
| ข้อกำหนด | รายละเอียด |
|---|---|
รวม id |
FunctionResponse ทุกรายการต้องมี id จาก FunctionCall ที่เกี่ยวข้อง |
แมตช์ที่ name |
name ในการตอบกลับต้องตรงกับ name ในการเรียก |
| จำนวนการจับคู่ที่ตรงกัน | ส่งคืน FunctionResponse 1 รายการสำหรับ FunctionCall แต่ละรายการที่ได้รับ |
Python
# ✅ Include matching call_id and name in the function_result
final_interaction = client.interactions.create(
model="gemini-3.5-flash",
previous_interaction_id=interaction.id,
tools=[my_tool],
input=[{
"type": "function_result",
"name": fc_step.name,
"call_id": fc_step.id,
"result": [{"type": "text", "text": json.dumps(result)}],
}],
)
JavaScript
// ✅ Include matching call_id and name in the function_result
const finalInteraction = await client.interactions.create({
model: "gemini-3.5-flash",
previousInteractionId: interaction.id,
tools: [myTool],
input: [{
type: "function_result",
name: fcStep.name,
call_id: fcStep.id,
result: [{ type: "text", text: JSON.stringify(result) }],
}],
});
Java
import java.util.Arrays;
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Function;
import com.google.genai.gaos.models.interactions.FunctionResultStep;
import com.google.genai.gaos.models.interactions.FunctionResultStepResultUnion;
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.TextContent;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
Client client = new Client();
// Assumes interactionId, callId, functionName, myTool, and resultJson from previous step
String interactionId = "interaction-id-123";
String callId = "call-id-123";
String functionName = "get_weather";
Function myTool = Function.builder().name(functionName).build();
String resultJson = "{\"temperature\": \"72F\"}";
// ✅ Include matching callId and name in the FunctionResultStep
FunctionResultStep functionResult =
FunctionResultStep.builder()
.name(functionName)
.callId(callId)
.result(
FunctionResultStepResultUnion.of(
Arrays.asList(TextContent.builder().text(resultJson).build())))
.build();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.5-flash"))
.previousInteractionId(interactionId)
.tools(Arrays.asList(myTool))
.input(InteractionsInput.ofStep(Arrays.asList(functionResult)))
.build();
Interaction finalInteraction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
Go
package main
import (
"context"
"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)
}
// Assumes interactionID, callID, functionName, myTool, and resultJSON from previous step
interactionID := "interaction-id-123"
callID := "call-id-123"
functionName := "get_weather"
myTool := interactions.NewTool(interactions.Function{Name: genai.Ptr(functionName)})
resultJSON := `{"temperature": "72F"}`
// ✅ Include matching CallID and Name in the FunctionResultStep
functionResult := interactions.NewStep(interactions.FunctionResultStep{
Name: genai.Ptr(functionName),
CallID: callID,
Result: interactions.NewFunctionResultStepResultUnion([]interactions.FunctionResultSubcontent{
interactions.NewFunctionResultSubcontent(interactions.TextContent{Text: resultJSON}),
}),
})
finalRes, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.5-flash"),
PreviousInteractionID: genai.Ptr(interactionID),
Tools: []interactions.Tool{myTool},
Input: interactions.NewInteractionsInput([]interactions.Step{functionResult}),
}),
})
if err != nil {
log.Fatal(err)
}
_ = finalRes
}
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.5-flash",
"previous_interaction_id": "<INTERACTION_ID>",
"tools": [...],
"input": [{
"type": "function_result",
"name": "my_function",
"call_id": "<CALL_ID>",
"result": [{"type": "text", "text": "..."}]
}]
}'
คำตอบฟังก์ชันหลายรูปแบบ
เรามักเห็นลูกค้าให้รูปภาพนอกการตอบกลับฟังก์ชัน ซึ่งอาจทำให้โมเดลทำงานโดยไม่คาดคิด (เช่น การรั่วไหลของความคิด) และส่งผลให้เอาต์พุตมีคุณภาพต่ำลง โปรดทำตามคำแนะนำในเอกสารประกอบเกี่ยวกับ API การตอบกลับฟังก์ชันมัลติโมดัล แทน และรวมเนื้อหามัลติโมดัลไว้ในส่วนการตอบกลับฟังก์ชันที่คุณ ส่งไปยังโมเดล โมเดลสามารถประมวลผลเนื้อหามัลติโมดอลนี้ในรอบถัดไป เพื่อสร้างคำตอบที่แม่นยำยิ่งขึ้น
Python
# ✅ Include multimodal content in the function response
final_interaction = client.interactions.create(
model="gemini-3.5-flash",
previous_interaction_id=interaction.id,
input=[
{
"type": "function_result",
"name": tool_call.name,
"call_id": tool_call.id,
"result": [
{"type": "text", "text": "instrument.jpg"},
{
"type": "image",
"mime_type": "image/jpeg",
"data": base64_image_data,
},
],
}
],
)
JavaScript
// ✅ Include multimodal content in the function response
const finalInteraction = await client.interactions.create({
model: "gemini-3.5-flash",
previousInteractionId: interaction.id,
input: [{
type: "function_result",
name: toolCall.name,
call_id: toolCall.id,
result: [
{ type: "text", text: "instrument.jpg" },
{
type: "image",
mime_type: "image/jpeg",
data: base64ImageData,
},
],
}],
});
Java
import java.util.Arrays;
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.FunctionResultStep;
import com.google.genai.gaos.models.interactions.FunctionResultStepResultUnion;
import com.google.genai.gaos.models.interactions.ImageContent;
import com.google.genai.gaos.models.interactions.ImageContentMimeType;
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.TextContent;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
Client client = new Client();
// Assumes interactionId, callId, functionName, and base64ImageData from previous step
String interactionId = "interaction-id-123";
String callId = "call-id-123";
String functionName = "get_instrument_image";
String base64ImageData = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=";
// ✅ Include multimodal content in the function response
FunctionResultStep functionResult =
FunctionResultStep.builder()
.name(functionName)
.callId(callId)
.result(
FunctionResultStepResultUnion.of(
Arrays.asList(
TextContent.builder().text("instrument.jpg").build(),
ImageContent.builder()
.mimeType(ImageContentMimeType.IMAGE_JPEG)
.data(base64ImageData)
.build())))
.build();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.5-flash"))
.previousInteractionId(interactionId)
.input(InteractionsInput.ofStep(Arrays.asList(functionResult)))
.build();
Interaction finalInteraction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
Go
package main
import (
"context"
"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)
}
// Assumes interactionID, callID, functionName, and base64ImageData from previous step
interactionID := "interaction-id-123"
callID := "call-id-123"
functionName := "get_instrument_image"
base64ImageData := "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
// ✅ Include multimodal content in the function response
functionResult := interactions.NewStep(interactions.FunctionResultStep{
Name: genai.Ptr(functionName),
CallID: callID,
Result: interactions.NewFunctionResultStepResultUnion([]interactions.FunctionResultSubcontent{
interactions.NewFunctionResultSubcontent(interactions.TextContent{
Text: "instrument.jpg",
}),
interactions.NewFunctionResultSubcontent(interactions.ImageContent{
MimeType: interactions.ImageContentMimeType("image/jpeg").ToPointer(),
Data: genai.Ptr(base64ImageData),
}),
}),
})
finalRes, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.5-flash"),
PreviousInteractionID: genai.Ptr(interactionID),
Input: interactions.NewInteractionsInput([]interactions.Step{functionResult}),
}),
})
if err != nil {
log.Fatal(err)
}
_ = finalRes
}
คำสั่งในบรรทัดในคำตอบของฟังก์ชัน
เรามักเห็นลูกค้าให้คำสั่งเพิ่มเติมพร้อมกับการตอบกลับฟังก์ชัน
เป็นParts ซึ่งอาจทำให้โมเดลทำงานโดยไม่คาดคิด (เช่น การรั่วไหลของความคิด) และส่งผลให้เอาต์พุตมีคุณภาพต่ำลง แต่ให้ต่อท้ายคำสั่งเพิ่มเติม
ไว้ที่ท้ายข้อความการตอบกลับของฟังก์ชันโดยคั่นด้วยบรรทัดใหม่ 2 บรรทัด
Python
# ✅ Append inline instructions to the end of the function response separated by two newlines
result_text = f"{json.dumps(result)}\n\n<your inline instructions>"
final_interaction = client.interactions.create(
model="gemini-3.5-flash",
previous_interaction_id=interaction.id,
tools=[my_tool],
input=[{
"type": "function_result",
"name": fc_step.name,
"call_id": fc_step.id,
"result": [{"type": "text", "text": result_text}],
}],
)
JavaScript
// ✅ Append inline instructions to the end of the function response separated by two newlines
const resultText = `${JSON.stringify(result)}\n\n<your inline instructions>`;
const finalInteraction = await client.interactions.create({
model: "gemini-3.5-flash",
previousInteractionId: interaction.id,
tools: [myTool],
input: [{
type: "function_result",
name: fcStep.name,
call_id: fcStep.id,
result: [{ type: "text", text: resultText }],
}],
});
Java
import java.util.Arrays;
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Function;
import com.google.genai.gaos.models.interactions.FunctionResultStep;
import com.google.genai.gaos.models.interactions.FunctionResultStepResultUnion;
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.TextContent;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.List;
Client client = new Client();
// Assumes interactionId, callId, functionName, myTool, and resultJson from previous step
String interactionId = "interaction-id-123";
String callId = "call-id-123";
String functionName = "get_weather";
Function myTool = Function.builder().name(functionName).build();
String resultJson = "{\"temperature\": \"72F\"}";
// ✅ Append inline instructions to the end of the function response separated by two newlines
String resultText = resultJson + "\n\n<your inline instructions>";
FunctionResultStep functionResult =
FunctionResultStep.builder()
.name(functionName)
.callId(callId)
.result(
FunctionResultStepResultUnion.of(
Arrays.asList(TextContent.builder().text(resultText).build())))
.build();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.5-flash"))
.previousInteractionId(interactionId)
.tools(Arrays.asList(myTool))
.input(InteractionsInput.ofStep(Arrays.asList(functionResult)))
.build();
Interaction finalInteraction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
Go
package main
import (
"context"
"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)
}
// Assumes interactionID, callID, functionName, myTool, and resultJSON from previous step
interactionID := "interaction-id-123"
callID := "call-id-123"
functionName := "get_weather"
myTool := interactions.NewTool(interactions.Function{Name: genai.Ptr(functionName)})
resultJSON := `{"temperature": "72F"}`
// ✅ Append inline instructions to the end of the function response separated by two newlines
resultText := resultJSON + "\n\n<your inline instructions>"
functionResult := interactions.NewStep(interactions.FunctionResultStep{
Name: genai.Ptr(functionName),
CallID: callID,
Result: interactions.NewFunctionResultStepResultUnion([]interactions.FunctionResultSubcontent{
interactions.NewFunctionResultSubcontent(interactions.TextContent{Text: resultText}),
}),
})
finalRes, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.5-flash"),
PreviousInteractionID: genai.Ptr(interactionID),
Tools: []interactions.Tool{myTool},
Input: interactions.NewInteractionsInput([]interactions.Step{functionResult}),
}),
})
if err != nil {
log.Fatal(err)
}
_ = finalRes
}
ลดการเรียกใช้เครื่องมือที่ไม่จำเป็น
หากพบว่ามีการเรียกใช้เครื่องมือมากเกินไป เทคนิค 2 อย่างต่อไปนี้จะช่วยลดการเรียกใช้เครื่องมือได้
เริ่มต้นด้วยการลดระดับการคิด (
medium,lowหรือminimal) ระดับการคิดที่สูงขึ้นจะกระตุ้นให้โมเดลใช้เครื่องมือมากขึ้นเพื่อสำรวจและ ยืนยัน ดังนั้นการลดระดับจึงช่วยลดการเรียกใช้เครื่องมือได้เพิ่มคำสั่งของระบบ: หากยังคงมีการใช้งานมากเกินไปหลังจากปรับ ระดับการคิด ให้พิจารณาใช้พรอมต์ที่จำกัดการใช้เครื่องมือ เช่น
You have a limited action budget of <n> tool calls. Use them efficiently.
ฟีเจอร์ของตระกูล Gemini 3
Gemini 3.5 Flash สืบทอดความสามารถทั้งหมดของตระกูล Gemini 3 ซึ่งรวมถึงการใช้คอมพิวเตอร์ ฟีเจอร์ที่เปิดตัวใน Gemini 3 ซึ่งจะยังคงมีต่อไป
- การคิด: เข้ารหัส บริบทการให้เหตุผลจะยังคงอยู่ในการเรียก API อัตโนมัติใน Interactions API; โดยนัยใน GenerateContent
- เอาต์พุตที่มีโครงสร้างพร้อมเครื่องมือ: รวมโหมด JSON กับ เครื่องมือในตัว (การค้นหา, บริบท URL, การเรียกใช้โค้ด, การเรียกใช้ฟังก์ชัน)
- การตอบกลับฟังก์ชันแบบหลายรูปแบบ: แสดง รูปภาพ เสียง และสื่ออื่นๆ ในผลลัพธ์การเรียกใช้ฟังก์ชัน
- การรันโค้ดด้วยรูปภาพ: รันโค้ดที่ ประมวลผลและสร้างรูปภาพ
- การใช้เครื่องมือร่วมกัน: ใช้เครื่องมือในตัวและ การเรียกใช้ฟังก์ชันที่กำหนดเองในคำขอเดียวกัน
- ความละเอียดของสื่อ:
การควบคุมการจัดสรรโทเค็นอย่างละเอียดสำหรับอินพุตรูปภาพ วิดีโอ และ PDF
โมเดล Gemini 3 รองรับการตั้งค่าความละเอียดต่อรายการเนื้อหา (
low,medium,high,ultra_high) สำหรับพรอมต์ที่มีความเที่ยงตรงแบบผสม - ลายเซ็นความคิด: การแสดงการให้เหตุผลภายในของโมเดลที่เข้ารหัส ต้องใช้สำหรับการเรียกใช้ฟังก์ชันแบบการสนทนาไปมาในโหมดแบบไม่เก็บสถานะ ซึ่งจัดการโดยอัตโนมัติโดย Interactions API และ SDK อย่างเป็นทางการ
แนวทางปฏิบัติแนะนำในการเขียนพรอมต์
โมเดล Gemini 3.x เป็นโมเดลการให้เหตุผล ซึ่งจะเปลี่ยนวิธีที่คุณควรใช้พรอมต์
- คำสั่งที่แม่นยำ: ใช้คำสั่งที่กระชับ Gemini 3.x ตอบสนองต่อคำสั่งที่ชัดเจนและตรงไปตรงมาได้ดีที่สุด เทคนิควิศวกรรมพรอมต์ (Prompt Engineering) ที่ซับซ้อนหรือมีรายละเอียดมากเกินไปซึ่งออกแบบมา สำหรับโมเดลรุ่นเก่าอาจทำให้โมเดลวิเคราะห์มากเกินไป
- ความละเอียดของเอาต์พุต: โดยค่าเริ่มต้น Gemini 3 และ 3.1 จะมีความละเอียดน้อยกว่าและชอบ คำตอบที่ตรงไปตรงมาและมีประสิทธิภาพ หาก Use Case ของคุณต้องใช้โทนการสนทนา ให้ชี้นำโมเดลอย่างชัดเจนในพรอมต์ (เช่น "อธิบายเรื่องนี้ในฐานะ ผู้ช่วยที่เป็นมิตรและช่างพูด")
- การจัดการบริบท: เมื่อทำงานกับชุดข้อมูลขนาดใหญ่ (เช่น หนังสือทั้งเล่ม ฐานโค้ด หรือวิดีโอยาว) ให้วางคำสั่งหรือคำถามที่เฉพาะเจาะจงไว้ท้ายพรอมต์หลังจากบริบทข้อมูล ยึดตรรกะของโมเดลโดยเริ่มคำถามด้วยวลี เช่น "จากข้อมูลก่อนหน้า..."
ดูข้อมูลเพิ่มเติมเกี่ยวกับกลยุทธ์การออกแบบพรอมต์ได้ในคู่มือวิศวกรรมพรอมต์ (Prompt Engineering)
ข้อจำกัด
- Gemini 3.x ไม่รองรับการแบ่งกลุ่มรูปภาพ สำหรับเวิร์กโหลดการแบ่งกลุ่ม ให้ใช้ Gemini 2.5 Flash ต่อไปโดยปิดการคิด
คำถามที่พบบ่อย
วันที่ความรู้ล่าสุดของ Gemini 3.5 Flash คือวันใด Gemini 3.5 Flash มีการตัดข้อมูลความรู้ ณ เดือนมกราคม 2025 ดูข้อมูลล่าสุดได้ที่เครื่องมือการอ้างอิงของ Search
ขีดจำกัดของหน้าต่างบริบทคืออะไร Gemini 3.5 Flash รองรับหน้าต่างบริบทของอินพุตขนาด 1 ล้านโทเค็นและโทเค็นเอาต์พุตสูงสุด 65,000 โทเค็น
thinking_budgetโค้ดเก่าของฉันจะยังใช้งานได้ไหม ได้thinking_budgetยังคงรองรับความเข้ากันได้แบบย้อนหลัง แต่เราขอแนะนำให้ย้ายข้อมูลไปยังthinking_levelเพื่อประสิทธิภาพที่คาดการณ์ได้มากขึ้น แต่อย่าใช้ทั้ง 2 อย่างในคำขอเดียวกันGemini 3.5 Flash รองรับ Batch API ไหม ได้ ดูรายละเอียดได้ที่คู่มือ Batch API
ฟีเจอร์นี้รองรับการแคชบริบทไหม ได้ ระบบรองรับการแคชบริบท
เครื่องมือใดบ้างที่รองรับ Gemini 3.5 Flash รองรับ Google Search การเชื่อมต่อแหล่งข้อมูลกับ Google Maps การค้นหาไฟล์ การเรียกใช้โค้ด บริบท URL และ การเรียกใช้ฟังก์ชันมาตรฐาน รวมถึง การใช้เครื่องมือร่วมกัน และ การใช้คอมพิวเตอร์
รุ่นอื่นๆ
ขั้นตอนถัดไป
- ดูข้อมูลเพิ่มเติมเกี่ยวกับกลยุทธ์การออกแบบพรอมต์ได้ในคู่มือวิศวกรรมพรอมต์ (Prompt Engineering)
- เริ่มต้นใช้งาน Gemini 3 Cookbook
- ดูข้อมูลเกี่ยวกับการเพิ่มประสิทธิภาพและการอนุมานของ Gemini API