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 模型
Mistral AI 提供了以下模型,可在 Gemini Enterprise Agent Platform 中使用。如需访问 Mistral AI 模型,请前往其 Model Garden 模型卡片。
使用 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 文档。
准备工作
如需将 Mistral AI 模型与 Gemini Enterprise Agent Platform 搭配使用,您必须执行以下步骤。必须启用 Agent Platform API (aiplatform.googleapis.com) 才能使用 Gemini Enterprise Agent Platform。如果您已有启用了 Agent Platform API 的项目,则可以使用该项目,而无需创建新项目。
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Cloud de Confiance project.
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.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 个词元 |
如果要增加代理平台 (Agent Platform) 的任何配额,您可以使用 Cloud de Confiance 控制台申请增加配额。如需详细了解配额,请参阅 Cloud 配额概览。