Gemini Enterprise Agent Platform 上的 Mistral AI 模型提供全代管無伺服器模型,做為 API。如要在 Agent Platform 上使用 Mistral AI 模型,請直接向 Agent Platform API 端點傳送要求。由於 Mistral AI 模型使用代管 API,因此不必佈建或管理基礎架構。
您可以串流傳送回覆,減少使用者感受到的延遲時間。串流回應會使用伺服器傳送事件 (SSE),逐步串流回應。
您只需在用量達到一定程度時,才需支付 Mistral AI 模型費用 (即付即用)。如要瞭解隨用隨付方案的定價,請參閱 Gemini Enterprise Agent Platform 定價頁面
page。
可用的 Mistral AI 模型
您可以在 Gemini Enterprise Agent Platform 中使用 Mistral AI 的下列模型。如要存取 Mistral AI 模型,請前往 Model Garden 的模型資訊卡。
Mistral Medium 3
Mistral Medium 3 是用途廣泛的模型,適用於各種工作,包括程式設計、數學推論、解讀長篇文件、摘要和對話。擅長處理需要進階推理能力、理解圖像或高度專業知識的複雜工作,例如:創意寫作、代理工作流程、生成程式碼。
Gemini 具有多模態功能,可處理視覺輸入內容,並支援數十種語言,包括超過 80 種程式設計語言。此外,這項模型還提供函式呼叫和代理工作流程。
Mistral Medium 3 專為單一節點推論作業最佳化,特別適合長背景區間的應用程式。因此單一節點可達到高處理量。
Mistral OCR (25.05)
Mistral OCR (25.05) 是文件理解的光學字元辨識 API。Mistral OCR (25.05) 擅長解讀複雜的文件元素,包括交錯的圖像、數學運算式、表格,以及 LaTeX 格式等進階版面配置。這項模型可深入瞭解內容豐富的文件,例如含有圖表、方程式和圖示的科學論文。
Mistral OCR (25.05) 是搭配 RAG 系統使用的理想模型,可將多模態文件 (例如投影片或複雜的 PDF) 做為輸入內容。
您可以將 Mistral OCR (25.05) 與其他 Mistral 模型配對,重新格式化結果。這項組合可確保擷取的內容不僅準確,還能以結構化且連貫的方式呈現,因此適用於各種下游應用程式和分析。
Mistral Small 3.1 (25.03)
Mistral Small 3.1 (25.03) 具備多模態功能,脈絡窗口最多可達 128,000 個詞元。與先前的 Mistral AI Small 模型相比,這款模型可處理及解讀視覺輸入內容和長篇文件,進一步擴大應用範圍。Mistral Small 3.1 (25.03) 是一款多功能模型,適用於程式設計、數學推理、文件解讀和對話等各種工作。Mistral Small 3.1 (25.03) 專為低延遲應用程式設計,與同等品質的模型相比,可提供頂尖效率。
Mistral Small 3.1 (25.03) 經過完整的訓練後處理程序,可配合人類偏好和需求,因此適用於需要聊天或精確遵循指令的應用程式。
前往 Mistral Small 3.1 (25.03) 模型資訊卡
Codestral 2
Codestral 2 是 Mistral 專為程式碼生成打造的模型,特別適合高精確度的中間填空 (FIM) 補全。開發人員可透過共用的指令和完成 API 端點,編寫程式碼並與程式碼互動。這項技術精通程式碼,也能使用多種語言對話,因此軟體開發人員可運用這項技術設計進階 AI 應用程式。
最新版 Codestral 2 比舊版 Codestral (25.01) 有顯著提升:
- 接受的完成次數增加 30%。
- 建議後保留的程式碼多出 10%。
- 減少 50% 的失控生成內容,提高對較長編輯內容的信心。
改善短期和長期情境 FIM 完成的學術基準成效。
- 生成程式碼:程式碼完成、建議、翻譯。
- 瞭解程式碼和說明文件:程式碼摘要和說明。
- 程式碼品質:程式碼審查、重構、修正錯誤及生成測試案例。
- 程式碼填空:使用者可以透過提示定義程式碼的起點,並使用選用後置字串和選用停止字元定義程式碼的終點。Codestral 模型接著會生成適合插入兩者之間的程式碼,因此非常適合需要生成特定程式碼片段的工作。
使用 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 的現有專案,可以使用該專案,不必建立新專案。
- 登入 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 模型資訊卡,然後按一下「啟用」:
對 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 |
|
128,000 | |
europe-west4 |
|
128,000 | |
| Mistral OCR (25.05) | |||
us-central1 |
|
30 頁 | |
europe-west4 |
|
30 頁 | |
| Mistral Small 3.1 (25.03) | |||
us-central1 |
|
128,000 | |
europe-west4 |
|
128,000 | |
| Codestral 2 | |||
us-central1 |
|
128,000 個權杖 | |
europe-west4 |
|
128,000 個權杖 |
如要增加 Gemini Enterprise Agent Platform 的生成式 AI 配額,可以透過 Google Cloud 控制台申請提高配額。如要進一步瞭解配額,請參閱「Cloud Quotas 總覽」。