您可以使用 curl 指令,透過下列模型名稱將要求傳送至 Gemini Enterprise Agent Platform 端點:
- 如要使用 Llama 4 Maverick 17B-128E,請使用
llama-4-maverick-17b-128e-instruct-maas - 如要使用 Llama 4 Scout 17B-16E,請使用
llama-4-scout-17b-16e-instruct-maas - 如要使用 Llama 3.3 70B,請使用
llama-3.3-70b-instruct-maas
如要瞭解如何對 Llama 模型發出串流和非串流呼叫,請參閱「呼叫開放模型的 MaaS API」。
事前準備
如要透過 Gemini Enterprise Agent Platform 使用 Llama 模型,請完成下列步驟。如要使用 Gemini Enterprise Agent Platform,必須啟用 Agent Platform API (aiplatform.googleapis.com)。如果您已啟用 Agent Platform API 的現有專案,可以使用該專案,不必建立新專案。
- 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Gemini Enterprise Agent Platform API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Gemini Enterprise Agent Platform API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.- 前往下列任一 Model Garden 模型資訊卡,然後按一下「啟用」:
對 Llama 模型發出串流呼叫
下列範例會對 Llama 模型發出串流呼叫。
REST
設定環境後,您可以使用 REST 測試文字提示。下列範例會將要求傳送至發布商模型端點。
使用任何要求資料之前,請先修改下列項目的值:
- LOCATION:支援 Llama 模型的區域。
- MODEL:要使用的模型名稱。
- ROLE:與訊息相關聯的角色。您可以指定
user或assistant。 第一則訊息必須使用user角色。模型會交替進行user和assistant回合。如果最終訊息使用assistant角色,回應內容會立即接續該訊息的內容。您可以使用這項功能限制模型回覆的部分內容。 - CONTENT:
user或assistant訊息的內容,例如文字。 - MAX_OUTPUT_TOKENS:
回覆內可以生成的權杖數量上限。一個符記約為四個字元。100 個符記約等於 60 到 80 個字。
如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。
- STREAM:布林值,用於指定是否要串流傳送回覆。串流傳送回覆內容,減少使用者對延遲的感受。設為
true可串流回應,設為false則可一次傳回回應。 - ENABLE_LLAMA_GUARD: 布林值,指定是否要在輸入和輸出內容中啟用 Llama Guard。根據預設,系統會啟用 Llama Guard,並在判斷回覆內容不安全時標示出來。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions
JSON 要求內文:
{
"model": "meta/MODEL",
"messages": [
{
"role": "ROLE",
"content": "CONTENT"
}
],
"max_tokens": MAX_OUTPUT_TOKENS,
"stream": true,
"extra_body": {
"google": {
"model_safety_settings": {
"enabled": ENABLE_LLAMA_GUARD,
"llama_guard_settings": {}
}
}
}
}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions"
PowerShell
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions" | Select-Object -Expand Content
您應該會收到類似如下的 JSON 回應。
對 Llama 模型發出一元呼叫
以下範例會對 Llama 模型進行一元呼叫。
REST
設定環境後,您可以使用 REST 測試文字提示。下列範例會將要求傳送至發布商模型端點。
使用任何要求資料之前,請先修改下列項目的值:
- LOCATION:支援 Llama 模型的區域。
- MODEL:要使用的模型名稱。
- ROLE:與訊息相關聯的角色。您可以指定
user或assistant。 第一則訊息必須使用user角色。模型會交替進行user和assistant回合。如果最終訊息使用assistant角色,回應內容會立即接續該訊息的內容。您可以使用這項功能限制模型回覆的部分內容。 - CONTENT:
user或assistant訊息的內容,例如文字。 - MAX_OUTPUT_TOKENS:
回覆內可以生成的權杖數量上限。一個符記約為四個字元。100 個符記約等於 60 到 80 個字。
如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。
- STREAM:布林值,用於指定是否要串流傳送回覆。串流傳送回覆內容,減少使用者對延遲的感受。設為
true可串流回應,設為false則可一次傳回回應。 - ENABLE_LLAMA_GUARD: 布林值,指定是否要在輸入和輸出內容中啟用 Llama Guard。根據預設,系統會啟用 Llama Guard,並在判斷回覆內容不安全時標示出來。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions
JSON 要求內文:
{
"model": "meta/MODEL",
"messages": [
{
"role": "ROLE",
"content": "CONTENT"
}
],
"max_tokens": MAX_OUTPUT_TOKENS,
"stream": false,
"extra_body": {
"google": {
"model_safety_settings": {
"enabled": ENABLE_LLAMA_GUARD,
"llama_guard_settings": {}
}
}
}
}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions"
PowerShell
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/endpoints/openapi/chat/completions" | Select-Object -Expand Content
您應該會收到類似如下的 JSON 回應。
已標記的回覆
根據預設,使用 Llama 3.3 和 Llama 3.1 模型進行的所有預測都會啟用 Llama Guard 3 8B。根據預設,使用 Llama 3.2 模型進行的所有預測都會啟用 Llama Guard 3 11B 視覺功能。Llama Guard 會檢查輸入和輸出內容,協助保護回覆內容。如果 Llama Guard 判斷回覆內容不安全,就會標記該回覆。
如要停用 Llama Guard,請修改模型安全設定。詳情請參閱串流或一元範例中的 model_safety_settings 欄位。
使用 Vertex AI Studio
如要使用 Llama 模型,您可以在 Google Cloud 控制台使用 Vertex AI Studio 快速設計生成式 AI 模型原型並進行測試。舉例來說,您可以使用 Vertex AI Studio 比較 Llama 模型回覆與其他支援的模型,例如 Google 的 Gemini。
Llama 模型支援的區域和配額
如果是 Llama 模型,則配額適用於模型可用的每個區域。配額以每分鐘查詢次數 (QPM) 為單位。
| 型號 | 區域 | 配額 | 脈絡長度 |
|---|---|---|---|
| Llama 4 Maverick 17B-128E | |||
us-east5 |
|
524,288 | |
| Llama 4 Scout 17B-16E | |||
us-east5 |
|
1,310,720 | |
| Llama 3.3 70B | |||
us-central1 |
|
128,000 |
如要增加 Gemini Enterprise Agent Platform 的生成式 AI 配額,可以透過 Google Cloud 控制台申請提高配額。如要進一步瞭解配額,請參閱「Cloud Quotas 總覽」。