생성형 AI 모델의 사용 가능 여부는 자주 변경됩니다. 새롭고 더 나은 모델이 출시되고 오래되고 성능이 낮은 모델은 지원이 중단됩니다.
Firebase AI Logic를 사용하여 모바일 또는 웹 앱에서 생성형 AI 모델에 직접 액세스하는 경우 이러한 빈번한 모델 변경사항을 수용하도록 앱을 구성하는 것이 중요합니다. 모든 사용자가 사용해야 하는 모델을 사용하기 위해 앱의 최신 버전으로 업데이트하는 것은 아닙니다.
Firebase Remote Config을 사용하면 새 버전의 앱을 출시하지 않고도 Firebase 콘솔에서 앱의 파라미터 값 (예: 모델 이름)을 동적으로 원격으로 업데이트할 수 있습니다.
모델 이름 변경은 Firebase AI Logic와 함께 Remote Config를 사용하는 중요한 사용 사례이지만, Remote Config를 사용하여 모델 생성 구성 (최대 토큰, 온도 등), 안전 설정, 시스템 안내, 프롬프트 데이터와 같은 앱의 매개변수를 동적으로, 심지어 조건부로 제어할 수도 있습니다.
이 가이드에서는 앱에서 Remote Config를 구현하여 앱에서 사용되는 모델 이름을 제어하는 방법을 설명합니다.
1단계: Firebase 콘솔에서 파라미터 값 설정
Remote Config 클라이언트 템플릿을 만들고 앱에서 가져와 사용할 model_name 매개변수와 값을 구성합니다.
Firebase 콘솔에서 Firebase 프로젝트를 엽니다. 그런 다음 탐색 메뉴에서 실행을 펼치고 Remote Config을 선택합니다.
페이지 상단의 클라이언트/서버 선택기에서 클라이언트가 선택되어 있는지 확인합니다.
구성 만들기(또는 이전에 클라이언트 템플릿을 사용한 적이 있는 경우 파라미터 추가)를 클릭하여 클라이언트 템플릿을 시작합니다.
model_name매개변수를 정의합니다.매개변수 이름 설명 유형 기본값 model_name모델 이름입니다. 사용 가능한 모델 이름을 참조하세요. 문자열 gemini-2.5-flash이 매개변수를 추가한 후 변경사항 게시를 클릭합니다. 새 Remote Config 템플릿이 아닌 경우 변경사항을 검토하고 변경사항 게시를 다시 클릭합니다.
2단계: 앱에 Remote Config 추가 및 초기화
Remote Config 라이브러리를 추가하고 앱 내에서 Remote Config을 설정합니다.
Swift
Firebase AI Logic 설정의 일환으로 이미 Firebase SDK를 앱에 추가했지만 Remote Config도 추가해야 합니다.
Xcode에서 프로젝트를 연 상태로 파일 > 패키지 종속 항목 추가로 이동합니다.
firebase-ios-sdk를 선택한 다음 패키지 추가를 클릭합니다.
프로젝트 탐색기에서 앱 > 대상 > 앱을 선택합니다.
일반 탭에서 프레임워크, 라이브러리, 삽입된 콘텐츠로 스크롤합니다.
+를 클릭하고 FirebaseRemoteConfig를 선택한 다음 추가를 클릭합니다.
코드에
FirebaseRemoteConfig가져오기를 추가합니다.import FirebaseRemoteConfig앱에 적합한 클래스에서 Firebase를 초기화하고 기본 애플리케이션 로직에 Remote Config을 추가합니다.
여기서는 앱이 실시간으로 새 값을 가져올 수 있도록 Remote Config 및 Remote Config 실시간 리스너를 가져오기로 포함하고 최소 가져오기 간격을 추가합니다.
let remoteConfig = RemoteConfig.remoteConfig() let settings = RemoteConfigSettings() settings.minimumFetchInterval = 3600 remoteConfig.configSettings = settings
Kotlin
모듈(앱 수준) Gradle 파일(일반적으로
app/build.gradle.kts또는app/build.gradle)에 Remote Config 종속 항목을 추가합니다.dependencies { implementation(platform("com.google.firebase:firebase-bom:34.5.0")) implementation("com.google.firebase:firebase-ai") implementation("com.google.firebase:firebase-config") // ... other dependencies }기본 애플리케이션 로직에 Remote Config을 추가합니다. 여기서는 Remote Config을 초기화하고 최소 가져오기 간격을 추가합니다.
val remoteConfig: FirebaseRemoteConfig = Firebase.remoteConfig val configSettings = remoteConfigSettings { minimumFetchIntervalInSeconds = 3600 } remoteConfig.setConfigSettingsAsync(configSettings)
Java
모듈(앱 수준) Gradle 파일(일반적으로
app/build.gradle.kts또는app/build.gradle)에 Remote Config 종속 항목을 추가합니다.dependencies { implementation(platform("com.google.firebase:firebase-bom:34.5.0")) implementation("com.google.firebase:firebase-ai") implementation("com.google.firebase:firebase-config") // ... other dependencies }기본 애플리케이션 로직에 Remote Config을 추가합니다. 여기서는 Remote Config을 초기화하고 최소 가져오기 간격을 추가합니다.
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder() .setMinimumFetchIntervalInSeconds(3600) .build(); mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
Web
텍스트 편집기에서 코드를 열고 Remote Config을 가져옵니다.
import { getRemoteConfig } from 'firebase/remote-config';기본 함수 내에서 Firebase AI Logic SDK에 대해 Firebase 앱이 초기화된 후 Remote Config을 초기화합니다.
// Initialize Remote Config and get a reference to the service const remoteConfig = getRemoteConfig(app);가져오기 간격 최솟값을 설정합니다.
remoteConfig.settings.minimumFetchIntervalMillis = 3600000;
Dart
Flutter 프로젝트 디렉터리에서 다음 명령어를 사용하여 Remote Config을 설치하고 추가합니다.
flutter pub add firebase_remote_config./lib/main.dart를 열고 Firebase AI Logic를 지원하기 위해 추가한 다른 가져오기 뒤에 가져오기를 추가합니다.import 'package:firebase_vertexai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_remote_config/firebase_remote_config.dart';나중에 사용할 수 있도록 앱에
_modelName변수를 추가합니다.late final String _modelName; late final String _systemInstructions; late final String _prompt;Remote Config 객체 인스턴스를 가져온 뒤 가져오기 간격을 최솟값으로 설정하여 상시적으로 새로고침을 할 수 있도록 합니다. Firebase가 초기화된 후에 추가해야 합니다.
final remoteConfig = FirebaseRemoteConfig.instance; await remoteConfig.setConfigSettings(RemoteConfigSettings( fetchTimeout: const Duration(seconds: 3600), minimumFetchInterval: const Duration(seconds: 3600), ));
Unity
이 안내에 따라 Unity 프로젝트에 Remote Config을 추가합니다.
Remote Config 객체 인스턴스를 가져온 뒤 가져오기 간격을 최솟값으로 설정하여 상시적으로 새로고침을 할 수 있도록 합니다. Firebase가 초기화된 후에 추가해야 합니다.
var remoteConfig = FirebaseRemoteConfig.DefaultInstance; const int MillisecondsPerSecond = 1000; await remoteConfig.SetConfigSettingsAsync(new ConfigSettings() { FetchTimeoutInMilliseconds = 3600 * MillisecondsPerSecond, MinimumFetchIntervalInMilliseconds = 3600 * MillisecondsPerSecond });
3단계: 인앱 파라미터 값 설정
Remote Config 객체에서 인앱 기본 파라미터 값을 설정해야 합니다. 이렇게 하면 앱이 Remote Config 서비스에서 값을 가져올 수 없더라도 예상대로 동작합니다.
Swift
Firebase Console에서 Remote Config을 엽니다.
파라미터 탭에서 메뉴를 열고 기본값 다운로드를 선택합니다.
메시지가 표시되면 iOS의 경우 .plist를 사용 설정하고 파일 다운로드를 클릭합니다.
애플리케이션 디렉터리에 파일을 저장합니다.
Xcode에서 앱을 마우스 오른쪽 버튼으로 클릭하고 파일 추가를 선택합니다.
remote_config_defaults.plist를 선택한 다음 추가를 클릭합니다.
기본 파일을 참조하도록 앱 코드를 업데이트합니다.
// Set default values for Remote Config parameters. remoteConfig.setDefaults(fromPlist: "remote_config_defaults")
Kotlin
Firebase Console에서 Remote Config을 엽니다.
파라미터 탭에서 메뉴를 열고 기본값 다운로드를 선택합니다.
메시지가 표시되면 Android의 경우 .xml을 사용 설정한 후 파일 다운로드를 클릭합니다.
앱의 XML 리소스 디렉터리에 파일을 저장합니다.
이전에 추가한
configSettings뒤에 기본값을 추가하도록 기본 활동 파일을 업데이트합니다.// Set default values for Remote Config parameters. remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
Java
Firebase Console에서 Remote Config을 엽니다.
파라미터 탭에서 메뉴를 열고 기본값 다운로드를 선택합니다.
메시지가 표시되면 Android의 경우 .xml을 사용 설정한 후 파일 다운로드를 클릭합니다.
앱의 XML 리소스 디렉터리에 파일을 저장합니다.
이전에 추가한
configSettings뒤에 기본값을 추가하도록 기본 활동 파일을 업데이트합니다.// Set default values for Remote Config parameters. mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config_defaults);
Web
코드에서 직접 모델 이름의 기본값을 설정할 수 있습니다.
// Set default values for Remote Config parameters.
remoteConfig.defaultConfig = {
model_name: 'gemini-2.5-flash',
};
Dart
코드에서 직접 모델 이름의 기본값을 설정할 수 있습니다.
// Set default values for Remote Config parameters.
remoteConfig.setDefaults(const {
"model_name": "gemini-2.5-flash"
});
Unity
코드에서 직접 모델 이름의 기본값을 설정할 수 있습니다.
// Set default values for Remote Config parameters.
await remoteConfig.SetDefaultsAsync(
new System.Collections.Generic.Dictionary<string, object>() {
{ "model_name", "gemini-2.5-flash" }
}
);
4단계: 값 가져오기 및 활성화
모델 이름의 기본값을 설정한 후 다음을 추가하여 값을 가져오고 활성화합니다.
Swift
// Fetch and activate Remote Config values
remoteConfig.fetchAndActivate { status, error in
if let error = error {
print("Error fetching Remote Config: \(error.localizedDescription)")
}
}
이렇게 하면 새 Remote Config 템플릿이 게시될 때마다 Remote Config 객체가 업데이트됩니다.
Kotlin
// Fetch and activate Remote Config values
remoteConfig.fetchAndActivate()
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
val updated = task.result
Log.d(TAG, "Remote Config values fetched and activated: $updated")
} else {
Log.e(TAG, "Error fetching Remote Config", task.exception)
}
}
Java
// Fetch and activate Remote Config values
mFirebaseRemoteConfig.fetchAndActivate()
.addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
boolean updated = task.getResult();
Log.d(TAG, "Config params updated: " + updated);
} else {
Log.e(TAG, "Error fetching Remote Config", task.exception)
}
}
});
Web
가져오기에
getValue및fetchAndActivate를 추가합니다.import { getValue, fetchAndActivate } from 'firebase/remote-config';모델 이름의 기본값을 지정하는 코드를 찾습니다. 해당 코드 블록 바로 뒤에 다음 코드를 추가하여 구성을 가져와 활성화하고 가져온 값을
modelName상수에 할당합니다.// Fetch and activate Remote Config. try { await fetchAndActivate(remoteConfig); } catch(err) { console.error('Remote Config fetch failed', err); } console.log('Remote Config fetched.'); // Assign Remote Config values. const modelName = getValue(remoteConfig, 'model_name').asString();
Dart
// Fetch and activate Remote Config.
remoteConfig.fetchAndActivate();
// Assign Remote Config values.
String? _modelName = remoteConfig.getString("model_name");
Unity
// Fetch and activate Remote Config values.
await remoteConfig.FetchAndActivateAsync();
5단계: 실시간 Remote Config 리스너 추가
Remote Config 템플릿에 적용한 변경사항이 업데이트되는 즉시 클라이언트로 전파되도록 앱에 실시간 Remote Config 리스너를 추가합니다.
다음 코드는 파라미터 값이 변경될 때마다 Remote Config 객체를 업데이트합니다.
Swift
// Add real-time Remote Config
remoteConfig.addOnConfigUpdateListener { configUpdate, error in
guard let configUpdate = configUpdate, error == nil else {
print("Error listening for config updates: \(error?.localizedDescription ?? "No error available")")
return
}
print("Updated keys: \(configUpdate.updatedKeys)")
remoteConfig.activate { changed, error in
guard error == nil else {
print("Error activating config: \(error?.localizedDescription ?? "No error available")")
return
}
print("Activated config successfully")
}
}
Kotlin
원하는 경우 addOnCompleteListener 활성화 내에서 작업을 구성할 수도 있습니다.
// Add a real-time Remote Config listener
remoteConfig.addOnConfigUpdateListener(object : ConfigUpdateListener {
override fun onUpdate(configUpdate : ConfigUpdate) {
Log.d(ContentValues.TAG, "Updated keys: " + configUpdate.updatedKeys);
remoteConfig.activate().addOnCompleteListener {
// Optionally, add an action to perform on update here.
}
}
override fun onError(error : FirebaseRemoteConfigException) {
Log.w(ContentValues.TAG, "Config update error with code: " + error.code, error)
}
}
Java
원하는 경우 addOnCompleteListener 활성화 내에서 작업을 구성할 수도 있습니다.
// Add a real-time Remote Config listener
remoteConfig.addOnConfigUpdateListener(new ConfigUpdateListener() {
@Override
public void onUpdate(ConfigUpdate configUpdate) {
Log.d(ContentValues.TAG, "Updated keys: " + configUpdate.getUpdatedKeys());
remoteConfig.activate().addOnCompleteListener(new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
// Optionally, add an action to perform on update here.
}
});
}
@Override
public void onError(FirebaseRemoteConfigException error) {
Log.w(ContentValues.TAG, "Config update error with code: " + error.getCode(), error);
}
});
Web
웹 앱에는 실시간 Remote Config 리스너가 지원되지 않습니다.
Dart
// Add a real-time Remote Config listener
remoteConfig.onConfigUpdated.listen((event) async {
await remoteConfig.activate();
});
Unity
// Add a real-time Remote Config listener to automatically update whenever
// a new template is published.
// Note: the parameters can be anonymous as they are unused.
remoteConfig.OnConfigUpdateListener += (_, _) => {
remoteConfig.ActivateAsync();
};
6단계: Remote Config 값을 사용하도록 Gemini API 요청 업데이트
|
Gemini API 제공업체를 클릭하여 이 페이지에서 제공업체별 콘텐츠와 코드를 확인합니다. |
이제 Remote Config이 완전히 구성되었으므로 하드코딩된 값을 Remote Config에서 가져온 값으로 대체하도록 코드를 업데이트합니다.
Swift
import FirebaseAI
// When creating a `GenerativeModel` instance, source the model name value from Remote Config
let modelName = remoteConfig.configValue(forKey: "model_name").stringValue
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: modelName
)
// ...
Kotlin
// When creating a `GenerativeModel` instance, source the model name value from Remote Config
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = remoteConfig.getString("model_name")
)
// ...
Java
// When creating a `GenerativeModel` instance, source the model name value from Remote Config
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ remoteConfig.getString("model_name"),
/* generationConfig (optional) */ null,
/* safetySettings (optional) */ null,
/* requestOptions (optional) */ new RequestOptions(),
/* tools (optional) */ null,
/* toolsConfig (optional) */ null,
/* systemInstruction (optional) */ null,
);
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// ...
Web
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// When creating a `GenerativeModel` instance, source the model name value from Remote Config
const model = getGenerativeModel(ai, {
model: modelName
});
// ...
Dart
// ...
// When creating a `GenerativeModel` instance, source the model name value from Remote Config
final model = FirebaseAI.googleAI().generativeModel(
model: _modelName,
);
// ...
Unity
// ...
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// When creating a `GenerativeModel` instance, source the model name value from Remote Config
var modelName = remoteConfig.GetValue("model_name").StringValue;
var model = ai.GetGenerativeModel(
modelName: modelName
);
// ...
7단계: 앱 실행
앱을 빌드하고 실행하여 작동하는지 확인합니다. Firebase Console의 Remote Config 페이지에서 구성을 변경하고 변경사항을 게시한 후 결과를 확인합니다.
다음 단계
기타 Remote Config 및 Firebase AI Logic 사용 사례 구현에 대해 자세히 알아보세요.
모바일 앱 및 게임의 경우:
Remote Config 및 A/B Testing으로 다양한 모델 설정을 테스트합니다.
Remote Config 출시를 사용하여 모델 파라미터 변경사항을 점진적으로 출시합니다(iOS+ 및 Android만 해당).
Remote Config 맞춤설정을 사용하여 머신러닝을 통해 개별 사용자에게 가장 적합한 설정을 결정합니다(iOS+, Android, Unity만 해당).