Mistral AI 模型

Gemini Enterprise Agent Platform 上的 Mistral AI 模型提供全代管無伺服器模型,做為 API。如要在 Agent Platform 上使用 Mistral AI 模型,請直接向 Agent Platform API 端點傳送要求。由於 Mistral AI 模型使用代管 API,因此不必佈建或管理基礎架構。

您可以串流傳送回覆,縮短使用者感受到的延遲時間。串流回應會使用伺服器傳送事件 (SSE),逐步串流回應。

您只需為實際使用的 Mistral AI 模型付費 (即付即用)。如要瞭解即付即用方案的價格,請參閱 Gemini Enterprise Agent Platform 定價頁面的 Mistral AI 模型價格。

可用的 Mistral AI 模型

您可以在 Gemini Enterprise Agent Platform 中使用 Mistral AI 的下列模型。如要存取 Mistral AI 模型,請前往其 Model Garden 模型資訊卡。

Mistral Medium 3 這款多功能多模態模型專為進階推論、程式設計、長脈絡文件解讀、單一節點高處理量和代理工作流程而設計。
Mistral OCR (25.05) 光學字元辨識 API,可深入瞭解文件內容、擷取交錯的圖像、表格、圖表和 LaTeX 格式,適用於多模態 RAG 管道。
Mistral Small 3.1 (25.03) 多功能、低延遲的多模態模型,脈絡窗口為 128,000 個權杖,適合用於高效率的對話、程式設計和指令遵循。
Codestral 2 專為高精確度填空 (FIM) 完成、程式碼審查、重構和開發人員工具而建構的程式碼生成模型。

使用 Mistral AI 模型

您可以使用 curl 指令,透過下列模型名稱將要求傳送至 Gemini Enterprise Agent Platform 端點:

  • 如要使用 Mistral Medium 3,請使用 mistral-medium-3
  • 如要使用 Mistral OCR (25.05),請使用 mistral-ocr-2505
  • 如要使用 Mistral Small 3.1 (25.03),請使用 mistral-small-2503
  • 如要使用 Codestral 2,請使用 codestral-2

如要進一步瞭解如何使用 Mistral AI SDK,請參閱 Mistral AI Gemini Enterprise Agent Platform 說明文件。

事前準備

如要透過 Gemini Enterprise Agent Platform 使用 Mistral AI 模型,請按照下列步驟操作。如要使用 Gemini Enterprise Agent Platform,必須啟用 Agent Platform API (aiplatform.googleapis.com)。如果您現有的專案已啟用 Agent Platform API,可以使用該專案,不必建立新專案。

  1. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自體驗產品的實際應用成效。新客戶還能獲得價值 $300 美元的免費抵免額,能用於執行、測試及部署工作負載。
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Gemini Enterprise Agent Platform API, if it is 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 API

  5. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Gemini Enterprise Agent Platform API, if it is 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 API

  8. 前往下列任一 Model Garden 模型資訊卡,然後按一下「啟用」:

對 Mistral AI 模型進行串流呼叫

以下範例會對 Mistral AI 模型發出串流呼叫。

REST

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

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

  • LOCATION:支援 Mistral AI 模型的區域。
  • MODEL:要使用的模型名稱。在要求主體中,排除 @ 模型版本號碼。
  • ROLE:與訊息相關聯的角色。您可以指定 user 或 assistant。 第一則訊息必須使用 user 角色。模型會交替進行 user 和 assistant 回合。如果最後一則訊息使用 assistant 角色,回應內容會立即接續該訊息的內容。您可以使用這項功能限制模型回覆的部分內容。
  • STREAM:布林值,用於指定是否要串流傳送回覆。串流傳送回覆內容,減少使用者對延遲的感受。設為 true 可串流回覆,設為 false 則可一次傳回回覆。
  • CONTENT:user 或 assistant 訊息的內容,例如文字。
  • MAX_OUTPUT_TOKENS: 回覆內可以生成的詞元數量上限。一個權杖約為 3.5 個字元。100 個符記約等於 60 到 80 個字。

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

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:streamRawPredict

JSON 要求內文:

{
"model": MODEL,
  "messages": [
   {
    "role": "ROLE",
    "content": "CONTENT"
   }],
  "max_tokens": MAX_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/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:streamRawPredict"

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/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:streamRawPredict" | Select-Object -Expand Content

您應該會收到類似以下的 JSON 回應。

對 Mistral AI 模型發出一元呼叫

下列範例會對 Mistral AI 模型進行一元呼叫。

REST

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

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

  • LOCATION:支援 Mistral AI 模型的區域。
  • MODEL:要使用的模型名稱。在要求主體中,排除 @ 模型版本號碼。
  • ROLE:與訊息相關聯的角色。您可以指定 user 或 assistant。 第一則訊息必須使用 user 角色。模型會交替進行 user 和 assistant 回合。如果最後一則訊息使用 assistant 角色,回應內容會立即接續該訊息的內容。您可以使用這項功能限制模型回覆的部分內容。
  • STREAM:布林值,用於指定是否要串流傳送回覆。串流傳送回覆內容,減少使用者對延遲的感受。設為 true 可串流回覆,設為 false 則可一次傳回回覆。
  • CONTENT:user 或 assistant 訊息的內容,例如文字。
  • MAX_OUTPUT_TOKENS: 回覆內可以生成的詞元數量上限。一個權杖約為 3.5 個字元。100 個符記約等於 60 到 80 個字。

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

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:rawPredict

JSON 要求內文:

{
"model": MODEL,
  "messages": [
   {
    "role": "ROLE",
    "content": "CONTENT"
   }],
  "max_tokens": MAX_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/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:rawPredict"

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/v1/projects/PROJECT_ID/locations/LOCATION/publishers/mistralai/models/MODEL:rawPredict" | Select-Object -Expand Content

您應該會收到類似以下的 JSON 回應。

Mistral AI 模型區域供應情形和配額

使用 Mistral AI 模型時,每個提供模型的區域都有配額限制。配額以每分鐘查詢次數 (QPM) 和每分鐘權杖數 (TPM) 為單位。TPM 包含輸入和輸出詞元。

模型 區域 配額 脈絡長度
Mistral Medium 3
us-central1
  • QPM:90
  • TPM:315,000
128,000
europe-west4
  • QPM:90
  • TPM:315,000
128,000
Mistral OCR (25.05)
us-central1
  • 每分鐘查詢次數:30
  • 每個要求頁數:30 (1 頁 = 100 萬個輸入權杖和 100 萬個輸出權杖)
30 頁
europe-west4
  • 每分鐘查詢次數:30
  • 每個要求頁數:30 (1 頁 = 100 萬個輸入權杖和 100 萬個輸出權杖)
30 頁
Mistral Small 3.1 (25.03)
us-central1
  • QPM:60
  • TPM:200,000
128,000
europe-west4
  • QPM:60
  • TPM:200,000
128,000
Codestral 2
us-central1
  • 每分鐘查詢次數:1,100
  • 輸入 TPM:1,100,000
  • 輸出 TPM:110,000
128,000 個權杖
europe-west4
  • 每分鐘查詢次數:1,100
  • 輸入 TPM:1,100,000
  • 輸出 TPM:110,000
128,000 個權杖

如要增加任何 Agent Platform 的配額,您可以透過 Google Cloud 主控台申請提高配額。如要進一步瞭解配額,請參閱「Cloud Quotas 總覽」。