Mô hình mới nhất Các mô hình khác
Gemini 3.5 Flash (gemini-3.5-flash) là một mô hình Flash thế hệ cũ không còn được dùng trong dòng Gemini 3. Các yêu cầu gửi đến gemini-3.5-flash sẽ tự động được chuyển đến Gemini 3.6 Flash. Để biết thông tin về mô hình Flash mới nhất của chúng tôi, hãy xem Gemini 3.8 Flash.
Hướng dẫn này được lưu giữ để tham khảo và ghi lại các thay đổi cơ bản về API Gemini 3.x cũng như các đề xuất về tham số.
Tổng quan về mô hình
| Mô hình | Mã kiểu máy | Trạng thái |
|---|---|---|
| Gemini 3.5 Flash | gemini-3.5-flash |
Không dùng nữa (tự động chuyển đến gemini-3.6-flash). |
Gemini 3.5 Flash hỗ trợ cửa sổ ngữ cảnh 1 triệu token, tối đa 65.000 token đầu ra, khả năng tư duy và cùng một bộ công cụ cũng như các tính năng nền tảng như Gemini 3 Flash, bao gồm cả Sử dụng máy tính (Bản xem trước).
Để biết thông số kỹ thuật đầy đủ, hãy xem phần tổng quan về các mô hình.
Bắt đầu nhanh
Tất cả ví dụ trong hướng dẫn này đều sử dụng Interactions API. API GenerateContent cũng được hỗ trợ; các lựa chọn cấu hình và đề xuất tương tự cũng được áp dụng.
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."
}'
Tính năng mới
- Hiệu suất ổn định: Được tối ưu hoá cho các tác vụ lập trình và tác nhân trên quy mô lớn.
- Thực thi bằng tác nhân: Triển khai tác nhân phụ, giải quyết vấn đề và vòng lặp tác nhân nhanh chóng trên quy mô lớn.
- Lập trình: Các chu kỳ lập trình lặp đi lặp lại, khám phá nhanh và tạo nguyên mẫu để kiểm thử các đường dẫn thay thế và khám phá các giải pháp một cách linh hoạt.
- Tầm nhìn dài hạn: Quy trình làm việc nhiều bước và sử dụng công cụ trên quy mô lớn.
- Lưu giữ các bước suy luận: Mô hình tự động duy trì quá trình suy luận trung gian trong các cuộc trò chuyện nhiều lượt. Không cần thay đổi API.
- Mức độ tư duy mặc định mới: Mức độ tư duy mặc định đã thay đổi từ
highthànhmedium. Hãy xem phần Mức độ nỗ lực mặc định mới để biết thông tin chi tiết. - Cải thiện khả năng tư duy của
low:lowđược cải thiện đáng kể đối với mã và các tác vụ dựa trên tác nhân đòi hỏi ít bước hơn, mang lại chất lượng cao với độ trễ và chi phí thấp hơn.
Chọn mô hình Flash phù hợp
Vì gemini-3.5-flash không được dùng nữa và tự động chuyển đến gemini-3.6-flash, nên bạn nên di chuyển sang một trong các mô hình đang hoạt động sau đây:
- Gemini 3.8 Flash: Mô hình Flash mới nhất và thông minh nhất của chúng tôi, dành cho các quy trình lập trình và tác nhân phức tạp. Xem hướng dẫn về Gemini 3.8 Flash.
- Gemini 3.6 Flash: Thay thế trực tiếp cho
gemini-3.5-flash, giúp giảm mức sử dụng mã thông báo và giảm giá đầu ra. Xem hướng dẫn về Gemini 3.6 Flash và 3.5 Flash-Lite. - Gemini 3.5 Flash-Lite / Gemini 3.1 Flash-Lite: Đối với những tác vụ có chi phí thấp, số lượng lớn và không yêu cầu khả năng suy luận đầy đủ của Flash, hãy sử dụng Gemini 3.5 Flash-Lite hoặc Gemini 3.1 Flash-Lite.
Thay đổi về hành vi
Mức độ nỗ lực mặc định mới: medium
Mức độ tư duy mặc định hiện là medium, thay đổi từ high trong Gemini 3
Flash Preview. medium mang lại kết quả rất tốt cho nhiều loại nhiệm vụ, đồng thời nhanh hơn và tiết kiệm chi phí hơn. Đối với các vấn đề phức tạp, high
khuyến khích mô hình suy nghĩ sâu hơn.
| Mức độ nỗ lực | Trường hợp sử dụng |
|---|---|
minimal |
Tối ưu hoá cho tốc độ phản hồi. Các trường hợp sử dụng giống như trò chuyện, câu trả lời nhanh dựa trên thông tin thực tế, lệnh gọi công cụ đơn giản hơn. |
low |
Mã và các tác vụ dựa trên tác nhân đòi hỏi độ trễ thấp hơn và ít bước hơn. Cũng phù hợp với các công việc phân tích và viết lách đòi hỏi tư duy. |
medium (mặc định) |
Chất lượng tốt nhất cho hầu hết các tác vụ. Nên dùng cho mã phức tạp và các trường hợp sử dụng tác nhân. |
high |
Tối đa hoá khả năng tư duy và sử dụng công cụ của mô hình. Phù hợp nhất cho việc suy luận phức tạp, toán khó và các nhiệm vụ khó nhất về lập trình hoặc tác nhân. Cho phép suy nghĩ mở rộng và gọi hàm. |
Để ghi đè chế độ mặc định, hãy đặt thinking_level trong cấu hình:
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"}
}'
Bảng sau đây cho biết những cấp độ tư duy được hỗ trợ cho mỗi mô hình:
| Cấp độ tư duy | Gemini 3.5 Flash | Gemini 3.1 Pro | Gemini 3.1 Flash-Lite | Gemini 3 Flash | Mô tả |
|---|---|---|---|---|---|
minimal |
Được hỗ trợ | Không được hỗ trợ | Được hỗ trợ (Mặc định) | Được hỗ trợ | Phù hợp với chế độ cài đặt "không suy nghĩ" cho hầu hết các câu hỏi. Xin lưu ý rằng minimal không đảm bảo rằng tính năng suy nghĩ sẽ tắt. Mô hình có thể suy luận rất ít cho các tác vụ phức tạp. |
low |
Được hỗ trợ | Được hỗ trợ | Được hỗ trợ | Được hỗ trợ | Giảm thiểu độ trễ và chi phí. |
medium |
Được hỗ trợ (Mặc định) | Được hỗ trợ | Được hỗ trợ | Được hỗ trợ | Tư duy cân bằng cho hầu hết các nhiệm vụ. |
high |
Được hỗ trợ (Động) | Được hỗ trợ (Mặc định, Động) | Được hỗ trợ (Động) | Được hỗ trợ (Mặc định, Động) | Tối đa hoá độ sâu suy luận. |
Lưu giữ các bước suy luận
Mô hình này tự động duy trì suy luận trung gian trong các cuộc trò chuyện nhiều lượt. Khi có trong nhật ký trò chuyện, bối cảnh suy luận sẽ được chuyển tiếp, giúp cải thiện hiệu suất cho các nhiệm vụ phức tạp gồm nhiều bước như gỡ lỗi lặp lại và tái cấu trúc mã. Không cần thay đổi API:
- Interactions API: Suy nghĩ đã được lưu tự động. Không có thay đổi nào về hành vi.
- GenerateContent API: Bắt đầu từ Gemini 3.5 Flash, mô hình này sẽ sử dụng bối cảnh suy luận từ tất cả các lượt trước đó khi có chữ ký suy nghĩ trong nhật ký trò chuyện. Để bật tính năng này, hãy truyền nhật ký trò chuyện đầy đủ, chưa sửa đổi (bao gồm cả chữ ký suy nghĩ) trong
contents. Các SDK sẽ tự động xử lý việc này.
Nội dung cập nhật về tham số và các phương pháp hay nhất trong Gemini 3.x
Những điều sau đây áp dụng cho tất cả các mô hình Gemini 3.x, bao gồm cả Gemini 3.5 Flash.
temperature,top_p,top_k: bạn không nên thay đổi các giá trị mặc định. Khả năng suy luận của Gemini 3 được tối ưu hoá cho chế độ cài đặt mặc định.- Sử dụng
thinking_levelthay vìthinking_budget. - So khớp phản hồi của lệnh gọi hàm:
id,namevà số lượng phản hồi phải khớp với các lệnh gọi trước đó. - Phản hồi hàm đa phương thức: đưa nội dung đa phương thức vào bên trong phản hồi hàm, chứ không phải bên ngoài phản hồi hàm.
- Hướng dẫn cùng dòng trong phản hồi của hàm: thêm vào văn bản phản hồi của hàm, không phải dưới dạng các phần riêng biệt.
- Giảm số lượng lệnh gọi công cụ không cần thiết: Sử dụng các cấp độ tư duy thấp hơn hoặc thử nghiệm với các chỉ dẫn hệ thống để giảm số lượng lệnh gọi công cụ trong quy trình làm việc dựa trên tác nhân.
Hãy xem các phần bên dưới để biết cách cập nhật mã.
Tham số lấy mẫu (không còn được đề xuất)
temperature, top_p và top_k không còn được đề xuất cho tất cả các mô hình Gemini 3.x. Khả năng suy luận của Gemini 3 được tối ưu hoá cho các chế độ cài đặt mặc định. Xoá các tham số này khỏi tất cả yêu cầu.
# ⚠️ Remove these parameters (not recommended)
generation_config = {
"temperature": 0.7,
"top_p": 0.9,
"top_k": 40,
}
Để đảm bảo tính xác định, bạn nên xác định một chỉ dẫn hệ thống có các quy tắc rõ ràng cho trường hợp sử dụng cụ thể của mình.
thinking_budget (không nên dùng nữa)
Tham số thinking_budget dạng số thô không còn được đề xuất trên tất cả các mô hình Gemini 3.x. Thay vào đó, hãy sử dụng enum chuỗi thinking_level.
# ⚠️ Before (not recommended)
generation_config = {
"thinking": {"thinking_budget": 7500},
}
# ✅ After
generation_config = {
"thinking": {"thinking_level": "medium"},
}
Các giá trị có thể sử dụng: minimal, low, medium (mặc định) và high.
Gọi hàm: so khớp phản hồi nghiêm ngặt
Interactions API đã báo lỗi về các phản hồi hàm không khớp. API GenerateContent hiện chưa báo lỗi, nhưng các phản hồi không khớp sẽ khiến mô hình trả về các phản hồi trống có finish_reason: STOP trong hầu hết các trường hợp. Luôn tuân thủ các quy ước sau:
| Yêu cầu | Thông tin chi tiết |
|---|---|
Bao gồm id |
Mỗi FunctionResponse phải bao gồm id từ FunctionCall tương ứng |
Ván name |
name trong phản hồi phải khớp với name trong lệnh gọi |
| Số lượng trùng khớp | Trả về đúng một FunctionResponse cho mỗi FunctionCall nhận được |
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": "..."}]
}]
}'
Phản hồi đa phương thức của hàm
Chúng tôi thường thấy khách hàng cung cấp hình ảnh bên ngoài phản hồi của hàm. Điều này có thể dẫn đến hành vi không mong muốn của mô hình (ví dụ: rò rỉ suy nghĩ) và dẫn đến kết quả đầu ra có chất lượng thấp hơn. Thay vào đó, hãy làm theo đề xuất trong tài liệu về API Phản hồi hàm đa thức và đưa nội dung đa thức vào các phần phản hồi hàm mà bạn gửi đến mô hình. Mô hình có thể xử lý nội dung đa phương thức này trong lượt tiếp theo để đưa ra câu trả lời chính xác hơn.
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
}
Hướng dẫn cùng dòng trong câu trả lời của hàm
Chúng tôi thường thấy khách hàng cung cấp thêm hướng dẫn cùng với phản hồi của hàm dưới dạng Parts tiếp theo. Điều này có thể dẫn đến hành vi không mong muốn của mô hình (ví dụ: rò rỉ suy nghĩ) và dẫn đến kết quả đầu ra có chất lượng thấp hơn. Thay vào đó, hãy thêm mọi hướng dẫn bổ sung vào cuối văn bản phản hồi của hàm, cách nhau bằng hai dòng mới.
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
}
Giảm số lệnh gọi công cụ không cần thiết
Nếu bạn gặp phải tình trạng sử dụng quá nhiều lệnh gọi công cụ, thì có 2 kỹ thuật giúp giảm thiểu tình trạng này:
Bắt đầu bằng cách giảm cấp độ tư duy (
medium,lowhoặcminimal): Cấp độ tư duy cao hơn khuyến khích mô hình sử dụng nhiều công cụ hơn để khám phá và xác minh, vì vậy, việc giảm cấp độ có thể giảm số lệnh gọi công cụ.Thêm chỉ dẫn hệ thống: Nếu tình trạng sử dụng quá mức vẫn tiếp diễn sau khi điều chỉnh mức độ suy nghĩ, hãy cân nhắc sử dụng câu lệnh hạn chế việc sử dụng công cụ. Ví dụ:
You have a limited action budget of <n> tool calls. Use them efficiently.
Các tính năng của nhóm mô hình Gemini 3
Gemini 3.5 Flash kế thừa tất cả các chức năng của nhóm mô hình Gemini 3, bao gồm cả tính năng Sử dụng máy tính. Các tính năng được giới thiệu trong Gemini 3 và vẫn được duy trì:
- Tư duy: Bối cảnh suy luận được mã hoá được giữ nguyên trong các lệnh gọi API. Tự động trong Interactions API; ngầm trong GenerateContent.
- Kết quả có cấu trúc bằng công cụ: Kết hợp chế độ JSON với các công cụ tích hợp sẵn (Tìm kiếm, Bối cảnh từ URL, thực thi mã, gọi hàm).
- Phản hồi đa phương thức của hàm: Trả về hình ảnh, âm thanh và nội dung nghe nhìn khác trong kết quả gọi hàm.
- Thực thi mã bằng hình ảnh: Thực thi mã xử lý và tạo hình ảnh.
- Sử dụng kết hợp các công cụ: Sử dụng các công cụ tích hợp và tính năng gọi hàm tuỳ chỉnh trong cùng một yêu cầu.
- Độ phân giải của nội dung nghe nhìn:
Kiểm soát chi tiết việc phân bổ mã thông báo cho dữ liệu đầu vào là hình ảnh, video và PDF.
Các mô hình Gemini 3 hỗ trợ chế độ cài đặt độ phân giải cho từng mục nội dung (
low,medium,high,ultra_high) cho câu lệnh có độ chân thực kết hợp. - Chữ ký suy nghĩ: Biểu thị được mã hoá cho suy luận nội bộ của mô hình. Bắt buộc đối với gọi hàm nhiều lượt ở chế độ không có trạng thái; được quản lý tự động bởi Interactions API và SDK chính thức.
Các phương pháp hay nhất để viết câu lệnh
Các mô hình Gemini 3.x là mô hình suy luận, điều này thay đổi cách bạn nên đưa ra câu lệnh.
- Hướng dẫn chính xác: Hãy trình bày ngắn gọn. Gemini 3.x phản hồi tốt nhất với các chỉ dẫn trực tiếp và rõ ràng. Các kỹ thuật thiết kế câu lệnh dài dòng hoặc phức tạp dành cho các mô hình cũ có thể khiến mô hình phân tích quá mức.
- Độ chi tiết của câu trả lời: Theo mặc định, Gemini 3 và 3.1 ít chi tiết hơn và ưu tiên câu trả lời trực tiếp, hiệu quả. Nếu trường hợp sử dụng của bạn yêu cầu giọng điệu trò chuyện, hãy hướng dẫn rõ ràng cho mô hình trong câu lệnh (ví dụ: "Hãy giải thích điều này như một trợ lý thân thiện, thích trò chuyện").
- Quản lý ngữ cảnh: Khi làm việc với các tập dữ liệu lớn (chẳng hạn như toàn bộ sách, cơ sở mã hoặc video dài), hãy đặt hướng dẫn hoặc câu hỏi cụ thể ở cuối câu lệnh, sau ngữ cảnh dữ liệu. Cố định lập luận của mô hình bằng cách bắt đầu câu hỏi bằng một cụm từ như "Dựa trên thông tin trước đó...".
Tìm hiểu thêm về các chiến lược thiết kế câu lệnh trong hướng dẫn kỹ thuật viết câu lệnh.
Các điểm hạn chế
- Gemini 3.x không hỗ trợ tính năng phân đoạn hình ảnh. Đối với các khối lượng công việc phân đoạn, hãy tiếp tục sử dụng Gemini 2.5 Flash khi tắt tính năng tư duy.
Câu hỏi thường gặp
Điểm cắt kiến thức của Gemini 3.5 Flash là gì? Gemini 3.5 Flash có điểm cắt kiến thức là tháng 1 năm 2025. Để biết thêm thông tin mới, hãy sử dụng công cụ Cơ sở tìm kiếm.
Hạn mức cửa sổ ngữ cảnh là bao nhiêu? Gemini 3.5 Flash hỗ trợ cửa sổ ngữ cảnh đầu vào 1 triệu token và tối đa 65.000 token đầu ra.
Mã
thinking_budgetcũ của tôi có còn hoạt động không? Có,thinking_budgetvẫn được hỗ trợ để đảm bảo khả năng tương thích ngược, nhưng bạn nên di chuyển sangthinking_levelđể có hiệu suất dễ dự đoán hơn. Đừng sử dụng cả hai trong cùng một yêu cầu.Gemini 3.5 Flash có hỗ trợ Batch API không? Có. Hãy xem hướng dẫn về Batch API để biết thông tin chi tiết.
Tính năng Lưu vào bộ nhớ đệm ngữ cảnh có được hỗ trợ không? Có, tính năng Lưu bộ nhớ đệm theo ngữ cảnh được hỗ trợ.
Những công cụ nào được hỗ trợ? Gemini 3.5 Flash hỗ trợ Google Tìm kiếm, Neo bám vào Google Maps, Tìm kiếm tệp, Thực thi mã, Bối cảnh từ URL và Gọi hàm tiêu chuẩn, bao gồm cả sử dụng công cụ kết hợp và Sử dụng máy tính.
Các mô hình khác
Bước tiếp theo
- Tìm hiểu thêm về các chiến lược thiết kế câu lệnh trong hướng dẫn kỹ thuật tạo câu lệnh.
- Bắt đầu sử dụng Gemini 3 Cookbook
- Tìm hiểu về quy trình suy luận và tối ưu hoá Gemini API