모델에 대한 각 호출에서 모델 구성을 함께 전송하여 모델의 대답 생성 방식을 제어할 수 있습니다. 각 모델은 maxOutputTokens 설정 또는 사고, 응답 모달리티, 이미지, 음성을 위한 전문 구성과 같은 다양한 구성 옵션을 지원합니다.
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.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
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
GenerativeModel 인스턴스를 만드는 과정에서 GenerationConfig의 매개변수 값을 설정합니다.
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
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
GenerativeModel 인스턴스를 만드는 과정에서 GenerationConfig의 매개변수 값을 설정합니다.
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
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
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.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
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
GenerativeModel 인스턴스를 만드는 과정에서 GenerationConfig의 매개변수 값을 설정합니다.
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
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
GenerativeModel 인스턴스를 만드는 과정에서 GenerationConfig의 매개변수 값을 설정합니다.
// ...
// Set parameter values in a `GenerationConfig`.
// IMPORTANT: Example values shown here. Make sure to update for your use case.
// Note that temperature, top-K, and top-P are deprecated and ignored by the latest Gemini models.
var generationConfig = new GenerationConfig(
candidateCount: 1,
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를 사용하여 프롬프트와 모델 구성을 실험할 수 있습니다.매개변수 설명
다음 표는 사용 가능한 매개변수의 대략적인 개요입니다. 일부 매개변수는 특정 모델에만 적용됩니다.
온도, Top-K, Top-P는 지원이 중단되었으며 최신 Gemini 모델에서는 무시됩니다.
| 매개변수 | 설명 | 제한사항 | 기본값 |
|---|---|---|---|
오디오 타임스탬프audioTimestamp
|
오디오 전용 입력 파일의 타임스탬프 이해를 사용 설정합니다. |
불리언
|
false
|
후보 수candidateCount
|
반환할 응답 변형의 수를 지정합니다. 각 요청에 대해 모든 후보의 출력 토큰이 청구되지만 입력 토큰은 한 번만 청구됩니다. |
지원되는 값:
|
1
|
최대 출력 토큰maxOutputTokens
|
대답에서 생성될 수 있는 최대 토큰 수를 지정합니다. | --- | --- |
빈도 페널티frequencyPenalty
|
생성된 대답에 반복적으로 표시되는 토큰을 포함할 확률을 제어합니다. 양수 값은 생성된 콘텐츠에 반복적으로 표시되는 토큰에 페널티를 적용하여 콘텐츠가 반복될 가능성을 줄입니다. |
TTS 모델에는 적용되지 않습니다. | --- |
상태 페널티presencePenalty
|
생성된 대답에 이미 표시된 토큰을 포함할 확률을 제어합니다. 양수 값은 생성된 콘텐츠에 이미 표시된 토큰에 페널티를 적용하여 다양한 콘텐츠가 생성될 가능성을 높입니다. |
TTS 모델에는 적용되지 않습니다. | --- |
중지 시퀀스stopSequences
|
문자열 중 하나가 응답에서 발견되면 모델에 콘텐츠 생성을 중지하도록 지시하는 문자열 목록을 지정합니다. |
TTS 모델에는 적용되지 않습니다. |
--- |
| 특수 구성 | |||
생각 중thinkingConfig
|
모델이 대답을 생성할 때 모델의 '사고 과정'을 제어합니다.
|
지원되는 값: 사고 문서 참고 TTS 모델에는 적용되지 않습니다.
Firebase AI Logic에서는 Live API 모델의 |
모델에 따라 다름 |
응답 모달리티responseModalities
|
출력 유형 (예: 텍스트, 오디오, 이미지)을 지정합니다. | Gemini 이미지 모델('Nano Banana' 모델), TTS 모델, Live API 모델을 사용하는 경우에만 적용되며 필수입니다. | --- |
이미지 특성imageConfig
|
생성된 이미지의 가로세로 비율과 해상도를 지정합니다. |
지원되는 값: 이미지 생성 구성 참고 Gemini 이미지 모델 ('Nano Banana' 모델)을 사용하는 경우에만 적용됩니다. |
1:1 가로세로 비율 (정사각형) 1024x1024 해상도 |
음성speechConfig
|
오디오 출력에 사용되는 음성을 지정합니다. |
TTS 모델 및 Live API 모델을 사용하는 경우에만 적용됩니다. TTS 모델에 필요합니다. |
Puck
|
콘텐츠 생성을 제어하는 다른 옵션
- 프롬프트 디자인에 대해 자세히 알아보세요. 모델이 내 요구사항에 맞는 출력을 생성하도록 영향을 줄 수 있습니다.
- 안전 설정을 사용하여 증오심 표현, 음란물 등 유해하다고 간주될 수 있는 대답을 받을 가능성을 조정합니다.
- 시스템 요청 사항을 설정하여 모델의 동작을 조정합니다. 이 기능은 모델이 최종 사용자의 추가 안내에 노출되기 전에 추가하는 프리앰블과 같습니다.
- 프롬프트와 함께 대답 스키마를 전달하여 특정 출력 스키마를 지정합니다. 이 기능은 JSON 출력을 생성할 때 가장 흔히 사용되지만 분류 작업(예: 모델이 특정 라벨이나 태그를 사용하도록 하려는 경우)에도 사용할 수 있습니다.