שימוש בתצורת המודל כדי לשלוט בתשובות

בכל קריאה למודל, אפשר לשלוח הגדרת מודל כדי לשלוט באופן שבו המודל יוצר תגובה. כל מודל תומך באפשרויות שונות של הגדרות, כמו הגדרת maxOutputTokens או הגדרות מיוחדות לחשיבה, לאופני תגובה, לתמונות או לדיבור.

ברוב תרחישי השימוש, כשניגשים למודל Gemini, מגדירים את המודל באמצעות GenerationConfig. עם זאת, אם אתם מגדירים מודל Gemini Live API, אתם משתמשים ב-LiveGenerationConfig.

בדף הזה מוסבר איך להגדיר את התצורה של מודלים של Gemini ומופיע תיאור של כל פרמטר.

Jump to Gemini config Jump to Gemini Live API config

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.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
let config = GenerationConfig(
  candidateCount: 1,
  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.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
val config = generationConfig {
    candidateCount = 1
    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.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.candidateCount = 1;
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.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
const generationConfig = {
  candidate_count: 1,
  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.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
final generationConfig = GenerationConfig(
  candidateCount: 1,
  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.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
var generationConfig = new GenerationConfig(
  candidateCount: 1,
  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 Studio.

LiveGenerationConfig למודלים של 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.



תיאור הפרמטרים

בטבלה הבאה מופיעה סקירה כללית של הפרמטרים הזמינים. חלק מהפרמטרים רלוונטיים רק למודלים מסוימים.

שימו לב שהפרמטרים temperature,‏ top-K ו-top-P הוצאו משימוש והמודלים העדכניים של Gemini מתעלמים מהם.

פרמטר תיאור מגבלות ערך ברירת מחדל
חותמת זמן של אודיו
audioTimestamp
מאפשרת להבין חותמות זמן בקובצי קלט של אודיו בלבד.

בוליאני

ההגדרה הזו רלוונטית רק כשמשתמשים בהגדרה GenerativeModel וסוג הקלט הוא קובץ אודיו בלבד.

false
מספר המועמדים
candidateCount
מציין את מספר וריאציות התגובה שיוחזרו. בכל בקשה, אתם מחויבים על אסימוני הפלט של כל המועמדים, אבל אתם מחויבים רק פעם אחת על אסימוני הקלט.

ערכים נתמכים: 1 עד 8 (כולל)

רלוונטי רק כשמשתמשים ב-generateContent.

לא רלוונטי כשמשתמשים במודלים של generateContentStream, במודלים של TTS או במודלים של Live API.

1
מספר מקסימלי של טוקנים בפלט
maxOutputTokens
מציין את המספר המקסימלי של טוקנים שאפשר ליצור בתשובה. --- ---
קנס על תדירות
frequencyPenalty

ההגדרה הזו שולטת בסבירות להכללת טוקנים שמופיעים שוב ושוב בתשובה שנוצרת.

ערכים חיוביים מענישים טוקנים שמופיעים שוב ושוב בתוכן שנוצר, ומקטינים את ההסתברות לחזרה על תוכן.

לא רלוונטי למודלים של TTS. ---
קנס על נוכחות
presencePenalty

שליטה בהסתברות להכללת טוקנים שכבר מופיעים בתשובה שנוצרה.

ערכים חיוביים מענישים טוקנים שכבר מופיעים בתוכן שנוצר, ומגדילים את הסיכוי ליצור תוכן מגוון יותר.

לא רלוונטי למודלים של TTS. ---
הפסקת רצפים
stopSequences
מציינת רשימה של מחרוזות שאומרות למודל להפסיק ליצור תוכן אם אחת מהמחרוזות מופיעה בתשובה.

ההגדרה רלוונטית רק כשמשתמשים בהגדרת GenerativeModel.

לא רלוונטי למודלים של TTS.

---
הגדרות מיוחדות
חושב
thinkingConfig

הפרמטר הזה קובע את 'תהליך החשיבה' של המודלים כשהם יוצרים תשובה.

  • שליטה בכמות החשיבה שהמודל יכול לבצע באמצעות רמת חשיבה (מודלים מגרסה Gemini 3.x ואילך).
  • האם לכלול סיכום של נקודות חשובות.

ערכים נתמכים: אפשר לעיין במסמכי ההסבר

לא רלוונטי למודלים של TTS.

בשלב הזה, Firebase AI Logic עדיין לא תומך בהגדרת thinkingConfig למודלים של Live API.

תלוי במודל
אופני תגובה
responseModalities
מציין את סוג הפלט (כמו טקסט, אודיו או תמונות). רלוונטי (ונדרש) רק כשמשתמשים ב: Gemini מודלים של תמונות (מודלים של Nano Banana), מודלים של TTS ו- מודלים של Live API. ---
מאפייני התמונה
imageConfig
מציין את יחס הגובה-רוחב והרזולוציה של התמונות שנוצרו.

ערכים נתמכים: ראו הגדרה של יצירת תמונות

ההגדרה רלוונטית רק כשמשתמשים בGemini מודלים של תמונות (מודלים של Nano Banana).

יחס גובה-רוחב של 1:1 (ריבוע)
רזולוציה של 1024x1024
דיבור (קול)
speechConfig
מציינת את הקול שמשמש לפלט האודיו. רלוונטי רק כשמשתמשים במודלים של TTS ובמודלים של Live API.

חובה במודלים של TTS.
Puck





אפשרויות נוספות לשליטה ביצירת תוכן

  • מידע נוסף על עיצוב הנחיות כדי להשפיע על המודל ליצור פלט שמתאים לצרכים שלכם.
  • כדאי להשתמש בהגדרות הבטיחות כדי לשנות את הסיכוי לקבל תשובות שאפשר להגדיר כמזיקות, כולל דברי שטנה ותוכן מיני בוטה.
  • הגדרת הוראות מערכת כדי לכוון את התנהגות המודל. Aware AI היא תכונה שפועלת כמו הקדמה שמוסיפים לפני שהמודל נחשף להוראות נוספות ממשתמש הקצה.
  • מעבירים סכימת תגובה יחד עם ההנחיה כדי לציין סכימת פלט ספציפית. התכונה הזו משמשת בעיקר כשיוצרים פלט JSON, אבל אפשר להשתמש בה גם למשימות סיווג (למשל, כשרוצים שהמודל ישתמש בתוויות או בתגים ספציפיים).