ในการเรียกใช้โมเดลแต่ละครั้ง คุณสามารถส่งการกำหนดค่าโมเดลเพื่อควบคุมวิธีที่โมเดลสร้างคำตอบได้
แต่ละโมเดลรองรับตัวเลือกการกำหนดค่าที่แตกต่างกัน
เช่น การตั้งค่า maxOutputTokens หรือการกำหนดค่าเฉพาะสำหรับการคิด
รูปแบบการตอบสนอง รูปภาพ หรือคำพูด
สำหรับกรณีการใช้งานส่วนใหญ่เมื่อเข้าถึงโมเดล Gemini คุณจะ
กำหนดค่าโมเดลโดยใช้ GenerationConfig แต่หากกำหนดค่า
Gemini Live API คุณจะต้องใช้ LiveGenerationConfig
หน้านี้แสดงวิธีกำหนดค่าสำหรับโมเดล Gemini และ อธิบายพารามิเตอร์แต่ละรายการ
ไปที่ Geminiการกำหนดค่า ไปที่ Gemini Live APIการกำหนดค่า
GenerationConfig สำหรับโมเดล Gemini
|
คลิกผู้ให้บริการ Gemini API เพื่อดูเนื้อหาและโค้ดเฉพาะของผู้ให้บริการ ในหน้านี้ |
กำหนด GenerationConfig สำหรับโมเดลส่วนใหญ่ของ Gemini ซึ่งรวมถึง
โมเดลการใช้งานทั่วไป โมเดลการสร้างรูปภาพ ("โมเดล Nano Banana") และ
โมเดล Text-to-Speech (TTS)
ระบบจะรักษาการกำหนดค่าไว้ตลอดอายุการใช้งานของอินสแตนซ์ GenerativeModel
หากต้องการใช้การกำหนดค่าอื่น ให้สร้างและใช้อินสแตนซ์ใหม่
ที่มีการกำหนดค่าอื่น
Swift
ตั้งค่าพารามิเตอร์ใน
GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
import FirebaseAILogic
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
let config = GenerationConfig(
maxOutputTokens: 200,
stopSequences: ["red"]
)
// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: config
)
// ...
Kotlin
ตั้งค่าพารามิเตอร์ใน
GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
val config = generationConfig {
maxOutputTokens = 200
stopSequences = listOf("red")
}
// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
generationConfig = config
)
// ...
Java
ตั้งค่าพารามิเตอร์ใน
GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.maxOutputTokens = 200;
configBuilder.stopSequences = List.of("red");
GenerationConfig config = configBuilder.build();
// Specify the config as part of creating the `GenerativeModel` instance.
GenerativeModelFutures model = GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
"GEMINI_MODEL_NAME",
config
);
);
// ...
Web
ตั้งค่าพารามิเตอร์ใน
GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
// ...
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
const generationConfig = {
maxOutputTokens: 200,
stopSequences: ["red"],
};
// Specify the config as part of creating the `GenerativeModel` instance.
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", generationConfig });
// ...
Dart
ตั้งค่าพารามิเตอร์ใน
GenerationConfig
ซึ่งเป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
final generationConfig = GenerationConfig(
maxOutputTokens: 200,
stopSequences: ["red"],
);
// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
config: generationConfig,
);
// ...
Unity
ตั้งค่าพารามิเตอร์ใน
GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// For the latest general-use Gemini models, the following parameters are now unsupported:
// temperature, top-K, top-P, frequency penalty, presence penalty, and candidate count
var generationConfig = new GenerationConfig(
maxOutputTokens: 200,
stopSequences: new string[] { "red" }
);
// Initialize the Gemini Developer API backend service.
// Specify the config as part of creating the `GenerativeModel` instance.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: generationConfig
);
คุณดูคำอธิบายของแต่ละพารามิเตอร์ได้ ในส่วนถัดไปของหน้านี้
คุณทดลองใช้พรอมต์และการกำหนดค่าโมเดลได้โดยใช้ Google AI StudioLiveGenerationConfig สำหรับโมเดล Gemini Live API
|
คลิกผู้ให้บริการ Gemini API เพื่อดูเนื้อหาและโค้ดเฉพาะของผู้ให้บริการ ในหน้านี้ |
ตั้งค่า LiveGenerationConfig เฉพาะเมื่อใช้โมเดล Gemini Live API
ระบบจะรักษาการกำหนดค่าไว้ตลอดอายุการใช้งานของอินสแตนซ์ LiveModel
หากต้องการใช้การกำหนดค่าอื่น ให้สร้างและใช้อินสแตนซ์ใหม่
ที่มีการกำหนดค่าอื่น
Swift
ตั้งค่าพารามิเตอร์ใน
liveGenerationConfig
ระหว่างการเริ่มต้นอินสแตนซ์ LiveModel ดังนี้
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
let config = LiveGenerationConfig(
maxOutputTokens: 200,
responseModalities: [.audio],
speech: SpeechConfig(voiceName: "Fenrir"),
)
// Specify the config as part of creating the `liveModel` instance.
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "GEMINI_LIVE_MODEL_NAME",
generationConfig: config
)
// ...
Kotlin
ตั้งค่าพารามิเตอร์ใน
LiveGenerationConfig
ซึ่งเป็นส่วนหนึ่งของการสร้างอินสแตนซ์ LiveModel
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
val config = liveGenerationConfig {
maxOutputTokens = 200
responseModality = ResponseModality.AUDIO
speechConfig = SpeechConfig(voice = Voices.FENRIR)
}
// Specify the config as part of creating the `LiveModel` instance.
val liveModel = Firebase.ai(backend = GenerativeBackend.agentPlatform()).liveModel(
modelName = "GEMINI_LIVE_MODEL_NAME",
generationConfig = config
)
// ...
Java
ตั้งค่าพารามิเตอร์ใน
LiveGenerationConfig
ซึ่งเป็นส่วนหนึ่งของการสร้างอินสแตนซ์ LiveModel
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
LiveGenerationConfig.Builder configBuilder = new LiveGenerationConfig.Builder();
configBuilder.setMaxOutputTokens(200);
configBuilder.setResponseModality(ResponseModality.AUDIO);
configBuilder.setSpeechConfig(new SpeechConfig(Voices.FENRIR));
LiveGenerationConfig config = configBuilder.build();
// Specify the config as part of creating the `LiveModel` instance.
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"GEMINI_LIVE_MODEL_NAME",
config
);
// ...
Web
ตั้งค่าพารามิเตอร์ใน
LiveGenerationConfig
ระหว่างการเริ่มต้นอินสแตนซ์ LiveGenerativeModel ดังนี้
// ...
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
const liveGenerationConfig = {
maxOutputTokens: 200,
responseModalities: [ResponseModality.AUDIO],
speechConfig: {
voiceConfig: {
prebuiltVoiceConfig: { voiceName: "Fenrir" },
},
},
};
// Specify the config as part of creating the `LiveGenerativeModel` instance.
const liveModel = getLiveGenerativeModel(ai, {
model: "GEMINI_LIVE_MODEL_NAME",
liveGenerationConfig,
});
// ...
Dart
ตั้งค่าพารามิเตอร์ใน
LiveGenerationConfig
ซึ่งเป็นส่วนหนึ่งของการสร้างอินสแตนซ์ LiveGenerativeModel
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
final config = LiveGenerationConfig(
maxOutputTokens: 200,
responseModalities: [ResponseModalities.audio],
speechConfig: SpeechConfig(voiceName: 'Fenrir'),
);
// Specify the config as part of creating the `liveGenerativeModel` instance.
final liveModel = FirebaseAI.googleAI().liveGenerativeModel(
model: 'GEMINI_LIVE_MODEL_NAME',
liveGenerationConfig: config,
);
// ...
Unity
ตั้งค่าพารามิเตอร์ใน
LiveGenerationConfig
ซึ่งเป็นส่วนหนึ่งของการสร้างอินสแตนซ์ LiveModel
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here).
var config = new LiveGenerationConfig(
maxOutputTokens: 200,
responseModalities: new[] { ResponseModality.Audio },
speechConfig: SpeechConfig.UsePrebuiltVoice("Fenrir")
);
// Specify the config as part of creating the `LiveModel` instance.
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "GEMINI_LIVE_MODEL_NAME",
liveGenerationConfig: config
);
// ...
คุณดูคำอธิบายของแต่ละพารามิเตอร์ได้ ในส่วนถัดไปของหน้านี้
คุณทดลองใช้พรอมต์และการกำหนดค่าโมเดลได้โดยใช้ Google AI Studioคำอธิบายพารามิเตอร์
ตารางต่อไปนี้เป็นภาพรวมระดับสูงของพารามิเตอร์ที่ใช้ได้ พารามิเตอร์บางรายการ ใช้ได้กับบางรุ่นเท่านั้น
| พารามิเตอร์ | คำอธิบาย | ข้อจำกัด | ค่าเริ่มต้น |
|---|---|---|---|
การประทับเวลาเสียงaudioTimestamp
|
ช่วยให้เข้าใจการประทับเวลาสำหรับไฟล์อินพุตเสียงเท่านั้น |
บูลีน
ใช้ได้เฉพาะเมื่อใช้ |
false
|
โทเค็นเอาต์พุตสูงสุดmaxOutputTokens
|
ระบุจำนวนโทเค็นสูงสุดที่สร้างได้ใน การตอบกลับ | --- | --- |
หยุดลำดับstopSequences
|
ระบุรายการสตริงที่บอกให้โมเดลหยุดสร้างเนื้อหาหากพบสตริงใดสตริงหนึ่งในคำตอบ |
ใช้ได้เฉพาะเมื่อใช้การกำหนดค่า ไม่เกี่ยวข้องกับ โมเดลรูปภาพ ("Nano Banana") หรือ โมเดล TTS |
--- |
| การกำหนดค่าเฉพาะ | |||
กำลังคิดthinkingConfig
|
ควบคุม "กระบวนการคิด" ของโมเดลเมื่อสร้างคำตอบ
|
ค่าที่รองรับ: ดูเอกสารประกอบเกี่ยวกับความคิด ใช้ไม่ได้กับโมเดล TTS
Firebase AI Logic ยังไม่รองรับการตั้งค่า
|
ขึ้นอยู่กับรุ่น |
รูปแบบการตอบกลับresponseModalities
|
ระบุประเภทเอาต์พุต (เช่น ข้อความ เสียง หรือรูปภาพ) | ใช้ได้ (และต้องระบุ) เมื่อใช้ Gemini โมเดลรูปภาพ (โมเดล "Nano Banana"), โมเดล TTS และ Live API โมเดลเท่านั้น | --- |
ลักษณะของรูปภาพimageConfig
|
ระบุสัดส่วนภาพและความละเอียดของรูปภาพที่สร้างขึ้น |
ค่าที่รองรับ: ดูกำหนดค่าการสร้างรูปภาพ ใช้ได้เฉพาะเมื่อใช้Geminiโมเดลรูปภาพ ("Nano Banana" ) |
สัดส่วนภาพ 1:1 (สี่เหลี่ยมจัตุรัส) ความละเอียด 1024x1024 |
คำพูด (เสียง)speechConfig
|
ระบุเสียงที่ใช้สำหรับเอาต์พุตเสียง |
ใช้ได้เมื่อใช้โมเดล TTS และโมเดล Live API เท่านั้น ต้องระบุสำหรับโมเดล TTS |
Puck
|
ตัวเลือกอื่นๆ ในการควบคุมการสร้างเนื้อหา
- ดูข้อมูลเพิ่มเติมเกี่ยวกับการออกแบบพรอมต์ เพื่อให้คุณมีอิทธิพลต่อโมเดลในการสร้างเอาต์พุตที่เฉพาะเจาะจงตามความต้องการของคุณ
- ใช้การตั้งค่าความปลอดภัย เพื่อปรับความน่าจะเป็นที่จะได้รับคำตอบที่อาจถือว่า เป็นอันตราย ซึ่งรวมถึงวาจาสร้างความเกลียดชังและเนื้อหาเกี่ยวกับเรื่องเพศอย่างโจ่งแจ้ง
- ตั้งคำสั่งของระบบ เพื่อกำหนดลักษณะการทำงานของโมเดล ฟีเจอร์นี้เป็นเหมือนคำนำที่คุณ เพิ่มก่อนที่โมเดลจะได้รับคำสั่งเพิ่มเติมจากผู้ใช้ปลายทาง
- ส่งสคีมาการตอบกลับ พร้อมกับพรอมต์เพื่อระบุสคีมาเอาต์พุตที่เฉพาะเจาะจง โดยส่วนใหญ่แล้ว ฟีเจอร์นี้จะใช้กันโดยทั่วไปเมื่อสร้างเอาต์พุต JSON แต่ก็ใช้กับงานการจัดประเภทได้เช่นกัน (เช่น เมื่อคุณต้องการให้โมเดลใช้ป้ายกำกับหรือแท็กที่เฉพาะเจาะจง)