जवाबों को कंट्रोल करने के लिए, मॉडल कॉन्फ़िगरेशन का इस्तेमाल करना

मॉडल को किए गए हर कॉल में, मॉडल कॉन्फ़िगरेशन भेजा जा सकता है. इससे यह कंट्रोल किया जा सकता है कि मॉडल किस तरह से जवाब जनरेट करे. हर मॉडल के लिए कॉन्फ़िगरेशन के अलग-अलग विकल्प उपलब्ध होते हैं. जैसे, maxOutputTokens सेट करना या सोचने, जवाब देने के तरीके, इमेज या स्पीच के लिए खास कॉन्फ़िगरेशन.

Gemini मॉडल को ऐक्सेस करने के ज़्यादातर मामलों में, GenerationConfig का इस्तेमाल करके मॉडल को कॉन्फ़िगर किया जाता है. हालांकि, अगर आपको Gemini Live API मॉडल कॉन्फ़िगर करना है, तो LiveGenerationConfig का इस्तेमाल करें.

इस पेज पर, Gemini मॉडल के लिए कॉन्फ़िगरेशन सेट अप करने का तरीका बताया गया है. साथ ही, हर पैरामीटर के बारे में जानकारी दी गई है.

Gemini कॉन्फ़िगरेशन पर जाएं Gemini Live API कॉन्फ़िगरेशन पर जाएं

Gemini मॉडल के लिए GenerationConfig

इस पेज पर, सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, Gemini API पर क्लिक करें.

GenerationConfig को ज़्यादातर Gemini मॉडल के लिए सेट करें. इनमें सामान्य इस्तेमाल वाले मॉडल, इमेज जनरेट करने वाले मॉडल ("Nano Banana" मॉडल), और टेक्स्ट को स्पीच में बदलने वाले (टीटीएस) मॉडल शामिल हैं.

यह कॉन्फ़िगरेशन, GenerativeModel इंस्टेंस के लाइफ़टाइम के लिए सेव रहता है. अगर आपको किसी दूसरे कॉन्फ़िगरेशन का इस्तेमाल करना है, तो किसी दूसरे कॉन्फ़िगरेशन के साथ एक नया इंस्टेंस बनाएं और उसका इस्तेमाल करें.

Swift

GenerativeModel इंस्टेंस बनाते समय, GenerationConfig में पैरामीटर की वैल्यू सेट करें.


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

GenerativeModel इंस्टेंस बनाते समय, GenerationConfig में पैरामीटर की वैल्यू सेट करें.


// ...

// 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

GenerativeModel इंस्टेंस बनाते समय, GenerationConfig में पैरामीटर की वैल्यू सेट करें.


// ...

// 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

GenerativeModel इंस्टेंस बनाते समय, GenerationConfig में पैरामीटर की वैल्यू सेट करें.


// ...

// 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

GenerativeModel इंस्टेंस बनाते समय, GenerationConfig में पैरामीटर की वैल्यू सेट करें.


// ...

// 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

GenerativeModel इंस्टेंस बनाते समय, GenerationConfig में पैरामीटर की वैल्यू सेट करें.


// ...

// 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 Studio का इस्तेमाल करके, प्रॉम्प्ट और मॉडल कॉन्फ़िगरेशन के साथ एक्सपेरिमेंट किया जा सकता है.

Gemini Live API मॉडल के लिए LiveGenerationConfig

इस पेज पर, सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, Gemini API पर क्लिक करें.

Gemini Live API मॉडल का इस्तेमाल करते समय ही LiveGenerationConfig सेट करें.

यह कॉन्फ़िगरेशन, LiveModel इंस्टेंस के लाइफ़टाइम के लिए सेव रहता है. अगर आपको किसी दूसरे कॉन्फ़िगरेशन का इस्तेमाल करना है, तो किसी दूसरे कॉन्फ़िगरेशन के साथ एक नया इंस्टेंस बनाएं और उसका इस्तेमाल करें.

Swift

LiveModel इंस्टेंस को शुरू करते समय, liveGenerationConfig में पैरामीटर की वैल्यू सेट करें:


// ...

// 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

LiveModel इंस्टेंस बनाते समय, LiveGenerationConfig में पैरामीटर की वैल्यू सेट करें.


// ...

// 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

LiveModel इंस्टेंस बनाते समय, LiveGenerationConfig में पैरामीटर की वैल्यू सेट करें.


// ...

// 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

LiveGenerativeModel इंस्टेंस को शुरू करते समय, LiveGenerationConfig में पैरामीटर की वैल्यू सेट करें:


// ...

// 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

LiveGenerativeModel इंस्टेंस बनाते समय, LiveGenerationConfig में पैरामीटर की वैल्यू सेट करें.


// ...

// 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

LiveModel इंस्टेंस बनाते समय, LiveGenerationConfig में पैरामीटर की वैल्यू सेट करें.


// ...

// 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
इससे सिर्फ़ ऑडियो वाली इनपुट फ़ाइलों के लिए टाइमस्टैंप समझने की सुविधा चालू होती है.

बूलियन

