要求 Llama 預測

您可以使用 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 模型發出串流和非串流呼叫,請參閱「呼叫開放模型的 MaaS API」。

事前準備

如要在 Gemini Enterprise Agent Platform 使用 Llama 模型,請務必完成下列步驟。您必須啟用 Agent Platform API (aiplatform.googleapis.com) 和 Cloud Commerce Consumer Procurement API (cloudcommerceconsumerprocurement.googleapis.com),才能在 Gemini Enterprise Agent Platform 使用 Llama 模型。如果您已有專案啟用這些 API,可以使用該專案,不必建立新專案。

  1. In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  2. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  3. Verify that billing is enabled for your Cloud de Confiance project.

  4. Enable the Gemini Enterprise Agent Platform and Cloud Commerce Consumer Procurement APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the APIs

  5. 前往下列其中一個 Model Garden 模型資訊卡,然後按一下「Enable」(啟用):

必要的角色

如要取得啟用及使用 Llama 模型所需的權限,請要求管理員在專案中授予您下列 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

如要進一步瞭解如何授予權限及設定合作夥伴模型的組織政策,請參閱「授予使用者合作夥伴模型的存取權」。

對 Llama 模型發出串流呼叫

下列範例會對 Llama 模型發出串流呼叫。

REST

設定環境後,您可以使用 REST 測試文字提示詞。下列範例會將要求傳送至發布者模型端點。

使用任何要求資料之前,請先修改下列項目的值:

  • LOCATION:支援 Llama 模型的區域,例如 us-east5。
  • MODEL:要使用的模型名稱,例如 llama-4-maverick-17b-128e-instruct-maas。
  • ROLE:與訊息相關聯的角色。您可以指定 user 或 assistant。第一則訊息必須使用 user 角色。模型會交替執行 user 和 assistant 回合。如果最後一則訊息使用 assistant 角色,回覆內容會緊接在該訊息的內容之後。您可以使用這項功能,限制模型的部分回覆。
  • CONTENT:user 或 assistant 訊息的內容,例如文字。
  • MAX_OUTPUT_TOKENS:回覆內可以生成的詞元數量上限。一個詞元約為四個字元。100 個符記約等於 60 到 80 個字。

    如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。

  • STREAM:布林值,指定是否要串流回覆。串流回覆,減少使用者感受到的延遲。設為 true 即可串流回覆,設為 false 則會一次傳回所有回覆。

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
}

如要傳送要求,請選擇以下其中一個選項:

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 模型的區域,例如 us-east5。
  • MODEL:要使用的模型名稱,例如 llama-4-maverick-17b-128e-instruct-maas。
  • ROLE:與訊息相關聯的角色。您可以指定 user 或 assistant。第一則訊息必須使用 user 角色。模型會交替執行 user 和 assistant 回合。如果最後一則訊息使用 assistant 角色,回覆內容會緊接在該訊息的內容之後。您可以使用這項功能,限制模型的部分回覆。
  • CONTENT:user 或 assistant 訊息的內容,例如文字。
  • MAX_OUTPUT_TOKENS:回覆內可以生成的詞元數量上限。一個詞元約為四個字元。100 個符記約等於 60 到 80 個字。

    如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。

  • STREAM:布林值,指定是否要串流回覆。串流回覆,減少使用者感受到的延遲。設為 true 即可串流回覆,設為 false 則會一次傳回所有回覆。

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
}

如要傳送要求,請選擇以下其中一個選項:

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 回覆。

使用 Agent Studio

如果是 Llama 模型,您可以使用 Agent Studio,在 Cloud de Confiance 控制台快速設計及測試生成式 AI 模型的原型。舉例來說,您可以使用 Agent 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

如要提高 Agent Platform 的配額,請使用 Cloud de Confiance 控制台提出要求。如要進一步瞭解配額,請參閱「Cloud Quotas 總覽」。