|
按一下您的Gemini API供應商,即可在這個頁面上查看供應商專屬內容和程式碼。 |
Google 的生成式 AI 模型僅適用於特定區域。您可以根據法規遵循、延遲時間、可用性和耐用性方面的需求,選擇模型存取位置。
使用 Firebase AI Logic 時,每個使用 Agent Platform Gemini API (formerly Vertex AI) 的要求都可以選擇包含存取模型的位置。Firebase AI Logic 採用預設位置資訊設定。
- 使用新的「Agent Platform」初始化語法時:
global - 使用舊版「Vertex AI」初始化語法時:
us-central1
關於global位置
幾乎所有 Gemini 模型,Agent Platform Gemini API (formerly Vertex AI) 都提供 global 位置,這表示您的要求會由全球集區中任何可用的模型處理。
使用 global 位置傳送要求,有助於避免達到模型容量上限,並減少「服務超載」(503) 錯誤。此外,視模型而定,您可能必須使用 global 位置,因為這是該模型唯一可用的位置 (例如預先發布版 Gemini 模型)。
何時需要明確設定位置?
Firebase AI Logic 具有位置的自動預設值 (例如使用「Agent Platform」初始化語法時的 global)。不過,如果您需要或想要使用其他位置,則必須在程式碼中初始化 Agent Platform Gemini API (formerly Vertex AI) 後端服務時,明確指定位置。
視模型而定,您可能必須明確設定位置。
如果要求嘗試存取模型,但模型不支援該位置,您會收到 404 錯誤,指出模型was not found or your project does not have access to it。
Gemini 預先發布版和實驗模型:僅適用於
global位置。Gemini stable 模型:可在
global位置使用,通常位於us和eu多區域,以及許多特定區域。請注意,
global不支援 Gemini Live API 2.5 模型。
請參閱本頁後續章節的所有可用位置清單。
一般事實和最佳做法
以下是關於位置的重要資訊和最佳做法:
用量限制是依模型、區域和分鐘計算。
為避免意外達到容量上限,建議您使用
global位置 (如果模型在global位置可用)。建議使用 Firebase Remote Config 控制存取模型的位置。這樣一來,您就不必發布新版應用程式,也能變更位置。
如果
global位置不適用於您的用途,請考慮明確指定模型存取位置 (如果模型可在global以外的位置使用)。舉例來說,您可以使用 Firebase Remote Config,根據使用者的位置設定位置。
程式碼範例
Firebase AI Logic 具有自動預設位置 (例如使用「Agent Platform」初始化語法時的 global)。不過,如果您需要或想要使用其他位置,則必須在程式碼中初始化 Agent Platform Gemini API (formerly Vertex AI) 後端服務時,明確指定位置。
將 LOCATION 替換為位置代碼 (例如 global 或 us-central1),請參閱本頁稍後的可用位置清單。
Agent Platform 語法
Swift
agentPlatform 語法適用於 SDK 12.17.0 以上版本。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `agentPlatform` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
let ai = FirebaseAI.firebaseAI(backend: .agentPlatform(location: "LOCATION"))
// ...
Kotlin
agentPlatform 語法適用於 SDK 17.15.0 以上版本,以及 Firebase Android BoM 34.17.0 以上版本。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `agentPlatform` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
val ai = Firebase.ai(backend = GenerativeBackend.agentPlatform(location = "LOCATION"))
// ...
Java
agentPlatform 語法適用於 SDK 17.15.0 以上版本,以及 Firebase Android BoM 34.17.0 以上版本。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `agentPlatform` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.agentPlatform("LOCATION"));
// ...
Web
AgentPlatformBackend 語法適用於 SDK 12.17.0 以上版本。
// ...
// Initialize FirebaseApp
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `AgentPlatformBackend` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
const ai = getAI(firebaseApp, { backend: new AgentPlatformBackend('LOCATION') });
// ...
Dart
agentPlatform 語法適用於外掛程式 3.15.0 以上版本,以及 Firebase Flutter BoM 4.18.0 以上版本。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `agentPlatform` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
final ai = await FirebaseAI.agentPlatform(location: 'LOCATION');
// ...
Unity
SDK 13.15.0 以上版本支援 AgentPlatform 語法。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly Vertex AI).
// For the `AgentPlatform` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.AgentPlatform(location: "LOCATION"));
// ...
Vertex AI 語法
Swift
vertexAI 語法已在 SDK 13.0.0 版中移除。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexAI` syntax, the default location is `us-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
let ai = FirebaseAI.firebaseAI(backend: .vertexAI(location: "LOCATION"))
// ...
Kotlin
vertexAI 語法已從 SDK 18.0.0 版和 Firebase Android BoM 35.0.0 版中移除。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexAI` syntax, the default location is `us-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
val ai = Firebase.ai(backend = GenerativeBackend.vertexAI(location = "LOCATION"))
// ...
Java
vertexAI 語法已從 SDK 18.0.0 版和 Firebase Android BoM 35.0.0 版中移除。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexAI` syntax, the default location is `us-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.vertexAI("LOCATION"));
// ...
Web
VertexAIBackend 語法已在 SDK 13.0.0 版中移除。
// ...
// Initialize FirebaseApp
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `VertexAIBackend` syntax, the default location is `us-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
const ai = getAI(firebaseApp, { backend: new VertexAIBackend('LOCATION') });
// ...
Dart
vertexAI 語法已從外掛程式 5.0.0 版和 Firebase Flutter BoM 5.0.0 版中移除。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexAI` syntax, the default location is `us-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
final ai = await FirebaseAI.vertexAI(location: 'LOCATION');
// ...
Unity
SDK 14.0.0 版已移除 VertexAI 語法。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `VertexAI` syntax, the default location is `us-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.VertexAI(location: "LOCATION"));
// ...
請注意,如果指定的位置不支援該模型,系統會傳回 404 錯誤,指出模型 was not found or your project does not have access to it。
服務地區
Google Cloud 使用區域。Google Cloud 只會將客戶資料儲存在您指定的區域,適用於 Agent Platform 的 Generative AI 所有 正式發布功能。
Agent Platform 的生成式 AI 適用於下列區域。部分模型和/或特定版本可能不適用於所有位置 (如要瞭解詳細的位置適用情形,請參閱 Google Cloud 說明文件)。
注意事項:
Firebase AI Logic 預設為下列位置:
- 使用新的「Agent Platform」初始化語法時:
global - 使用舊版「Vertex AI」初始化語法時:
us-central1
- 使用新的「Agent Platform」初始化語法時:
Gemini 預先發布版和實驗模型:僅適用於
global位置。Gemini stable 模型:可在
global位置使用,通常位於us和eu多區域,以及許多特定區域。請注意,
global不支援 Gemini Live API 2.5 模型。
如要進一步瞭解各模型的可用位置,請參閱 Google Cloud 說明文件。
全球
global
美國
- 美國多區域 (
us) - 俄亥俄州哥倫布 (
us-east5) - 德州達拉斯 (
us-south1) - 愛荷華州 (
us-central1) - 內華達州拉斯維加斯 (
us-west4) - 美國南卡羅來納州蒙克斯科納 (
us-east1) - 北維吉尼亞州 (
us-east4) - 奧勒岡州 (
us-west1)
加拿大
- 蒙特婁 (
northamerica-northeast1)
南美洲
- 巴西聖保羅 (
southamerica-east1)
歐洲
- 歐盟多區域 (
eu) - 比利時 (
europe-west1) - 芬蘭 (
europe-north1) - 德國法蘭克福 (
europe-west3) - 英國倫敦 (
europe-west2) - 西班牙馬德里 (
europe-southwest1) - 義大利米蘭 (
europe-west8) - 荷蘭 (
europe-west4) - 法國巴黎 (
europe-west9) - 波蘭華沙 (
europe-central2) - 瑞士蘇黎世 (
europe-west6)
亞太地區
- 臺灣彰化縣 (
asia-east1) - 中國香港 (
asia-east2) - 印度孟買 (
asia-south1) - 韓國首爾 (
asia-northeast3) - 新加坡 (
asia-southeast1) - 澳洲雪梨 (
australia-southeast1) - 日本東京 (
asia-northeast1)
中東
- 沙烏地阿拉伯達曼 (
me-central2) - 卡達杜哈 (
me-central1) - 以色列特拉維夫 (
me-west1)