モデル構成を使用してレスポンスを制御する

モデルへの呼び出しごとに、モデル構成を送信して、モデルがどのように回答を生成するかを制御できます。各モデルは、maxOutputTokens の設定や、思考、レスポンス モダリティ、画像、音声、音声検出(VAD)の専用構成など、さまざまな構成オプションをサポートしています。

Gemini モデルにアクセスするほとんどのユースケースでは、GenerationConfig を使用してモデルを構成します。ただし、Gemini Live API モデルを構成する場合は、LiveGenerationConfig を使用します。

このページでは、Gemini モデルの構成を設定する方法について説明し、使用可能なパラメータの表を示します。

Gemini 構成に移動 Gemini Live API 構成に移動

Gemini モデルの GenerationConfig

Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。

一般用途モデル、画像生成(Nano Banana)モデル、テキスト読み上げ(TTS)モデルなど、ほとんどの Gemini モデルに GenerationConfig を設定します。

この構成は、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',
  generationConfig: 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 プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。

LiveGenerationConfig は、Gemini Live API モデルを使用する場合にのみ設定します。

この構成は、LiveModel インスタンスの存続期間中維持されます。別の構成を使用する場合は、別の構成で新しいインスタンスを作成して使用します。

次の例は、非常に基本的なモデル構成を示しています。その他のオプション(音声検出(VAD)の構成など)については、このページの後半にある使用可能なパラメータの表をご覧ください。

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

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

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

レスポンスで生成できるトークンの最大数を指定します。

gemini-4-argon の場合、デフォルトと最大出力トークンの上限は、非ストリーミング リクエストでは 32,768 トークン、ストリーミング リクエストでは 65,536 トークンです。Firebase AI Logic はまだ長いデコードをサポートしていませんが、この機能は近日公開予定です。

--- ---
停止シーケンス
stopSequences
レスポンスでいずれかの文字列が検出された場合に、コンテンツの生成を停止するようモデルに指示する文字列のリストを指定します。

GenerativeModel 構成を使用している場合にのみ適用されます。

Nano Banana モデルまたは TTS モデルには適用されません。

---
特殊な構成
思考中
thinkingConfig

レスポンスを生成する際のモデルの「思考プロセス」を制御します。

  • 思考レベルを使用して、モデルが実行できる思考量を制御します。
  • 思考の要約を含めるかどうかを制御します。

サポートされている値: 思考のドキュメントをご覧ください。

TTS モデルには適用されません。

Firebase AI Logic は、Live API モデルの thinkingConfig の設定をまだサポートしていません。

モデルによって異なる
レスポンス モダリティ
responseModalities
出力のタイプ(テキスト、音声、画像など)を指定します。 Nano Banana、TTS、Live API モデルを使用する場合にのみ適用(必須)されます。 ---
画像特性
imageConfig
生成された画像のアスペクト比と解像度を指定します。

サポートされている値: 画像生成を構成するをご覧ください。

Nano Banana モデルを使用する場合にのみ適用されます。

アスペクト比 1:1(スクエア)
解像度 1,024x1,024
音声(発話)
speechConfig
音声出力に使用する音声を指定します。 TTS モデルと Live API モデルを使用する場合にのみ適用されます。

TTS モデルでは必須です。
Puck
音声検出(VAD)
realtimeInputConfig
音声検出(VAD)、割り込み処理、ターン コンテキスト カバレッジを構成するか、自動 VAD を無効にします。

サポートされている値: VAD を構成するをご覧ください。

Live API モデルを使用する場合にのみ適用されます。

VAD が有効

個々の設定のデフォルト値をご覧ください。



コンテンツ生成を制御するその他のオプション

  • プロンプト設計の詳細を確認して、ニーズに合った出力を生成するようにモデルに指示します。
  • 安全性設定を使用して、ヘイトスピーチや性的描写が露骨なコンテンツなど、有害と見なされる可能性のある回答が生成される可能性を調整します。
  • システム指示を設定して、モデルの動作を制御します。この機能は、エンドユーザーからの詳細な指示がモデルに伝達される前に追加するプリアンブルのようなものです。
  • プロンプトとともにレスポンス スキーマを渡して、特定の出力スキーマを指定します。この機能は、JSON 出力を生成する際によく使用されますが、分類タスク(モデルに特定のラベルやタグを使用させる場合など)にも使用できます。