सर्वर प्रॉम्प्ट टेंप्लेट का इस्तेमाल करने पर, अपने ऐप्लिकेशन का नया वर्शन रिलीज़ किए बिना, दिए गए टेंप्लेट में वैल्यू अपडेट की जा सकती हैं. हालांकि, टेंप्लेट में किए गए किसी भी बदलाव का इस्तेमाल, आपके ऐप्लिकेशन से किए गए अनुरोधों में तुरंत किया जाएगा. इसलिए, आपको ऐसे बदलाव करने से बचना चाहिए जिनसे आपका ऐप्लिकेशन काम करना बंद कर सकता है या उसके व्यवहार में अनचाहे बदलाव हो सकते हैं.
इसलिए, अगर आपको बड़े बदलाव करने हैं या धीरे-धीरे बदलाव लागू करने हैं, तो प्रोडक्शन कोड में इस्तेमाल किए गए टेंप्लेट में बदलाव न करें.
इसके बजाय, हमारा सुझाव है कि मॉडल को किए गए अनुरोध में इस्तेमाल किए गए टेंप्लेट आईडी की वैल्यू को कंट्रोल करने के लिए, Firebase Remote Config का इस्तेमाल करें.
Firebase Remote Config की मदद से, अपने ऐप्लिकेशन में पैरामीटर की वैल्यू (जैसे, टेंप्लेट आईडी) को डाइनैमिक तरीके से और Firebase कंसोल से रिमोट तरीके से अपडेट किया जा सकता है. इसके लिए, आपको अपने ऐप्लिकेशन का नया वर्शन रिलीज़ करने की ज़रूरत नहीं पड़ती. इसमें बदलाव लागू करने के साथ-साथ, A/B टेस्टिंग के लिए भी बेहतर सुविधाएं और इंटिग्रेशन मौजूद हैं.
इस गाइड में, अपने ऐप्लिकेशन में Remote Config लागू करने का तरीका बताया गया है. खास तौर पर, अपने ऐप्लिकेशन में इस्तेमाल किए गए टेंप्लेट आईडी को कंट्रोल करने के लिए.
पहला चरण: Firebase कंसोल में पैरामीटर की वैल्यू सेट करना
क्लाइंट टेंप्लेट बनाएं. साथ ही, ऐप्लिकेशन में फ़ेच करने और इस्तेमाल करने के लिए, Remote Config template_id
पैरामीटर और उसकी वैल्यू कॉन्फ़िगर करें.
Firebase कंसोल में, DevOps और उपयोगकर्ता जुड़ाव > रिमोट कॉन्फ़िगरेशन पर जाएं.
पेज पर सबसे ऊपर मौजूद, क्लाइंट/सर्वर सिलेक्टर से, क्लाइंट को चुनें.
कॉन्फ़िगरेशन बनाएं पर क्लिक करके, क्लाइंट टेंप्लेट बनाना शुरू करें. अगर आपने पहले क्लाइंट टेंप्लेट का इस्तेमाल किया है, तो पैरामीटर जोड़ें पर क्लिक करें.
template_idपैरामीटर तय करें:पैरामीटर का नाम ब्यौरा टाइप डिफ़ॉल्ट वैल्यू template_idटेंप्लेट आईडी. स्ट्रिंग my-first-template-v1-0-0यह पैरामीटर जोड़ने के बाद, बदलाव पब्लिश करें पर क्लिक करें. अगर यह कोई नया Remote Config टेंप्लेट नहीं है, तो बदलावों की समीक्षा करें और फिर से बदलाव पब्लिश करें पर क्लिक करें.
दूसरा चरण: अपने ऐप्लिकेशन में 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.13.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.13.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वैरिएबल जोड़ें, ताकि इसका इस्तेमाल बाद में किया जा सके: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 });
तीसरा चरण: ऐप्लिकेशन में पैरामीटर की वैल्यू सेट करना
आपको ऐप्लिकेशन में पैरामीटर की डिफ़ॉल्ट वैल्यू Remote Config ऑब्जेक्ट में सेट करनी चाहिए. इससे यह पक्का होता है कि आपका ऐप्लिकेशन उम्मीद के मुताबिक काम करे. भले ही, वह Remote Config सेवा से वैल्यू फ़ेच न कर पाए.
Swift
Firebase कंसोल में, DevOps और उपयोगकर्ता जुड़ाव > रिमोट कॉन्फ़िगरेशन > पैरामीटर पेज पर जाएं.
मेन्यू खोलें और डिफ़ॉल्ट वैल्यू डाउनलोड करें को चुनें.प्रॉम्प्ट मिलने पर, iOS के लिए .plist को चालू करें. इसके बाद, फ़ाइल डाउनलोड करें पर क्लिक करें.
फ़ाइल को अपने ऐप्लिकेशन की डायरेक्ट्री में सेव करें.
Xcode में, अपने ऐप्लिकेशन पर राइट क्लिक करें और फ़ाइलें जोड़ें को चुनें
remote_config_defaults.plist को चुनें. इसके बाद, जोड़ें पर क्लिक करें.
डिफ़ॉल्ट फ़ाइल को रेफ़र करने के लिए, अपने ऐप्लिकेशन का कोड अपडेट करें:
// Set default values for Remote Config parameters. remoteConfig.setDefaults(fromPlist: "remote_config_defaults")
Kotlin
Firebase कंसोल में, DevOps और उपयोगकर्ता जुड़ाव > रिमोट कॉन्फ़िगरेशन > पैरामीटर पेज पर जाएं.
मेन्यू खोलें और डिफ़ॉल्ट वैल्यू डाउनलोड करें को चुनें.प्रॉम्प्ट मिलने पर, Android के लिए .xml को चालू करें. इसके बाद, फ़ाइल डाउनलोड करें पर क्लिक करें.
फ़ाइल को अपने ऐप्लिकेशन की एक्सएमएल रिसॉर्स डायरेक्ट्री में सेव करें.
पहले जोड़े गए
configSettingsके बाद, डिफ़ॉल्ट वैल्यू जोड़ने के लिए, अपनी मुख्य गतिविधि वाली फ़ाइल अपडेट करें:// Set default values for Remote Config parameters. remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
Java
Firebase कंसोल में, DevOps और उपयोगकर्ता जुड़ाव > रिमोट कॉन्फ़िगरेशन > पैरामीटर पेज पर जाएं.
मेन्यू खोलें और डिफ़ॉल्ट वैल्यू डाउनलोड करें को चुनें.प्रॉम्प्ट मिलने पर, Android के लिए .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 = {
template_id: 'my-first-template-v1-0-0',
};
Dart
अपने कोड में सीधे तौर पर, मॉडल के नाम के लिए डिफ़ॉल्ट वैल्यू सेट की जा सकती है:
// Set default values for Remote Config parameters.
remoteConfig.setDefaults(const {
"template_id": "my-first-template-v1-0-0"
});
Unity
अपने कोड में सीधे तौर पर, मॉडल के नाम के लिए डिफ़ॉल्ट वैल्यू सेट की जा सकती है:
// Set default values for Remote Config parameters.
await remoteConfig.SetDefaultsAsync(
new System.Collections.Generic.Dictionary<string, object>() {
{ "template_id", "my-first-template-v1-0-0" }
}
);
चौथा चरण: वैल्यू फ़ेच करना और उसे चालू करना
मॉडल के नाम के लिए डिफ़ॉल्ट वैल्यू सेट करने के बाद, वैल्यू फ़ेच करने और उसे चालू करने के लिए, यह कोड जोड़ें.
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';वह कोड ढूंढें जहां मॉडल के नाम के लिए डिफ़ॉल्ट वैल्यू तय की गई हो. उस कोड ब्लॉक के ठीक बाद, कॉन्फ़िगरेशन फ़ेच करने और उसे चालू करने के लिए यह कोड जोड़ें. साथ ही, फ़ेच की गई वैल्यू को
templateIDकॉन्स्टैंट असाइन करें.// 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 templateID = getValue(remoteConfig, 'template_id').asString();
Dart
// Fetch and activate Remote Config.
remoteConfig.fetchAndActivate();
// Assign Remote Config values.
String? _templateID = remoteConfig.getString("template_id");
Unity
// Fetch and activate Remote Config values.
await remoteConfig.FetchAndActivateAsync();
पांचवां चरण: रीयल-टाइम 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
// Add a real-time Remote Config listener
onConfigUpdate(remoteConfig, {
next: (configUpdate) => {
console.log("Updated keys:", configUpdate.getUpdatedKeys());
if (configUpdate.getUpdatedKeys().has("welcome_message")) {
activate(remoteConfig).then(() => {
showWelcomeMessage();
});
}
},
error: (error) => {
console.log("Config update error:", error);
},
complete: () => {
console.log("Listening stopped.");
}
});
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();
};
छठा चरण: Gemini API अनुरोधों को इस्तेमाल करने के लिए, Remote Config वैल्यू अपडेट करना
|
इस पेज पर, Gemini API प्रोवाइडर के हिसाब से कॉन्टेंट और कोड देखने के लिए, उस पर क्लिक करें. |
अब Remote Config पूरी तरह से कॉन्फ़िगर हो गया है. इसलिए, अपने कोड को अपडेट करें, ताकि हार्ड-कोड की गई वैल्यू की जगह Remote Config से ली गई वैल्यू का इस्तेमाल किया जा सके.
Swift
import FirebaseAI
let templateID = remoteConfig.configValue(forKey: "template_id").stringValue
let model = FirebaseAI.firebaseAI(backend: .googleAI()).templateGenerativeModel()
let customerName = "Jane"
// When making the `generateContent` call, source the template ID value from Remote Config
let response = try await model.generateContent(
templateID: templateID,
// Provide the values for any input variables required by your template.
inputs: [
"customerName": customerName
]
)
// ...
Kotlin
// ...
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).templateGenerativeModel()
val customerName = "Jane"
// When making the `generateContent` call, source the template ID value from Remote Config
val response = model.generateContent(
remoteConfig.getString("template_id"),
// Provide the values for any input variables required by your template.
mapOf(
"customerName" to customerName
)
)
val text = response.text
println(text)
Java
// ...
TemplateGenerativeModel ai = FirebaseAI.getInstance()
.templateGenerativeModel(null /* Request Options */);
TemplateGenerativeModelFutures model = TemplateGenerativeModelFutures.from(ai);
String customerName = "Jane";
// When making the `generateContent` call, source the template ID value from Remote Config
Future<GenerateContentResponse> response = model.generateContent(
remoteConfig.getString("template_id"),
// Provide the values for any input variables required by your template.
mapOf("customerName", customerName)
);
addCallback(response,
new FutureCallback<GenerateContentResponse>() {
public void onSuccess(GenerateContentResponse result) {
System.out.println(result.getText());
}
public void onFailure(Throwable t) {
reportError(t);
}
}
executor);
// ...
Web
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
const model = getTemplateGenerativeModel(ai);
const templateID = getValue(remoteConfig, 'template_id').asString();
const customerName = 'Jane';
// When making the `generateContent` call, source the template ID value from Remote Config
const result = await model.generateContent(
templateID,
// Provide the values for any input variables required by your template
{
customerName: customerName,
}
);
// ...
Dart
// ...
final model = FirebaseAI.googleAI().templateGenerativeModel();
final templateID = remoteConfig.getString("template_id");
final customerName = 'Jane';
// When making the `generateContent` call, source the template ID value from Remote Config
var response = await model.generateContent(
templateID,
// Provide the values for any input variables required by your template
inputs: {
'customerName': customerName,
},
);
// ...
Unity
// ...
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
var templateID = remoteConfig.GetValue("template_id").StringValue;
var model = ai.GetTemplateGenerativeModel();
var customerName = "Jane";
try
{
// When making the `generateContent` call, source the template ID value from Remote Config
var response = await model.GenerateContentAsync(
templateID,
// Provide the values for any input variables required by your template
new Dictionary<string, object>
{
{ "customerName", customerName },
}
);
Debug.Log($"Response Text: {response.Text}");
}
catch (Exception e)
{
Debug.LogError($"An error occurred: {e.Message}");
}
// ...
सातवां चरण: ऐप्लिकेशन चलाना
ऐप्लिकेशन बनाएं और चलाएं. साथ ही, पुष्टि करें कि यह काम कर रहा है. Firebase कंसोल में, Remote Config पेज से अपने कॉन्फ़िगरेशन में बदलाव करें. इसके बाद, बदलाव पब्लिश करें और नतीजों की पुष्टि करें.Firebase
अगले चरण
के लिए, इस्तेमाल के अन्य उदाहरण लागू करने के बारे में ज़्यादा जानें Remote Config और Firebase AI Logic.
मोबाइल ऐप्लिकेशन और गेम के लिए:
Remote Config और A/B Testing की मदद से, टेंप्लेट में किए गए बदलावों को टेस्ट करें.
Remote Config रोलआउट (सिर्फ़ iOS+ और Android) का इस्तेमाल करके, धीरे-धीरे बदलाव रिलीज़ करें.
मशीन लर्निंग की मदद से हर उपयोगकर्ता के लिए सबसे अच्छी सेटिंग तय करने के लिए Remote Config निजीकरण का इस्तेमाल करें (सिर्फ़ iOS+, Android, और Unity).