|
点击您的 Gemini API 提供商,以查看此页面上特定于提供商的内容和代码。 |
Google 的生成式 AI 模型可在特定区域使用。
在代码中初始化 Vertex AI Gemini API 后端服务时,您可以选择性地指定要在请求中访问的模型的位置。 请参阅本页稍后提供的可用位置列表。
以下是有关位置信息的一些关键事实和最佳实践:
容量限制是按模型、按区域、按分钟设置的。
如果您未指定位置,则默认为
us-central1。为避免意外达到容量限制,我们建议您在请求中将位置设为
global。如果将位置信息设置为
global不适用于您的使用情形,请考虑明确说明您访问模型的位置。例如,您可以使用 Firebase Remote Config 根据最终用户的位置设置位置。
了解 global 位置信息
如需访问几乎所有 Gemini 模型,Vertex AI Gemini API 支持 global 位置,这意味着您的请求将由全球池中任何可用的模型处理。将请求的位置设置为 global 有助于避免达到模型容量上限,并减少资源耗尽 (429) 错误。
代码示例
请注意,这些示例展示了如何访问 Gemini 模型,但您也可以在访问 Imagen 模型时指定位置。
将 LOCATION 替换为本页稍后列出的可用位置中的位置代码(例如 europe-west4)。
Swift
// ...
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
let ai = FirebaseAI.firebaseAI(backend: .vertexAI(location: "LOCATION"))
// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(modelName: "MODEL_NAME")
// ...
Kotlin
// ...
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
val model = Firebase.ai(backend = GenerativeBackend.vertexAI(location = "LOCATION"))
.generativeModel("MODEL_NAME")
// ...
Java
// ...
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.vertexAI("LOCATION"))
.generativeModel("MODEL_NAME");
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// ...
Web
// ...
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
const ai = getAI(firebaseApp, { backend: new VertexAIBackend('LOCATION') });
// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(ai, { model: 'MODEL_NAME' });
// ...
Dart
// ...
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
final ai = await FirebaseAI.vertexAI(location: 'LOCATION');
// Create a `GenerativeModel` instance with a model that supports your use case
final model = ai.generativeModel(model: 'MODEL_NAME');
// ...
Unity
// ...
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.VertexAI(location: "LOCATION"));
// Create a `GenerativeModel` instance with a model that supports your use case
var model = ai.GetGenerativeModel(modelName: "MODEL_NAME");
// ...
请注意,如果您指定了模型不可用的位置,系统会返回 404 错误,指出模型 was not found or your project does not have access to it。
可用位置
Google Cloud 使用区域。 Google Cloud 仅在您为 Vertex AI 上的生成式 AI 的所有正式版功能指定的区域中存储客户数据。
Vertex AI 上的生成式 AI 可在以下区域使用。 部分型号和/或特定版本可能无法在所有地区使用(如需详细了解地区可用性,请参阅 Google Cloud 文档)。
所有 Gemini 模型(Gemini Live 模型除外)也可在 global 位置中使用。对于 Imagen 模型,global 位置不受支持。
美国
- 俄亥俄州哥伦布 (
us-east5) - 德克萨斯州达拉斯 (
us-south1) - 爱荷华 (
us-central1) - 内华达州,拉斯维加斯 (
us-west4) - 南卡罗来纳州蒙克斯科纳 (
us-east1) - 北弗吉尼亚 (
us-east4) - 俄勒冈 (
us-west1)
加拿大
- 蒙特利尔 (
northamerica-northeast1)
南美洲
- 巴西圣保罗 (
southamerica-east1)
欧洲
- 比利时 (
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)