Firebase AI Logic SDK を使用してアプリから Gemini API を呼び出すと、生成 AI のレスポンスを制御するパラメータの数がリクエストに含まれます。通常、これらにはモデル名、モデル生成の構成(最大トークン数、温度など)、安全性設定、システム指示、プロンプト データが含まれます。
ほとんどの場合、これらは、さまざまなシナリオで、オンデマンドで、または必要に応じて変更する必要があります。
- 新しいアプリをリリースせずに生成 AI モデルを更新します。以前のバージョンが廃止される前に、新しい安定したモデル バージョンにアップグレードできます。また、ユーザーのニーズと属性に基づいて、低コストまたは高パフォーマンスのモデルに切り替えたり、最新かつ最高のモデルを特定のユーザー セグメント(ベータ版テスターなど)に条件付きでデプロイしたりすることもできます。
- モデルにアクセスするロケーションがユーザーに近い場所になるように設定します。
- さまざまなシステム指示とプロンプトに A/B テストを実行し、優れたテスト値をユーザーに段階的に展開します。
- フィーチャー トグルを使用して、アプリで生成 AI 機能をすばやく公開するか、非表示にします。
Firebase Remote Config は、このすべての機能を実行します。これにより、新しいバージョンのアプリをリリースしなくても、Firebase コンソールで設定した特性に一致するアプリ インスタンスに対して、必要に応じてパラメータ値の条件付き更新を実行できます。
このソリューション ガイドでは、推奨される具体的なユースケースと、生成 AI アプリに Remote Config を追加する方法について説明します。
アプリで Firebase Remote Config を使用する理由
Firebase Remote Config を使用すると、アプリをアップデートしなくても、アプリの動作を動的に調整できます。この方法は、迅速な反復処理と微調整が重要になる、生成 AI を使用するアプリで特に便利です。
生成 AI アプリに不可欠な Remote Config のユースケース
次の不可欠なユースケースでは、Remote Config と Firebase AI Logic を使用することをおすすめします。
アプリを更新せずに最新のモデル バージョンにアップグレードする: Remote Config パラメータを使用して必要に応じてモデル名を変更し、優先する Gemini モデルの最新バージョンが利用可能になり次第、アップグレードできるようにします。
アプリのアップデートなしでシステム指示と安全性の設定を更新する: システム指示と安全性の設定を Remote Config パラメータ内に保存し、デプロイ後に問題が見つかった場合にオンデマンドで変更できるようにします。
リスクを軽減し、AI の安全性を強化する: Remote Config のロールアウトを使用して、生成 AI の変更を iOS ユーザーと Android ユーザーに安全かつ段階的にリリースします。
Remote Config と生成 AI アプリを使用する場合におすすめの高度なユースケース
Remote Config と Google Analytics でアプリを計測したら、高度なユースケースを確認してください。
クライアントの位置情報に基づいてロケーションを設定する: Remote Config の条件を使用して、クライアントで検出された位置情報に基づいてモデルにアクセスするロケーションを設定します。
さまざまなモデルを試す: さまざまな生成 AI モデルをすばやくテストして切り替えたり、さまざまなユーザー セグメントに応じてさまざまなモデルにアクセスしたりして、特定のユースケースに最適なモデルを見つけることができます。
モデルのパフォーマンスを最適化する: システム プロンプト、最大出力トークン、温度などのモデル パラメータを微調整します。
クライアント属性に基づいてさまざまなシステム指示、プロンプト、モデル構成を使用する: Remote Config と Google Analytics を使用すると、クライアント属性またはカスタム オーディエンスに基づいて条件を作成し、これらの属性に基づいてさまざまなパラメータを設定できます。
たとえば、生成 AI を使用してアプリでテクニカル サポートを行っている場合は、アプリ プラットフォームに固有のシステム指示を設定して、Android、iOS、ウェブ プラットフォームのユーザーに正確な指示を提供できます。
ユーザーごとにエクスペリエンスをパーソナライズする: モバイルアプリやゲームで Remote Config パーソナライズを使用して、各ユーザーに最適な生成 AI 設定を自動的に決定します。
費用を管理する: 呼び出される生成 AI モデルとその使用頻度をリモートで調整し、ユーザー オーディエンスに基づいて出力トークンの最大値を動的に構成して、不要な費用を削減します。
アプリ エクスペリエンスと結果を最適化する: モバイルアプリやゲームで A/B Testing と Remote Config を使用して、さまざまなユーザー セグメントで生成 AI パラメータの変更をテストし、維持率や収益などの主要な指標に与える影響を確認します。
Firebase Remote Config で生成 AI アプリを計測することで、ユーザーに優れたエクスペリエンスを提供しながら、柔軟で安全、かつ費用対効果の高い AI 搭載アプリケーションを構築できます。
Firebase Remote Config をアプリに追加します。
このソリューション ガイドでは、Firebase Remote Config を使用して、Firebase AI Logic SDK を使用する Android アプリのパラメータを動的に更新します。ここでは以下について学びます。
- モデル名やシステム指示などのパラメータを Firebase Remote Config からフェッチして、有効にします。
- 動的に取得されたパラメータを使用するように Gemini API 呼び出しを更新して、アプリを更新しなくても、さまざまなモデルを切り替えたり、システム指示を変更したりできるようにします。
- パラメータをリモートで制御し、必要に応じてモデルの動作と機能を調整します。
前提条件
このガイドは、プラットフォーム向けのアプリ開発に精通していることを前提としています。
始める前に、以下の点を確認してください。
Firebase AI Logic スタートガイドを完了します。このガイドでは、Firebase プロジェクトを設定し、アプリを Firebase に接続し、SDK を追加し、選択した「Gemini API」プロバイダのバックエンド サービスを初期化し、モデル インスタンスを作成する方法について説明しています。
Firebase プロジェクトで Google Analytics を有効にして、その SDK をアプリに追加します(クライアント デバイスの位置情報に基づいてモデルにアクセスするロケーションを設定するなど、条件付きターゲティングに必要です)。
ステップ 1: Firebase コンソールでパラメータ値を設定する
クライアント Remote Config テンプレートを作成し、アプリでフェッチして使用するパラメータと値を構成します。
- Firebase コンソールで Firebase プロジェクトを開きます。次に、ナビゲーション メニューから [実行] を開き、Remote Config を選択します。
- ページ上部にある [クライアント/サーバー] セレクタで [クライアント] が選択されていることを確認します。
- [構成を作成](または、クライアント テンプレートを以前に使用したことがある場合は [パラメータを追加])をクリックして、クライアント テンプレートを開始します。
Remote Config で制御するパラメータを定義します。次に例を示します。
パラメータ名 説明 型 デフォルト値 model_name
モデル名。使用可能なモデル名をご覧ください。 文字列 gemini-2.0-flash
system_instructions
システム指示は、モデルが公開される前にモデルの動作に影響を与えるエンドユーザーからの詳細な手順に追加される「プリアンブル」のようなものです。 文字列 You are a helpful assistant who knows everything there is to know about Firebase!
prompt
生成 AI 機能で使用するデフォルトのプロンプト。 文字列 I am a developer who wants to know more about Firebase!
vertex_location
Vertex AI Gemini API を使用している場合にのみ適用されます。
モデルにアクセスするロケーションを制御します。Google Analytics によって検出されたクライアントの位置情報に基づいて、このオプションを構成する条件を設定できます。文字列 us-central1
パラメータの追加が完了したら、[変更を公開] をクリックします。新しい 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
クイックスタート アプリでは、これは
AppDelegate
クラスのVertexAISampleApp
内にあります。
Kotlin
モジュール(アプリレベル)の Gradle ファイル(通常は
app/build.gradle.kts
またはapp/build.gradle
)に Remote Config 依存関係を追加します。dependencies { implementation(platform("com.google.firebase:firebase-bom:33.14.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:33.14.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 アプリが Firebase AI Logic SDK 用に初期化されたら、プライマリ関数内で 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
、_systemInstructions
、_prompt
の各変数をアプリに追加します。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
こちらの手順に沿って、Remote Config を Unity プロジェクトに追加します。
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 コンソールで Remote Config を開きます。
[Parameters] タブで [メニュー] を開き、[デフォルト値をダウンロード] を選択します。
メッセージが表示されたら、[.plist(iOS 用)] を有効にして、[ファイルをダウンロード] をクリックします。
ファイルをアプリケーション ディレクトリに保存します。
サンプルアプリを使用している場合は、
FirebaseVertexAI/Sample/VertexAISample
内に保存します。Xcode でアプリを右クリックし、[ファイルを追加] を選択します。
サンプルを使用している場合は、[VertexAISample] を右クリックして [ "VertexAISample" にファイルを追加] を選択します。
[remote_config_defaults.plist] を選択し、[追加] をクリックします。
デフォルト ファイルを参照するようにアプリコードを更新します。
// Set default values remoteConfig.setDefaults(fromPlist: "remote_config_defaults")
Kotlin
Firebase コンソールで Remote Config を開きます。
[Parameters] タブで [メニュー] を開き、[デフォルト値をダウンロード] を選択します。
プロンプトが表示されたら、[.xml(Android 用)] を有効にして、[ファイルをダウンロード] をクリックします。
ファイルをアプリの XML リソース ディレクトリに保存します。
メイン アクティビティ ファイルを更新して、前に追加した
configSettings
の後にデフォルトを追加します。// Set default values. remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
Java
Firebase コンソールで Remote Config を開きます。
[Parameters] タブで [メニュー] を開き、[デフォルト値をダウンロード] を選択します。
プロンプトが表示されたら、[.xml(Android 用)] を有効にして、[ファイルをダウンロード] をクリックします。
ファイルをアプリの XML リソース ディレクトリに保存します。
メイン アクティビティ ファイルを更新して、前に追加した
configSettings
の後にデフォルトを追加します。// Set default values. mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config_defaults);
Web
デフォルト値はコードで直接設定できます。
// Set default Remote Config parameter values
remoteConfig.defaultConfig = {
model_name: 'gemini-2.0-flash',
system_instructions:
'You are a helpful assistant who knows everything there is to know about Firebase!',
prompt: 'I am a developer who wants to know more about Firebase!',
vertex_location: 'us-central1',
};
Dart
デフォルト値はコードで直接設定できます。
remoteConfig.setDefaults(const {
"model_name": "gemini-2.0-flash",
"system_instructions": "You are a helpful assistant who knows everything there is to know about Firebase!",
"prompt": "I am a developer who wants to know more about Firebase!",
"vertex_location": "us-central1"
});
Unity
デフォルト値はコードで直接設定できます。
await remoteConfig.SetDefaultsAsync(
new System.Collections.Generic.Dictionary<string, object>() {
{ "model_name", "gemini-2.0-flash" },
{ "system_instructions", "You are a helpful assistant who knows everything there is to know about Firebase!" },
{ "prompt", "I am a developer who wants to know more about Firebase!" },
{ "vertex_location", "us-central1" }
}
);
ステップ 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';
デフォルトの Remote Config 値を構成するために追加したコードの後で、構成をフェッチして有効にし、
modelName
、systemInstructions
、prompt
、vertexLocation
の各定数に値を割り当てます。// 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(); const systemInstructions = getValue(remoteConfig, 'system_instructions').asString(); const prompt = getValue(remoteConfig, 'prompt').asString(); const vertexLocation = getValue(remoteConfig, 'vertex_location').asString();
Dart
// Fetch and activate Remote Config.
remoteConfig.fetchAndActivate();
// Assign Remote Config values.
String? _modelName = remoteConfig.getString("model_name");
String? _systemInstructions = remoteConfig.getString("system_instructions");
String? _prompt = remoteConfig.getString("prompt");
String? _vertexLocation = remoteConfig.getString("vertex_location");
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
// Initialize the Gemini Developer API backend service
// The Gemini Developer API doesn't support setting the location of a model
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Create a `GenerativeModel` and add system instructions into its config
// Both the model name and the system instructions will be sourced from Remote Config
let modelName = remoteConfig.configValue(forKey: "model_name").stringValue
let systemInstructions = remoteConfig.configValue(forKey: "system_instructions").stringValue
let model = ai.generativeModel(
modelName: modelName,
systemInstruction: ModelContent(role: "system", parts: systemInstructions)
)
// Provide a prompt that contains text
// The text in the prompt will be sourced from Remote Config
let userPrompt = remoteConfig.configValue(forKey: "prompt").stringValue
// To generate text output, call `generateContent` with the text input
let response = try await model.generateContent(userPrompt)
if let text = response.text {
print(text)
}
Kotlin
// Initialize the Gemini Developer API backend service
// The Gemini Developer API doesn't support setting the location of a model
val ai = Firebase.ai(backend = GenerativeBackend.googleAI())
// Create a `GenerativeModel` and add system instructions into its config
// Both the model name and the system instructions will be sourced from Remote Config
val model = ai.generativeModel(
modelName = remoteConfig.getString("model_name"),
systemInstruction = content { text(remoteConfig.getString("system_instructions")) }
)
// To generate text output, call `generateContent` with the text input
// The text in the prompt will be sourced from Remote Config
val response = model.generateContent(remoteConfig.getString("prompt"))
print(response.text)
Java
// Initialize the Gemini Developer API backend service
// The Gemini Developer API doesn't support setting the location of a model
FirebaseAI ai = FirebaseAI.getInstance(GenerativeBackend.googleAI());
// Create a `GenerativeModel` and add system instructions into its config
// Both the model name and the system instructions will be sourced from Remote Config
GenerativeModel gm = ai.generativeModel(
/* modelName */ remoteConfig.getString("model_name"),
/* generationConfig (optional) */ null,
/* safetySettings (optional) */ null,
/* tools (optional) */ null,
/* toolsConfig (optional) */ null,
/* systemInstruction (optional) */ new Content.Builder().addText(
remoteConfig.getString("system_instructions")).build(),
/* requestOptions (optional) */ new RequestOptions()
);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);
// Provide a prompt that contains text
// The text in the prompt will be sourced from Remote Config
Content userPrompt = new Content.Builder()
.addText(remoteConfig.getString("prompt"))
.build();
// To generate text output, call `generateContent` with the text input
ListenableFuture<GenerateContentResponse> response = model.generateContent(userPrompt);
Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
String resultText = result.getText();
System.out.println(resultText);
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
Web
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service
// The Gemini Developer API doesn't support setting the location of a model
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `GenerativeModel` and add system instructions into its config
// Both the model name and the system instructions will be sourced from Remote Config
const model = getGenerativeModel(ai, {
model: modelName,
systemInstruction: systemInstruction
});
// Wrap in an async function so you can use await
async function run() {
// Provide a prompt that contains text
// The text in the prompt will be sourced from Remote Config
const userPrompt = prompt;
// To generate text output, call `generateContent` with the text input
const result = await model.generateContent(userPrompt);
const response = result.response;
const text = response.text();
console.log(text);
}
Dart
// Initialize the Gemini Developer API backend service
// The Gemini Developer API doesn't support setting the location of a model
final ai = await FirebaseAI.googleAI();
// Create a `GenerativeModel` and add system instructions into its config
// Both the model name and the system instructions will be sourced from Remote Config
final model =
ai.generativeModel(
model: _modelName,
systemInstruction: Content.system(_systemInstructions),
);
// Provide a prompt that contains text
// The text in the prompt will be sourced from Remote Config
final _userPrompt = [Content.text(_prompt)];
// To generate text output, call `generateContent` with the text input
final response = await model.generateContent(_userPrompt);
print(response.text);
Unity
// Initialize the Gemini Developer API backend service
// The Gemini Developer API doesn't support setting the location of a model
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Create a `GenerativeModel` and add system instructions into its config
// Both the model name and the system instructions will be sourced from Remote Config
var modelName = remoteConfig.GetValue("model_name").StringValue;
var systemInstructions = remoteConfig.GetValue("system_instructions").StringValue;
var model = ai.GetGenerativeModel(
modelName: modelName,
systemInstruction: ModelContent.Text(systemInstructions)
);
// Provide a prompt that contains text
// The text in the prompt will be sourced from Remote Config
var userPrompt = remoteConfig.GetValue("prompt").StringValue;
// To generate text output, call `GenerateContentAsync` with the text input
var response = await model.GenerateContentAsync(userPrompt);
UnityEngine.Debug.Log(response.Text ?? "No text in response.");
ステップ 7: アプリを実行する
アプリをビルドして実行し、動作することを確認します。Firebase コンソールの Remote Config ページで構成を変更し、変更をパブリッシュして結果を確認します。
次のステップ
詳細については、Remote Config についてをご覧ください。
クライアント コードに Google Analytics を追加してターゲティングを有効にする。
モバイルアプリとゲームの場合:
Remote Config と A/B Testing を使用して、さまざまなモデル設定をテストする。
Remote Config ロールアウトを使用して、モデル パラメータの変更を段階的にリリースする(iOS 以降と Android のみ)。
Remote Config パーソナライズを使用して、機械学習で個々のユーザーに最適な設定を決定する(iOS+、Android、Unity のみ)。