在 Android 上使用 Vertex AI in Firebase,实现可用于生产环境的生成式 AI
作者 / 高级开发者关系工程师 Thomas Ezan
实施 App Check 以防止 API 滥用
在使用 Vertex AI in Firebase API 时,实施强有力的安全措施以防止未经授权的访问和滥用至关重要。
Firebase App Check 有助于保护后端资源 (如 Vertex AI in Firebase 和 Cloud Functions for Firebase,甚至您自定义的后端) 免受滥用。App Check 通过验证传入流量是否来自运行在真实且未被篡改的 Android 设备上的真实应用来实现这一目标。
△ Firebase App Check 确保只有合法用户才能访问您的后端资源
dependencies {// BoM for the Firebase platformimplementation(platform("com.google.firebase:firebase-bom:33.7.0"))// Dependency for App Checkimplementation("com.google.firebase:firebase-appcheck-playintegrity")}
Firebase.initialize(context)Firebase.appCheck.installAppCheckProviderFactory(PlayIntegrityAppCheckProviderFactory.getInstance(),)
使用 Remote Config 实现服务器端配置管理
// Initialize the remote configuration by defining the refresh timeval remoteConfig: FirebaseRemoteConfig = Firebase.remoteConfigval configSettings = remoteConfigSettings {minimumFetchIntervalInSeconds = 3600}remoteConfig.setConfigSettingsAsync(configSettings)// Set default values defined in your app resourcesremoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)// Load the model nameval modelName = remoteConfig.getString("model_name")
收集用户反馈以评估影响
Row {Button (onClick = {firebaseAnalytics.logEvent("model_response_feedback") {param("feedback", "thumb_up")}}) {Icon(Icons.Default.ThumbUp, contentDescription = "Thumb up")},Button (onClick = {firebaseAnalytics.logEvent("model_response_feedback") {param("feedback", "thumb_down")}}) {Icon(Icons.Default.ThumbDown, contentDescription = "Thumb down")}}
用户隐私和负责任的 AI
谷歌开发者特别招募活动进行中
诚邀热爱技术的你加入
通过多种形式 (文章/视频/coding 等) 创作与 Google 技术相关的讲解分享、实践案例或活动感受等内容,以及分享您应用 AI 技术的故事经历与成果。我们将为您提供平台和资源,助力您在分享中提升技能。更有惊喜权益等您领取,快来报名参与吧!