Azure AI
介绍
Mistral AI 的开源模型和商业模型可以通过两种方式部署在 Microsoft Azure AI 云平台上
-
按用量付费的托管服务:使用模型即服务(MaaS)无服务器 API 部署,按端点使用量计费。部署不需要 GPU 容量配额。
-
实时端点:根据您选择部署的底层 GPU 基础设施,按配额计费。
本页面重点介绍 MaaS 服务,其中提供以下模型
- Mistral Large (24.11, 24.07)
- Mistral Small (24.09)
- Ministral 3B (24.10)
- Mistral Nemo
更多详细信息,请访问模型页面。
入门
以下部分概述了在 Azure AI MaaS 平台上部署和查询 Mistral 模型的步骤。
部署模型
按照Azure 文档中的说明,为您选择的模型创建新的部署。部署后,记下其对应的 URL 和密钥。
查询模型
部署的端点暴露了一个 REST API,您可以使用 Mistral 的 SDK 或纯 HTTP 调用来查询。
要运行以下示例,请设置以下环境变量
AZUREAI_ENDPOINT
: 您的端点 URL,格式应为https://your-endpoint.inference.ai.azure.com/v1/chat/completions
。AZUREAI_API_KEY
: 您的密钥。
- cURL
- Python
- TypeScript
curl --location $AZUREAI_ENDPOINT/v1/chat/completions \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $AZURE_API_KEY" \
--data '{
"model": "azureai",
"messages": [
{
"role": "user",
"content": "Who is the best French painter? Answer in one short sentence."
}
]
}'
此代码需要在包含以下软件包的虚拟环境中运行
mistralai-azure>=1.0.0
from mistralai_azure import MistralAzure
import os
endpoint = os.environ.get("AZUREAI_ENDPOINT", "")
api_key = os.environ.get("AZUREAI_API_KEY", "")
client = MistralAzure(azure_endpoint=endpoint,
azure_api_key=api_key)
resp = client.chat.complete(messages=[
{
"role": "user",
"content": "Who is the best French painter? Answer in one short sentence."
},
], model="azureai")
if resp:
print(resp)
此代码需要以下软件包
@mistralai/mistralai-azure
(版本 >=1.0.0
)
import { MistralAzure } from "@mistralai/mistralai-azure";
const client = new MistralAzure({
endpoint: process.env.AZUREAI_ENDPOINT || "",
apiKey: process.env.AZUREAI_API_KEY || ""
});
async function chat_completion(user_msg: string) {
const resp = await client.chat.complete({
model: "azureai",
messages: [
{
content: user_msg,
role: "user",
},
],
});
if (resp.choices && resp.choices.length > 0) {
console.log(resp.choices[0]);
}
}
chat_completion("Who is the best French painter? Answer in one short sentence.");
深入了解
更多详细信息和示例,请参考以下资源
- Mistral Large 2 和 Mistral NeMo 的发布博客文章.
- Azure 关于 Mistral 模型 MaaS 部署的文档.
- Azure ML 示例 GitHub 仓库,其中包含多个基于 Mistral 的示例。