モデルへの呼び出しごとに、モデル構成を送信して、モデルがレスポンスを生成する方法を制御できます。各モデルには、異なる構成オプションが用意されています。
Google AI Studio を使用して、プロンプトとモデル構成を試すこともできます。 Google AI Studio.Gemini の構成オプションに移動 Imagen の構成オプションに移動 (非推奨)
Gemini モデルを構成する
このセクションでは、 構成を設定する方法と、 Geminiモデルで使用するための 各パラメータの説明について説明します。
モデル構成を設定する(Gemini)
一般的な Gemini ユースケースの構成
|
Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。 |
構成はインスタンスの有効期間中維持されます。別の構成を使用する場合は、その構成で新しい 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.
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.
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.
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.
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.
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.
var generationConfig = new GenerationConfig(
candidateCount: 1,
maxOutputTokens: 200,
stopSequences: new string[] { "red" }
);
// 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
);
各パラメータの説明 については、このページの次のセクションをご覧ください。
Gemini Live API の構成
|
Gemini 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 = Voices.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(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
// ...
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
);
// ...
各パラメータの説明 については、このページの次のセクションをご覧ください。
パラメータの説明(Gemini)
使用可能なパラメータの概要を以下に示します。パラメータとその値の包括的なリストについては、選択した Gemini APIプロバイダ( Gemini Developer API または Agent Platform Gemini API (formerly Vertex AI))のドキュメントをご覧ください。
| パラメータ | 説明 | デフォルト値 |
|---|---|---|
音声タイムスタンプaudioTimestamp
|
音声のみの入力 ファイルでタイムスタンプの認識を有効にするブール値。 `generateContent` または |
false |
候補数candidateCount
|
返すレスポンス バリエーションの数を指定します。リクエストごとに、すべての候補の出力トークンが課金されますが、入力トークンは 1 回のみ課金されます。 サポートされる値:
|
1 |
頻度のペナルティfrequencyPenalty
|
生成されたレスポンスに繰り返し出現するトークンを含める確率を制御します。 値が正の場合は、生成された コンテンツに繰り返し出現するトークンにペナルティが課されるため、コンテンツが繰り返される確率は低下します。 |
--- |
最大出力トークンmaxOutputTokens
|
レスポンスで生成できるトークンの最大数を指定します。 | --- |
プレゼンス ペナルティpresencePenalty
|
生成されたレスポンスにすでに表示されているトークンを含める確率を制御します。
値が正の場合は、生成されたコンテンツ内の既存のトークンにペナルティが課されるため、より多様なコンテンツが生成される確率は高くなります。 |
--- |
停止シーケンスstopSequences
|
レスポンスでいずれかの文字列が検出された場合に、コンテンツの生成を停止するようモデルに指示する文字列のリストを指定します。 `GenerativeModel` 構成を使用する場合にのみ適用されます。
|
--- |
レスポンス モダリティresponseModalities
|
出力のタイプ(テキスト、音声、画像など)を指定します。 Gemini Image モデル(「Nano Banana」モデルなど)または Live API モデルを使用する場合にのみ適用されます。 |
--- |
音声speechConfig
|
音声出力に使用する音声を指定します。 音声生成モデルを使用する場合にのみ適用されます。 Live API モデルなど。 |
Puck |
画像特性imageConfig
|
生成された画像のアスペクト比と解像度を指定します。 サポートされる値: 画像生成を構成する をご覧ください。 Gemini Image モデル (「Nano Banana」モデルなど)を使用する場合にのみ適用されます。 |
1:1 のアスペクト比(スクエア) 1,024 x 1,024 の解像度 |
Imagen モデルを構成する
|
Imagen API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。 |
このセクションでは、 構成を設定する方法と、 Imagenモデルで使用する 各パラメータの説明について説明します。
モデル構成を設定する(Imagen)
構成はインスタンスの有効期間中維持されます。別の構成を使用する場合は、その構成で新しい ImagenModel インスタンスを作成します。
Swift
ImagenGenerationConfig
のパラメータの値を、ImagenModel インスタンスの作成の一部として設定します。
import FirebaseAILogic
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
let config = ImagenGenerationConfig(
negativePrompt: "frogs",
numberOfImages: 2,
aspectRatio: .landscape16x9,
imageFormat: .jpeg(compressionQuality: 100),
addWatermark: false
)
// Initialize the Gemini Developer API backend service
// Specify the config as part of creating the `ImagenModel` instance
let model = FirebaseAI.firebaseAI(backend: .googleAI()).imagenModel(
modelName: "IMAGEN_MODEL_NAME",
generationConfig: config
)
// ...
Kotlin
ImagenGenerationConfig
のパラメータの値を、ImagenModel インスタンスの作成の一部として設定します。
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
val config = ImagenGenerationConfig {
negativePrompt = "frogs",
numberOfImages = 2,
aspectRatio = ImagenAspectRatio.LANDSCAPE_16x9,
imageFormat = ImagenImageFormat.jpeg(compressionQuality = 100),
addWatermark = false
}
// Initialize the Gemini Developer API backend service
// Specify the config as part of creating the `GenerativeModel` instance
val model = Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel(
modelName = "IMAGEN_MODEL_NAME",
generationConfig = config
)
// ...
Java
ImagenGenerationConfig
のパラメータの値を、ImagenModel インスタンスの作成の一部として設定します。
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
ImagenGenerationConfig config = new ImagenGenerationConfig.Builder()
.setNegativePrompt("frogs")
.setNumberOfImages(2)
.setAspectRatio(ImagenAspectRatio.LANDSCAPE_16x9)
.setImageFormat(ImagenImageFormat.jpeg(100))
.setAddWatermark(false)
.build();
// Specify the config as part of creating the `ImagenModel` instance
ImagenModelFutures model = ImagenModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.imagenModel(
"IMAGEN_MODEL_NAME",
config
);
);
// ...
Web
ImagenGenerationConfig
のパラメータの値を、ImagenModel インスタンスの作成の一部として設定します。
// ...
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
const generationConfig = {
negativePrompt: "frogs",
numberOfImages: 2,
aspectRatio: ImagenAspectRatio.LANDSCAPE_16x9,
imageFormat: ImagenImageFormat.jpeg(100),
addWatermark: false
};
// Specify the config as part of creating the `ImagenModel` instance
const model = getImagenModel(ai, { model: "IMAGEN_MODEL_NAME", generationConfig });
// ...
Dart
ImagenGenerationConfig のパラメータの値を、
インスタンスの作成の一部として設定します。ImagenModel
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
final generationConfig = ImagenGenerationConfig(
negativePrompt: 'frogs',
numberOfImages: 2,
aspectRatio: ImagenAspectRatio.landscape16x9,
imageFormat: ImagenImageFormat.jpeg(compressionQuality: 100)
addWatermark: false
);
// Initialize the Gemini Developer API backend service
// Specify the config as part of creating the `ImagenModel` instance
final model = FirebaseAI.googleAI().imagenModel(
model: 'IMAGEN_MODEL_NAME',
config: generationConfig,
);
// ...
Unity
ImagenGenerationConfig
のパラメータの値を、ImagenModel インスタンスの作成の一部として設定します。
using Firebase.AI;
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
var config = new ImagenGenerationConfig(
numberOfImages: 2,
aspectRatio: ImagenAspectRatio.Landscape16x9,
imageFormat: ImagenImageFormat.Jpeg(100)
);
// Initialize the Gemini Developer API backend service
// Specify the config as part of creating the `ImagenModel` instance
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetImagenModel(
modelName: "imagen-4.0-generate-001",
generationConfig: config
);
// ...
各パラメータの説明 については、このページの次のセクションをご覧ください。
パラメータの説明(Imagen)
使用可能なパラメータの概要を以下に示します。
| パラメータ | 説明 | デフォルト値 |
|---|---|---|
ネガティブ プロンプト
negativePrompt
|
生成される画像から除外する内容の説明
このパラメータは、
|
--- |
結果の件数
numberOfImages
|
リクエストごとに返される生成された画像の数 | デフォルトは 1 画像 |
アスペクト比
aspectRatio
|
生成された画像の幅と高さの比 | デフォルトはスクエア(1:1) |
画像形式
imageFormat
|
出力オプション(画像形式(MIME タイプ)や生成された画像の圧縮レベルなど) | デフォルトの MIME タイプは PNG デフォルトの圧縮率は 75(MIME タイプが JPEG に設定されている場合) |
透かし
addWatermark
|
生成された画像に目に見えないデジタル透かし( SynthID)を追加するかどうか | デフォルトは true
|
人物生成
personGeneration
|
モデルによる人物の画像生成を許可するかどうか | デフォルトはモデルによって異なります |
安全性属性を含める
includeSafetyAttributes
|
フィルタリングされていない入力と出力のレスポンスで、安全性
属性のリストに対して丸められた責任ある AI スコアを有効にするかどうか 安全性属性のカテゴリ:
|
デフォルトは false |
seed パラメータ)
storageUri パラメータ)
enhancePrompt パラメータ)
コンテンツ生成を制御するその他のオプション
- プロンプト設計 の詳細を確認して、モデルがニーズに固有の出力を生成するようにします。
- 安全性設定を使用して、ヘイトスピーチや露骨な性的コンテンツなど、有害とみなされる可能性のあるレスポンスを取得する可能性を調整します。
- システム指示を設定して、モデルの動作を制御します。この機能は、エンドユーザーからの詳細な指示がモデルに伝達される前に追加する前文のようなものです。
- プロンプトとともにレスポンス スキーマ を渡して、特定の出力スキーマを指定します。この機能は JSON 出力を生成する場合に最もよく使用されますが、 分類タスク (モデルに特定のラベルやタグを使用させる場合など)にも使用できます。