ในการเรียกใช้โมเดลแต่ละครั้ง คุณสามารถส่งการกำหนดค่าโมเดลเพื่อควบคุมวิธีที่โมเดลสร้างคำตอบได้
แต่ละโมเดลรองรับตัวเลือกการกำหนดค่าที่แตกต่างกัน
เช่น การตั้งค่า maxOutputTokens หรือการกำหนดค่าเฉพาะสำหรับการคิด
รูปแบบการตอบสนอง รูปภาพ หรือคำพูด
สำหรับ Use Case ส่วนใหญ่เมื่อเข้าถึงโมเดล Gemini คุณจะกำหนดค่าโมเดลโดยใช้ GenerationConfig แต่หากกำหนดค่า
Gemini Live API คุณจะต้องใช้ LiveGenerationConfig
หน้านี้แสดงวิธีตั้งค่าการกำหนดค่าสำหรับโมเดล Gemini และมีคำอธิบายของพารามิเตอร์แต่ละรายการ
ข้ามไปที่การกำหนดค่า Gemini ข้ามไปที่การกำหนดค่า Gemini Live API
GenerationConfig สำหรับโมเดล Gemini
|
คลิกผู้ให้บริการ Gemini API เพื่อดูเนื้อหาและโค้ดเฉพาะของผู้ให้บริการในหน้านี้ |
ตั้งค่า GenerationConfig สำหรับโมเดล Gemini ส่วนใหญ่ ซึ่งรวมถึงโมเดลการใช้งานทั่วไป โมเดลการสร้างรูปภาพ (โมเดล "Nano Banana") และโมเดลการอ่านออกเสียงข้อความ (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 = Voice("FENRIR"))
}
// Specify the config as part of creating the `LiveModel` instance.
val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).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(new Voice("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 แต่ก็ใช้สำหรับงานการแยกประเภทได้เช่นกัน (เช่น เมื่อต้องการให้โมเดลใช้ป้ายกำกับหรือแท็กที่เฉพาะเจาะจง)