모델 구성을 사용하여 응답 제어

모델을 호출할 때마다 모델 구성을 함께 전송하여 모델의 대답 생성 방식을 제어할 수 있습니다. 각 모델은 서로 다른 구성 옵션을 제공합니다.

Google AI Studio를 사용하여 프롬프트와 모델 구성을 실험해 볼 수도 있습니다. Google AI Studio

Gemini 구성 옵션으로 이동 Imagen 구성 옵션으로 이동 (지원 중단)



Gemini 모델 구성

Gemini API 제공업체를 클릭하여 이 페이지에서 제공업체별 콘텐츠 및 코드를 확인합니다.

이 섹션에서는 구성을 설정하는 방법을 보여주고 Gemini 모델과 함께 사용할 각 매개변수에 대한 설명을 제공합니다.

모델 구성 설정 (Gemini)

일반적인 Gemini 사용 사례 구성

구성의 수명은 인스턴스의 수명과 동일합니다. 다른 구성을 사용하려면 해당 구성으로 새 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,
  temperature: 0.9,
  topP: 0.1,
  topK: 16,
  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")
    temperature = 0.9f
    topK = 16
    topP = 0.1f
}

// 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");
configBuilder.temperature = 0.9f;
configBuilder.topK = 16;
configBuilder.topP = 0.1f;

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"],
  temperature: 0.9,
  topP: 0.1,
  topK: 16,
};

// 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"],
  temperature: 0.9,
  topP: 0.1,
  topK: 16,
);

// 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" },
  temperature: 0.9f,
  topK: 16,
  topP: 0.1f
);

// 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 구성

구성의 수명은 인스턴스의 수명과 동일합니다. 다른 구성을 사용하려면 해당 구성으로 새 LiveModel 인스턴스를 만듭니다.

Swift

LiveModel 인스턴스를 초기화하는 동안 liveGenerationConfig 의 매개변수 값을 설정합니다.


// ...

// Set parameter values in a `LiveGenerationConfig` (example values shown here)
let config = LiveGenerationConfig(
  temperature: 0.9,
  topP: 0.1,
  topK: 16,
  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)
    temperature = 0.9f
    topK = 16
    topP = 0.1f
}

// 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));
configBuilder.setTemperature(0.9f);
configBuilder.setTopK(16);
configBuilder.setTopP(0.1f);

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 의 매개변수 값을 설정합니다.


// ...

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" },
    },
  },
  temperature: 0.9,
  topP: 0.1,
  topK: 16,
};

// 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'),
  temperature: 0.9,
  topP: 0.1,
  topK: 16,
);

// 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"),
  temperature: 0.9f,
  topK: 16,
  topP: 0.1f
);

// 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 Developer API 문서를 참조하세요.

매개변수 설명 기본값
오디오 타임스탬프
audioTimestamp

오디오 전용 입력 파일의 타임스탬프 이해를 사용 설정하는 불리언입니다.

generateContent 또는 generateContentStream 호출을 사용하고 입력 유형이 오디오 전용 파일인 경우에만 적용됩니다.

false
후보 수
candidateCount

반환할 응답 변형의 개수를 지정합니다. 각 요청에 대해 모든 후보의 출력 토큰이 청구되지만 입력 토큰은 한 번만 청구됩니다.

지원되는 값: 1 - 8 (포함)

generateContent 및 최신 Gemini 모델을 사용하는 경우에만 적용됩니다. Live API 모델 및 generateContentStream 은 지원되지 않습니다.

1
빈도 페널티
frequencyPenalty
생성된 응답에 반복적으로 표시되는 토큰을 포함할 확률을 제어합니다.
양수 값은 생성된 콘텐츠에 반복적으로 표시되는 토큰에 페널티를 적용하여 콘텐츠가 반복될 가능성을 줄입니다.
---
최대 출력 토큰
maxOutputTokens
응답에서 생성될 수 있는 토큰의 최대 개수를 지정합니다. ---
상태 페널티
presencePenalty
생성된 응답에 이미 표시된 토큰을 포함할 확률을 제어합니다.
양수 값은 생성된 콘텐츠에 이미 표시된 토큰에 페널티를 적용하여 다양한 콘텐츠가 생성될 가능성을 높입니다.
---
중지 시퀀스
stopSequences

문자열 중 하나가 응답에서 발견되면 모델에 콘텐츠 생성을 중지하도록 지시하는 문자열 목록을 지정합니다.

구성을 사용하는 경우에만 적용됩니다.GenerativeModel

