Prompt API를 사용하면 앱에서 사용하는 Gemini Nano 버전을 명시적으로 선택할 수 있습니다. 모델 출시 단계 및 성능 환경설정을 구성하면 새로운 모델 기능을 더 일찍 이용하거나 특정 하드웨어 제약조건에 맞게 앱을 최적화할 수 있습니다.
모델 구성 이해
특정 모델을 선택하려면 ModelConfig 클래스 내에서 출시 단계 와 모델 환경설정 이라는 두 가지 주요 매개변수를 구성해야 합니다.
출시 단계
출시 단계를 사용하면 안정적인 모델과 미리보기 모델 중에서 선택할 수 있습니다.
- 안정적 (
ModelReleaseStage.STABLE): 완전히 테스트를 거쳤으며 소비자 기기에 있는 최신 모델 버전을 선택합니다. 기본 설정입니다. - 미리보기 (
ModelReleaseStage.PREVIEW): 미리보기 단계의 최신 모델 버전을 선택합니다. 이 단계를 사용하면 안정적인 단계에 광범위하게 배포되기 전에 베타 기능 또는 최신 모델 아키텍처를 테스트할 수 있습니다.
개발자 미리보기를 위한 기본 요건 및 등록 안내는 AICore 개발자 미리보기 가이드를 참고하세요.
모델 환경설정
모델 환경설정을 사용하면 사용 사례에 가장 중요한 성능 특성을 지정할 수 있습니다.
- 전체 (
ModelPreference.FULL): 속도보다 모델 정확성과 전체 기능이 우선시되는 경우 이 환경설정을 사용하는 것이 좋습니다. - 빠름 (
ModelPreference.FAST): 최소 응답 시간이 필요한 지연 시간에 민감한 앱에 이 환경설정을 사용하는 것이 좋습니다.
생성 모델 구성
특정 모델 변형을 사용하려면 ModelConfig를 정의하고 클라이언트를 초기화할 때 GenerationConfig에 전달해야 합니다.
다음 예에서는 미리보기 단계에서 빠른 모델을 사용하도록 클라이언트를 구성하는 방법을 보여줍니다.
Kotlin
// Define the configuration with a specific stage and preference
val previewFastConfig = generationConfig {
modelConfig = modelConfig {
releaseStage = ModelReleaseStage.PREVIEW
preference = ModelPreference.FAST
}
}
// Initialize the GenerativeModel with the configuration
val generativeModel = Generation.getClient(previewFastConfig)
자바
// Define the configuration with a specific stage and preference
GenerationConfig previewFastConfig = new GenerationConfig.Builder()
.setModelConfig(new ModelConfig.Builder()
.setReleaseStage(ModelReleaseStage.PREVIEW)
.setPreference(ModelPreference.FAST)
.build())
.build();
// Initialize the GenerativeModel with the configuration
GenerativeModel generativeModel = Generation.INSTANCE.getClient(previewFastConfig);
모델 사용 가능 여부 확인
모든 기기가 출시 단계와 모델 환경설정의 모든 조합을 지원하는 것은 아닙니다. 미리보기 모델은 AICore 개발자 미리보기 가이드의 지원되는 기기 목록에서만 사용할 수 있습니다.
API는 사용 가능한 모든 모델 구성을 미리 나열하는 메서드를 제공하지 않습니다. 대신 원하는 구성으로 클라이언트를 초기화한 후 상태를 확인합니다.
- 클라이언트 초기화: 원하는
ModelConfig를 사용하여GenerativeModel인스턴스를 만듭니다. 상태 확인: 인스턴스에서
checkStatus()메서드를 호출하여 특정 모델 변형이 기기에서 사용 가능한지 확인합니다.
Kotlin
val generativeModel = Generation.getClient(previewFastConfig)
// Verify that the specific preview model is available
val status = generativeModel.checkStatus()
when (status) {
FeatureStatus.UNAVAILABLE -> {
// Specified preview model is not available on this device
}
FeatureStatus.DOWNLOADABLE -> {
// Specified preview model is available for this device, but not downloaded yet.
// Model may be downloaded through the AICore app or by calling generativeModel.download()
}
FeatureStatus.AVAILABLE -> {
// Proceed with inference
}
FeatureStatus.DOWNLOADING -> {
// Specified preview model is downloading
}
}
자바
GenerativeModel generativeModel = Generation.INSTANCE.getClient(previewFastConfig);
// For Java, use GenerativeModelFutures if you prefer ListenableFuture
GenerativeModelFutures generativeModelFutures = GenerativeModelFutures.from(generativeModel);
Futures.addCallback(
generativeModelFutures.checkStatus(),
new FutureCallback<Integer>() {
@Override
public void onSuccess(Integer status) {
if (status == FeatureStatus.AVAILABLE) {
// Proceed with inference
} else if (status == FeatureStatus.DOWNLOADING) {
// Specified preview model is downloading
} else if (status == FeatureStatus.DOWNLOADABLE) {
// Specified preview model is available for this device, but not downloaded yet.
// Call generativeModelFutures.download(callback) or use the AICore app.
} else if (status == FeatureStatus.UNAVAILABLE) {
// Specified preview model is not available on this device
}
}
@Override
public void onFailure(Throwable t) {
// Handle failure
}
},
ContextCompat.getMainExecutor(context));
향후 구성과의 호환성을 보장하기 위해 SDK는 클라이언트 초기화 중에 GenAiException이 발생하지 않도록 설계되었으며, 사용 가능 여부 확인을 위해 checkStatus() 메서드만 사용합니다.
권장사항
- 대체 전략 구현: 미리보기 모델은 모든 기기에서 사용 가능하지 않을 수 있으므로 항상 대체 전략을 구현하세요. 미리보기 구성에 대해
checkStatus()가false를 반환하면 앱이ModelReleaseStage.STABLE및ModelPreference.FULL로 정상적으로 되돌아가야 합니다. - 개발 및 프로덕션에 모델 출시 단계 사용: 개발 및 내부 테스트 중에 미리보기 단계를 사용하여 예정된 모델 개선사항을 평가합니다. 공개 프로덕션 출시의 경우 안정적 으로 전환하여 사용자에게 일관된 동작을 보장합니다.
알려진 문제
- 미리보기 출시 단계의 일부 기기는 출력에서 여러 후보를 지원하지 않으며
candidateCount가 1보다 크게 설정된 경우 오류를 반환합니다. 자세한 내용은 API 참조를 확인하세요. - 일부 구현에서는 여러 샘플이 지원되지 않습니다. 성능이 최종 프로덕션보다 느립니다.
- 현재 이미지 입력은 Pixel 10에서만 작동합니다.
nanov4-fast모델은 일부 기기에서 특정 프롬프트에 대해 잘못된 응답을 제공할 수 있습니다.