モデルへの呼び出しごとに、モデル構成を送信して、モデルがレスポンスを生成する方法を制御できます。各モデルは、maxOutputTokens の設定や、思考、レスポンス モダリティ、画像、音声の特殊な構成など、さまざまな構成オプションをサポートしています。
Gemini モデルにアクセスするほとんどのユースケースでは、
GenerationConfig を使用してモデルを構成します。ただし、
Gemini Live API モデルを構成する場合は、LiveGenerationConfig を使用します。
このページでは、Gemini モデルの構成を設定する方法と 各パラメータの 説明について説明します。
Gemini 構成に移動 Gemini Live API 構成に移動
GenerationConfig モデルの Gemini
|
Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。 |
ほとんどの Gemini モデルに GenerationConfig を設定します。これには、汎用モデル、画像生成モデル(「Nano Banana」モデル)、テキスト読み上げ(TTS)モデルなどがあります。
構成は、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
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
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 を使用して、プロンプトとモデル構成を試すことができます。 Google AI Studio.LiveGenerationConfig モデル用 Gemini Live API
|
Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。 |
LiveGenerationConfig は、Gemini Live API モデルを使用する場合にのみ設定します。
構成は、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 = 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
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
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 を使用して、プロンプトとモデル構成を試すことができます。 Google AI Studio.パラメータの説明
次の表に、使用可能なパラメータの概要を示します。一部のパラメータは、特定のモデルにのみ適用されます。
| パラメータ | 説明 | 制限事項 | デフォルト値 |
|---|---|---|---|
音声タイムスタンプaudioTimestamp
|
音声のみの入力ファイルでタイムスタンプの認識を有効にします。 |
ブール値
` |
false
|
最大出力トークンmaxOutputTokens
|
レスポンスで生成できるトークンの最大数を指定します。
|
--- | --- |
停止シーケンスstopSequences
|
レスポンスでいずれかの文字列が検出された場合に、コンテンツの生成を停止するようモデルに指示する文字列のリストを指定します。 |
画像モデル(「Nano Banana」)または TTS モデルには適用されません。 |
--- |
| 特殊な構成 | |||
思考thinkingConfig
|
モデルがレスポンスを生成する際の「思考プロセス」を制御します。
|
サポートされている値: 思考のドキュメント をご覧ください TTS モデルには該当なし。
Firebase AI Logic は、まだ Live API モデルの |
モデルによって異なります |
レスポンス モダリティresponseModalities
|
出力のタイプ(テキスト、音声、画像など)を指定します。 | Gemini 画像モデル(「Nano Banana」モデル)、TTS モデル、Live API モデルを使用する場合にのみ適用されます(必須)。GeminiLive API | --- |
画像特性imageConfig
|
生成される画像のアスペクト比と解像度を指定します。 |
サポートされている値: 画像生成を構成する をご覧ください Gemini 画像モデル(「Nano Banana」 モデル)を使用する場合にのみ適用されます。 |
アスペクト比 1:1(正方形) 解像度 1,024 x 1,024 |
音声(音声)speechConfig
|
音声出力に使用する音声を指定します。 |
TTS モデルと Live API モデルを使用する場合にのみ適用されます。 TTS モデルでは必須です。 |
Puck
|
コンテンツ生成を制御するその他のオプション
- プロンプト設計の詳細を確認して 、モデルがニーズに固有の出力を生成するように影響を与えます。
- 安全に関する設定を使用して、ヘイトスピーチや性的描写が露骨なコンテンツなど、有害とみなされる可能性のあるレスポンスを取得する可能性を調整します。
- システム指示 を設定して、モデルの動作を制御します。この機能は、エンドユーザーからの詳細な指示がモデルに伝達される前に追加するプリアンブルのようなものです。
- プロンプトとともにレスポンス スキーマ を渡して、特定の出力スキーマを指定します。この機能は JSON 出力を生成する場合に最もよく使用されますが、 分類タスク (モデルに特定のラベルやタグを使用させる場合など)にも使用できます。