---
온도
temperature
응답의 무작위 정도를 제어합니다.
온도가 낮을수록 더 결정적인 응답이 생성되고 온도가 높을수록 더 다양하거나 창의적인 응답이 생성됩니다.
모델에 따라 다름
Top-K
topK
생성된 콘텐츠에 사용되는 확률이 가장 높은 단어의 수를 제한합니다.
Top-K 값이 1이면 다음으로 선택된 토큰이 모델의 어휘에 포함된 모든 토큰 중에서 가장 확률이 높아야 한다는 의미입니다. 반면에 Top-K 값이 n이면 다음 토큰이 가장 확률이 높은 n 토큰 중에서 선택되어야 한다는 의미입니다 (모두 설정된 온도에 따라 다름).
모델에 따라 다름
Top-P
topP
생성된 콘텐츠의 다양성을 제어합니다.
토큰은 확률의 합이 Top-P 값과 같아질 때까지 확률이 가장 높은 것부터 (위의 Top-K 참조) 가장 낮은 것까지 선택됩니다.
모델에 따라 다름
응답 모드
responseModality

모델에서 Live API 또는 기본 멀티모달 출력을 사용할 때 스트리밍된 출력 유형(예: 텍스트, 오디오 또는 이미지)을 지정합니다.Gemini

Live API 모델을 사용하거나 멀티모달 출력이 가능한 Gemini 모델을 사용하는 경우에만 적용됩니다.

---
음성
speechConfig

Live API를 사용할 때 스트리밍된 오디오 출력에 사용되는 음성을 지정합니다. Live API.

Live API 모델을 사용하는 경우에만 적용됩니다.

Puck



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)

사용 가능한 매개변수의 대략적인 개요는 다음과 같습니다. 매개변수 및 해당 값의 전체 목록은 Google Cloud 문서를 참조하세요.

매개변수 설명 기본값
부정 프롬프트
negativePrompt
생성된 이미지에서 생략할 항목에 대한 설명입니다.

이 매개변수는 아직 imagen-3.0-generate-002에서 지원되지 않습니다.

---
결과 수
numberOfImages
각 요청에 대해 반환되는 생성된 이미지 수입니다. 기본값은 이미지 1개입니다.
가로세로 비율
aspectRatio
생성된 이미지의 너비 대 높이 비율입니다. 기본값은 정사각형 (1:1)입니다.
이미지 형식
imageFormat
생성된 이미지의 이미지 형식 (MIME 유형) 및 압축 수준과 같은 출력 옵션입니다. 기본 MIME 유형은 PNG
기본 압축은 75입니다 (MIME 유형이 JPEG로 설정된 경우).
워터마크
addWatermark
생성된 이미지에 표시되지 않는 디지털 워터마크 (SynthID라고 함)를 추가할지 여부입니다. 기본값은 true입니다.
인물 생성
personGeneration
모델에서 인물 생성을 허용할지 여부입니다. 기본값은 모델에 따라 다릅니다.
안전 속성 포함
includeSafetyAttributes
필터링되지 않은 입력 및 출력에 대한 응답에서 안전 속성 목록에 대해 반올림된 책임감 있는 AI 점수를 사용 설정할지 여부입니다.

안전 속성 카테고리: "Death, Harm & Tragedy", "Firearms & Weapons", "Hate", "Health", "Illicit Drugs", "Politics", "Porn", "Religion & Belief", "Toxic", "Violence", "Vulgarity", "War & Conflict".

기본값은 false입니다.



콘텐츠 생성을 제어하는 기타 옵션

  • 프롬프트 디자인 에 대해 자세히 알아보세요. 모델이 필요에 맞는 출력을 생성하도록 영향을 미칠 수 있습니다.
  • 안전 설정 을 사용하여 증오심 표현 및 성적으로 노골적인 콘텐츠를 비롯하여 유해하다고 간주될 수 있는 대답을 얻을 가능성을 조정합니다.
  • 시스템 요청 사항을 설정하여 모델의 동작을 조정합니다. 이 기능은 모델이 최종 사용자의 추가 요청 사항에 노출되기 전에 추가하는 프리앰블과 같습니다.
  • 프롬프트와 함께 대답 스키마 를 전달하여 특정 출력 스키마를 지정합니다. 이 기능은 JSON 출력을 생성할 때 가장 일반적으로 사용되지만 분류 작업에도 사용할 수 있습니다 (예: 모델이 특정 라벨 또는 태그를 사용하도록 하려는 경우).