在每次呼叫模型時,您可以傳送模型設定,以控制模型產生回應的方式。每個型號都提供不同的設定選項。
您可以嘗試使用提示和模型設定,並使用 Vertex AI Studio 快速進行疊代。
Gemini 設定選項 前往 Imagen 設定選項 前往
設定 Gemini 模型
本節將說明如何設定設定,以便搭配 Gemini 模型使用,並提供各個參數的說明。
設定模型設定 (Gemini)
一般用途的設定
在建立 GenerativeModel
例項時,請在 GenerationConfig
中設定參數值 (Kotlin | Java)。
系統會在執行個體的整個生命週期中維持設定。如果您想使用其他設定,請使用該設定建立新的 GenerativeModel
例項。
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
val config = generationConfig {
maxOutputTokens = 200
stopSequences = listOf("red")
temperature = 0.9f
topK = 16
topP = 0.1f
}
// Specify the config as part of creating the `GenerativeModel` instance
val generativeModel = Firebase.vertexAI.generativeModel(
modelName = "GEMINI_MODEL_NAME ",
generationConfig = config
)
// ...
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.maxOutputTokens = 200;
configBuilder.stopSequences = List.of("red");
configBuilder.temperature = 0.9f;
configBuilder.topK = 16;
configBuilder.topP = 0.1f;
GenerationConfig generationConfig = configBuilder.build();
// Specify the config as part of creating the `GenerativeModel` instance
GenerativeModel gm = FirebaseVertexAI.getInstance().generativeModel(
"GEMINI_MODEL_NAME ",
generationConfig
);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);
// ...
Gemini Live API 的設定
在建立 LiveModel
例項時,請在 LiveGenerationConfig
(Kotlin | Java) 中設定參數值。
系統會在執行個體的整個生命週期中維持設定。如果您想使用其他設定,請使用該設定建立新的 LiveModel
例項。
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here)
val config = liveGenerationConfig {
maxOutputTokens = 200
responseModality = ResponseModality.AUDIO
speechConfig = SpeechConfig(voice = Voices.FENRIR)
temperature = 0.9f
topK = 16
topP = 0.1f
}
// Specify the config as part of creating the `LiveModel` instance
val generativeModel = Firebase.vertexAI.liveModel(
modelName = "gemini-2.0-flash-live-preview-04-09",
generationConfig = config
)
// ...
// ...
// Set parameter values in a `LiveGenerationConfig` (example values shown here)
LiveGenerationConfig.Builder configBuilder = new LiveGenerationConfig.Builder();
configBuilder.setMaxOutputTokens(200);
configBuilder.setResponseModalities(ResponseModality.AUDIO);
configBuilder.setSpeechConfig(new SpeechConfig(Voices.FENRIR));
configBuilder.setTemperature(0.9f);
configBuilder.setTopK(16);
configBuilder.setTopP(0.1f);
LiveGenerationConfig generationConfig = configBuilder.build();
// Specify the config as part of creating the `LiveModel` instance
LiveGenerativeModel gm = FirebaseVertexAI.getInstance().liveModel(
"gemini-2.0-flash-live-preview-04-09",
generationConfig
);
LiveModelFutures model = LiveModelFutures.from(gm);
// ...
參數說明 (Gemini)
以下概略說明可用的參數 (如適用)。您可以在 Google Cloud 說明文件中找到完整的參數清單和參數值。
參數 | 說明 | 預設值 |
---|---|---|
音訊時間戳記
audioTimestamp
|
布林值,可讓系統針對僅含音訊的輸入檔案瞭解時間戳記。 僅適用於使用 |
false |
展示頻率處罰
frequencyPenalty
|
控制在產生的回覆中加入重複出現的符記的機率。 正值會對重複出現在生成內容中的符記加以懲罰,降低重複內容的機率。 |
--- |
輸出詞元數量上限
maxOutputTokens
|
指定回覆內可以生成的符記數量上限。 | --- |
外觀狀態處罰
presencePenalty
|
控制在產生的回覆中加入已出現的符記的機率。 正值會對已出現在產生內容中的符記處以懲罰,提高產生更多樣化內容的機率。 |
--- |
停止序列
stopSequences
|
指定字串清單,如果回應中遇到其中一個字串,就會指示模型停止產生內容。 僅適用於使用 |
--- |
溫度
temperature
|
控制回覆的隨機程度。 溫度越低,回覆就越確定;溫度越高,回覆就越多樣化或有創意。 |
視型號而定 |
Top-K
topK
|
限制產生內容中使用最高機率字詞的數量。 如果前 K 個值為 1 ,代表下一個所選詞元應為模型詞彙表中所有詞元中最可能的詞元,如果前 K 個值為 n ,則代表下一個所選詞元應從最可能的 n 個詞元中選取 (所有值皆根據設定的溫度參數)。 |
視型號而定 |
Top-P
topP
|
控管生成內容的多樣性。 模型會按照機率最高 (請見上方的 Top-K) 到最低的順序選取符記,直到所選符記的機率總和等於 Top-P 值。 |
視型號而定 |
回應模式
responseModality
|
指定使用 Live API 時的串流輸出類型,例如文字或音訊。 僅適用於使用 Live API 和 |
--- |
語音
speechConfig
|
指定使用 Live API 時,用於串流音訊輸出的語音。 僅適用於使用 Live API 和 |
Puck |
設定 Imagen 模型
本節將說明如何設定設定,以便搭配 Imagen 模型使用,並提供各個參數的說明。
設定模型設定 (Imagen)
在建立 ImagenModel
例項時,請在 ImagenGenerationConfig
(Kotlin | Java) 中設定參數值。
系統會在執行個體的整個生命週期中維持設定。如果您想使用其他設定,請使用該設定建立新的 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
)
// Specify the config as part of creating the `ImagenModel` instance
val imagenModel = Firebase.vertexAI.imagenModel(
modelName = "IMAGEN_MODEL_NAME ",
generationConfig = config
)
// ...
// ...
// 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
ImagenModel m = FirebaseVertexAI.getInstance().imagenModel(
"IMAGEN_MODEL_NAME ",
config
);
ImagenModelFutures model = ImagenModelFutures.from(m);
// ...
參數說明 (Imagen)
以下概略說明可用的參數 (如適用)。您可以在 Google Cloud 說明文件中找到完整的參數清單和參數值。
參數 | 說明 | 預設值 |
---|---|---|
負面提示
negativePrompt
|
說明您要在產生的圖片中省略哪些內容
|
--- |
結果數量
numberOfImages
|
每個要求傳回的產生圖片數量 | Imagen 3 型號的預設值為一張圖片 |
顯示比例
aspectRatio
|
生成圖片的寬高比 | 預設為正方形 (1:1) |
圖片格式
imageFormat
|
輸出選項,例如圖片格式 (MIME 類型) 和產生圖片的壓縮等級 | 預設 MIME 類型為 PNG 預設壓縮率為 75 (如果 MIME 類型設為 JPEG) |
浮水印
addWatermark
|
是否要在生成的圖像中加入隱形數位浮水印 (稱為 SynthID) | Imagen 3 型號的預設值為 true
|
人物生成
personGeneration
|
是否允許模型產生人物 | 預設值取決於模型 |
其他控管內容產生方式的選項
- 進一步瞭解提示設計,以便您影響模型,讓模型產生符合您需求的輸出內容。
- 您可以使用安全性設定調整可能會收到有害回覆的機率,包括仇恨言論和煽情露骨內容。
- 設定系統指示,引導模型的行為。這項功能就像是「前言」,可在模型向使用者提供任何進一步指示之前新增。
- 傳遞回覆結構定義和提示,即可指定特定輸出結構定義。這項功能最常用於產生 JSON 輸出內容,但也可以用於分類作業 (例如希望模型使用特定標籤或標記時)。