בכל קריאה למודל, אתם יכולים לשלוח הגדרות מודל כדי לקבוע איך המודל ייצור תשובה. כל מודל תומך באפשרויות הגדרה שונות, כמו הגדרת maxOutputTokens או הגדרות מיוחדות לחשיבה, למודלים של תגובה, לתמונות, לדיבור או לזיהוי דיבור (VAD).
ברוב תרחישי השימוש, כשניגשים למודל 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 Agent Platform Gemini API backend service (formerly Vertex AI).
// Specify the config as part of creating the `GenerativeModel` instance.
let model = FirebaseAI.firebaseAI(backend: .agentPlatform()).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 Agent Platform Gemini API backend service (formerly Vertex AI).
// Specify the config as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.agentPlatform()).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.agentPlatform())
.generativeModel(
"GEMINI_MODEL_NAME",
config
);
);
// ...
Web
מגדירים את ערכי הפרמטרים ב-GenerationConfig כחלק מיצירת מכונה של GenerativeModel.
// ...
// Initialize the Agent Platform Gemini API backend service (formerly Vertex AI).
const ai = getAI(firebaseApp, { backend: new AgentPlatformBackend() });
// 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 Agent Platform Gemini API backend service (formerly Vertex AI).
// Specify the config as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.agentPlatform().generativeModel(
model: 'GEMINI_MODEL_NAME',
generationConfig: 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 Agent Platform Gemini API backend service (formerly Vertex AI).
// Specify the config as part of creating the `GenerativeModel` instance.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.AgentPlatform());
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: generationConfig
);
LiveGenerationConfig למודלים של Gemini Live API
|
כדי לראות תוכן וקוד שספציפיים לספק, לוחצים על הספק Gemini API בדף הזה. |
צריך להגדיר LiveGenerationConfig רק כשמשתמשים במודלים של Gemini Live API.
ההגדרות נשמרות לאורך כל חיי המכונה של LiveModel. אם רוצים להשתמש בהגדרות אישיות אחרות, צריך ליצור מופע חדש עם הגדרות אישיות אחרות ולהשתמש בו.
בדוגמה הבאה מוצגת הגדרת מודל בסיסית מאוד. לאפשרויות נוספות (כמו הגדרת זיהוי דיבור (VAD)), עיינו בטבלה של הפרמטרים הזמינים בהמשך הדף.
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: .agentPlatform(location: "us-central1")).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.agentPlatform(location = "us-central1")).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.agentPlatform("us-central1")).liveModel(
"GEMINI_LIVE_MODEL_NAME",
config
);
// ...
Web
מגדירים את ערכי הפרמטרים ב-LiveGenerationConfig במהלך האתחול של המכונה LiveGenerativeModel:
// ...
// Initialize the Agent Platform Gemini API backend service (formerly Vertex AI).
const ai = getAI(firebaseApp, { backend: new AgentPlatformBackend("us-central1") });
// 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.agentPlatform(location: 'us-central1').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.AgentPlatform(location: "us-central1")).GetLiveModel(
modelName: "GEMINI_LIVE_MODEL_NAME",
liveGenerationConfig: config
);
// ...
פרמטרים זמינים של מודלים
בטבלה הבאה מופיעה סקירה כללית של הפרמטרים שאפשר להגדיר במודל. חלק מהפרמטרים רלוונטיים רק למודלים מסוימים.
| פרמטר | תיאור | מגבלות | ערך ברירת מחדל |
|---|---|---|---|
מספר מקסימלי של טוקנים בפלטmaxOutputTokens
|
מציינת את המספר המקסימלי של טוקנים שאפשר ליצור בתשובה.
ב- |
--- | --- |
רצפי עצירהstopSequences
|
רשימה של מחרוזות שמציינות למודל להפסיק ליצור תוכן אם אחת מהמחרוזות מופיעה בתשובה. |
רלוונטי רק כשמשתמשים בהגדרות אישיות של לא רלוונטי למודלים של Nano Banana או של המרת טקסט לדיבור (TTS). |
--- |
| הגדרות מיוחדות | |||
בתהליך חשיבהthinkingConfig
|
הפרמטר הזה שולט ב"תהליך החשיבה" של המודלים כשהם יוצרים תשובה.
|
ערכים נתמכים: ראו את המסמכים בנושא חשיבה לא רלוונטי למודלים של המרת טקסט לדיבור.
ב-Firebase AI Logic עדיין אי אפשר להגדיר |
תלוי במודל |
אופני התגובהresponseModalities
|
מציין את סוג הפלט (כמו טקסט, אודיו או תמונות). | רלוונטי (וחובה) רק כשמשתמשים במודלים של Nano Banana, TTS ו-Live API. | --- |
מאפייני התמונהimageConfig
|
מציין את יחס הגובה-רוחב ואת הרזולוציה של התמונות שנוצרות. |
ערכים נתמכים: ראו הגדרת יצירת תמונות רלוונטי רק כשמשתמשים במודלים של Nano Banana. |
יחס גובה-רוחב של 1:1 (ריבוע) רזולוציה של 1024x1024 |
דיבור (קול)speechConfig
|
מגדירה את הקול שבו משתמשים לפלט האודיו. |
רלוונטי רק כשמשתמשים במודלים של המרת טקסט לדיבור (TTS) ובמודלים של Live API. נדרש למודלים של TTS. |
Puck
|
זיהוי דיבור (VAD)realtimeInputConfig
|
מגדירה את זיהוי הדיבור (VAD), את הטיפול בהפרעות ואת הכיסוי של ההקשר של התור, או משביתה את ה-VAD האוטומטי. |
ערכים נתמכים: ראו הגדרת VAD רלוונטי רק כשמשתמשים במודלים של Live API. |
VAD מופעל ערכי ברירת המחדל של הגדרות ספציפיות. |
אפשרויות אחרות לשליטה ביצירת תוכן
- מידע נוסף על עיצוב הנחיות כדי להשפיע על המודל ליצור פלט שמתאים לצרכים הספציפיים שלכם.
- אתם יכולים להשתמש בהגדרות הבטיחות כדי לשנות את הסבירות לקבלת תשובות שעלולות להיחשב כמזיקות, כולל דברי שטנה ותוכן מיני בוטה.
- להגדיר הוראות מערכת כדי לכוון את ההתנהגות של המודל. התכונה הזו היא כמו הוראות מקדימות שמוסיפים לפני שהמודל נחשף להוראות נוספות ממשתמש הקצה.
- מעבירים סכֵימת תשובה יחד עם ההנחיה כדי לציין סכֵימת פלט ספציפית. התכונה הזו משמשת בדרך כלל כשרוצים ליצור פלט בפורמט JSON, אבל אפשר להשתמש בה גם למשימות סיווג (למשל, כשרוצים שהמודל ישתמש בתוויות או בתגים ספציפיים).