यह सुविधा सिर्फ़ तब लागू होती है, जब GenerativeModel कॉन्फ़िगरेशन का इस्तेमाल किया जा रहा हो और इनपुट टाइप सिर्फ़ ऑडियो फ़ाइल हो.

false
ज़्यादा से ज़्यादा आउटपुट टोकन
maxOutputTokens
इससे जवाब में जनरेट किए जा सकने वाले टोकन की ज़्यादा से ज़्यादा संख्या तय की जाती है. --- ---
सीक्वेंस बंद करना
stopSequences
यह स्ट्रिंग की एक सूची तय करता है. अगर जवाब में इनमें से कोई स्ट्रिंग मिलती है, तो मॉडल को कॉन्टेंट जनरेट करने से रोकने के लिए कहा जाता है.

यह सिर्फ़ GenerativeModel कॉन्फ़िगरेशन का इस्तेमाल करने पर लागू होता है.

यह सुविधा, इमेज मॉडल ("Nano Banana") या टीटीएस मॉडल के लिए उपलब्ध नहीं है.

---
खास कॉन्फ़िगरेशन
सोचा जा रहा है
thinkingConfig

यह कुकी, मॉडल के "सोचने की प्रोसेस" को कंट्रोल करती है. ऐसा तब होता है, जब मॉडल कोई जवाब जनरेट कर रहे होते हैं.

  • सोचने के लेवल (Gemini 3.x और इसके बाद के मॉडल) का इस्तेमाल करके, यह कंट्रोल करें कि मॉडल कितना सोच सकता है.
  • यह कंट्रोल करना कि सोच के बारे में खास जानकारी को शामिल करना है या नहीं.

इस्तेमाल की जा सकने वाली वैल्यू: सोचने से जुड़े दस्तावेज़ देखें

यह सुविधा, टीटीएस मॉडल के लिए उपलब्ध नहीं है.

Firebase AI Logic पर, Live API मॉडल के लिए thinkingConfig सेट करने की सुविधा अभी उपलब्ध नहीं है.

मॉडल पर निर्भर करता है
जवाब देने के तरीके
responseModalities
इससे आउटपुट का टाइप तय होता है. जैसे, टेक्स्ट, ऑडियो या इमेज. यह सिर्फ़ तब लागू होता है, जब Gemini इमेज मॉडल ("Nano Banana" मॉडल), टीटीएस मॉडल, और Live API मॉडल का इस्तेमाल किया जा रहा हो. साथ ही, ऐसा करना ज़रूरी है. ---
इमेज की विशेषताएं
imageConfig
इससे जनरेट की गई इमेज का आसपेक्ट रेशियो (लंबाई-चौड़ाई का अनुपात) और रिज़ॉल्यूशन तय होता है.

इस्तेमाल की जा सकने वाली वैल्यू: इमेज जनरेट करने की सुविधा कॉन्फ़िगर करना लेख पढ़ें

यह सुविधा सिर्फ़ Gemini इमेज मॉडल ("Nano Banana" मॉडल) का इस्तेमाल करने पर लागू होती है.

1:1 आसपेक्ट रेशियो (स्क्वेयर)
1024x1024 रिज़ॉल्यूशन
स्पीच (आवाज़)
speechConfig
ऑडियो आउटपुट के लिए इस्तेमाल की जाने वाली आवाज़ के बारे में बताता है. यह सुविधा, टीटीएस मॉडल और Live API मॉडल का इस्तेमाल करने पर ही लागू होती है.

टीटीएस मॉडल के लिए ज़रूरी है.
Puck



कॉन्टेंट जनरेट करने की सुविधा को कंट्रोल करने के अन्य विकल्प

  • प्रॉम्प्ट डिज़ाइन के बारे में ज़्यादा जानें, ताकि मॉडल को अपनी ज़रूरतों के हिसाब से आउटपुट जनरेट करने के लिए प्रेरित किया जा सके.
  • सुरक्षा सेटिंग का इस्तेमाल करके, ऐसे जवाब मिलने की संभावना को कम किया जा सकता है जिन्हें नुकसान पहुंचाने वाला माना जा सकता है. जैसे, नफ़रत फैलाने वाली भाषा और साफ़ तौर पर सेक्शुअल ऐक्ट दिखाने वाला कॉन्टेंट.
  • मॉडल के व्यवहार को कंट्रोल करने के लिए, सिस्टम के निर्देश सेट करें. यह सुविधा, प्रस्तावना की तरह होती है. इसे मॉडल को असली उपयोगकर्ता से कोई और निर्देश मिलने से पहले जोड़ा जाता है.
  • किसी खास आउटपुट स्कीमा के बारे में बताने के लिए, प्रॉम्प्ट के साथ रिस्पॉन्स स्कीमा पास करें. इस सुविधा का इस्तेमाल आम तौर पर, JSON आउटपुट जनरेट करने के लिए किया जाता है. हालांकि, इसका इस्तेमाल क्लासिफ़िकेशन टास्क के लिए भी किया जा सकता है. जैसे, जब आपको मॉडल से किसी खास लेबल या टैग का इस्तेमाल करवाना हो.