你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
本教程介绍如何在 Azure AI Foundry 中部署和使用 DeepSeek 推理模型。 本教程使用 DeepSeek-R1 进行说明。 但是,内容也适用于较新的 DeepSeek-R1-0528 推理模型。
本教程中执行的步骤包括:
- 创建和配置 Azure 资源以在 Azure AI Foundry 模型中使用 DeepSeek-R1。
- 配置模型部署。
- 将 DeepSeek-R1 与 Azure AI 推理 SDK 或 REST API 配合使用。
- 将 DeepSeek-R1 与其他 SDK 配合使用。
先决条件
若要完成本文,需要做好以下准备:
- 一份 Azure 订阅。 如果你正在使用 GitHub 模型,则可以升级体验并在此过程中创建 Azure 订阅。 如果适用于你,请阅读 从 GitHub 模型升级到 Azure AI Foundry 模型。
推理模型
推理模型可以在数学、编码、科学、策略和物流等领域达到更高的性能水平。 这些模型生成输出的方式是显式使用思想链在生成答案之前探索所有可能的路径。 他们在生成答案时验证答案,这有助于得出更准确的结论。 因此,推理模型在提示时可能需要更少的上下文才能产生有效的结果。
这种缩放模型性能的方式称为 推理计算时间 ,因为它将性能与更高的延迟和成本交易。 相比之下,其他方法可能会通过 训练计算时间进行扩展。
推理模型生成两种类型的内容作为输出:
- 推理完成
- 输出完成
这两个完成同时计入该模型生成的内容计数。 因此,两者会占用与该模型关联的令牌上限和费用。 某些模型(如 DeepSeek-R1)可能会响应推理内容。 其他项(例如 o1)仅输出补全结果。
创建资源
Foundry Models 是 Azure 中 Azure AI Foundry 资源中的一项功能。 可以在该资源下创建模型部署,以使用其预测。 还可以将资源连接到 Azure AI Foundry 中的 Azure AI 中心和项目,以根据需要创建智能应用程序。
若要创建支持 DeepSeek-R1 部署的 Azure AI 项目,请执行以下步骤。 还可以使用 Azure CLI 或基础结构即代码和 Bicep 来创建资源。
小窍门
由于可以在 Azure AI Foundry 门户中 自定义左窗格 ,因此你可能会看到与这些步骤中显示的项不同。 如果未看到要查找的内容,请选择 ... 左窗格底部的更多内容。
登录到 Azure AI Foundry 门户。
搜索 DeepSeek-R1 模型并打开其模型卡。
选择“ 使用此模型”。 此操作将打开一个向导,用于创建您将使用的 Azure AI Foundry 项目和资源。 可以保留项目的默认名称或更改它。
选择向导的“高级选项”部分中的下拉列表,查看与项目一起创建的设置和其他默认值的详细信息。 选择这些默认值以获得最佳功能,包括:
资产 DESCRIPTION 资源组 Azure 中所有资源的主容器。 此容器可帮助你组织协同工作的资源。 它还有助于确定与整个项目相关的成本的范围。 区域 要创建的资源的区域。 Azure AI Foundry 资源 资源允许访问 Azure AI 模型目录中的旗舰模型。 在本教程中,会创建一个新帐户,但 Azure AI Foundry 资源(以前称为 Azure AI 服务资源)可以在多个中心和项目中共享。 中心使用与资源的连接来访问该资源可用的模型部署。 若要了解如何创建与 Azure AI Foundry 资源的连接以使用模型,请参阅 连接 AI 项目。 选择 “创建 ”以与其他默认值一起创建 Foundry 项目。 等待项目创建完成。 此过程需要花费几分钟时间。
部署模型
创建项目和资源时,将显示部署向导。 DeepSeek-R1 作为由 Azure 直接销售的 Foundry 模型提供。 可以通过在 Azure AI Foundry 模型定价页上选择 DeepSeek 选项卡来查看模型的定价详细信息。
配置部署设置。 默认情况下,部署会接收正在部署的模型的名称。 部署名称用于请求路由到此特定模型部署的
model参数中。 此设置允许在附加特定配置时为模型配置特定名称。Azure AI Foundry 会自动选择之前使用项目创建的 Foundry 资源。 使用“自定义”选项根据需求更改连接。 DeepSeek-R1 目前以 全局标准 部署类型提供,可提供更高的吞吐量和性能。
选择“部署”。
部署完成后,“部署 详细信息 ”页随即打开。 现在,新模型已准备就绪,可供使用。
在操场中使用模型
您可以在实验环境中使用该模型,以便初步了解模型的功能。
在部署详细信息页上,选择顶部栏中的“在操场中打开”。 此操作会打开聊天游乐场。
在聊天沙盒的部署下拉列表中,你创建的部署已被自动选中。
根据需要配置系统提示。 一般情况下,推理模型不会像其他类型的模型一样使用系统消息。
键入提示并查看输出。
使用 “查看代码” 查看有关如何以编程方式访问模型部署的详细信息。
即时推理模型
生成推理模型的提示时,请考虑以下事项:
- 使用简单的说明,避免使用思维链技巧。
- 内置的推理功能使简单的零次提示和更复杂的方法一样有效。
- 提供其他上下文或文档(例如在 RAG 方案中)时,仅包括最相关的信息可能有助于防止模型过度复杂化其响应。
- 推理模型可能支持使用系统消息。 但是,它们可能不会像其他非推理模型那样严格地遵循它们。
- 创建多轮次应用程序时,请考虑仅追加模型的最终答案,而不考虑按推理内容部分所述对内容进行推理。
请注意,推理模型可能需要更长的时间才能生成响应。 他们使用长期推理的思维链,可实现更深层次、更结构化的问题解决。 他们还执行自我验证,交叉检查答案并纠正错误,从而展示新兴的自我反省行为。
在代码中使用模型
使用 Foundry 模型终结点和凭据连接到模型:
通过 Azure AI 模型推理包在代码中使用模型:
使用包管理器(例如 pip)安装包 azure-ai-inference:
pip install azure-ai-inference
然后,可以使用该包来调用模型。 以下示例演示如何创建客户端程序来调用聊天结果:
import os
from azure.ai.inference import ChatCompletionsClient
from azure.core.credentials import AzureKeyCredential
client = ChatCompletionsClient(
endpoint="https://<resource>.services.ai.azure.com/models",
credential=AzureKeyCredential(os.environ["AZURE_INFERENCE_CREDENTIAL"]),
)
from azure.ai.inference.models import SystemMessage, UserMessage
response = client.complete(
messages=[
UserMessage(content="How many languages are in the world?"),
],
model="DeepSeek-R1"
)
print(response.choices[0].message.content)
推理可能会生成更长的响应,并消耗更多令牌。 可以看到适用于 DeepSeek-R1 模型的 速率限制 。 请考虑使用重试策略来处理速率限制。 还可以 请求增加默认限制。
逻辑推理内容
某些推理模型(如 DeepSeek-R1)会生成补全内容并包含其背后的推理。 与补全关联的推理包含在标记 <think> 和 </think> 内的响应内容中。 模型可能会选择要为其生成推理内容的场景。 以下示例演示如何使用 Python 生成推理内容:
import re
match = re.match(r"<think>(.*?)</think>(.*)", response.choices[0].message.content, re.DOTALL)
print("Response:", )
if match:
print("\tThinking:", match.group(1))
print("\tAnswer:", match.group(2))
else:
print("\tAnswer:", response.choices[0].message.content)
print("Model:", response.model)
print("Usage:")
print("\tPrompt tokens:", response.usage.prompt_tokens)
print("\tTotal tokens:", response.usage.total_tokens)
print("\tCompletion tokens:", response.usage.completion_tokens)
Thinking: Okay, the user is asking how many languages exist in the world. I need to provide a clear and accurate answer. Let's start by recalling the general consensus from linguistic sources. I remember that the number often cited is around 7,000, but maybe I should check some reputable organizations.\n\nEthnologue is a well-known resource for language data, and I think they list about 7,000 languages. But wait, do they update their numbers? It might be around 7,100 or so. Also, the exact count can vary because some sources might categorize dialects differently or have more recent data. \n\nAnother thing to consider is language endangerment. Many languages are endangered, with some having only a few speakers left. Organizations like UNESCO track endangered languages, so mentioning that adds context. Also, the distribution isn't even. Some countries have hundreds of languages, like Papua New Guinea with over 800, while others have just a few. \n\nA user might also wonder why the exact number is hard to pin down. It's because the distinction between a language and a dialect can be political or cultural. For example, Mandarin and Cantonese are considered dialects of Chinese by some, but they're mutually unintelligible, so others classify them as separate languages. Also, some regions are under-researched, making it hard to document all languages. \n\nI should also touch on language families. The 7,000 languages are grouped into families like Indo-European, Sino-Tibetan, Niger-Congo, etc. Maybe mention a few of the largest families. But wait, the question is just about the count, not the families. Still, it's good to provide a bit more context. \n\nI need to make sure the information is up-to-date. Let me think – recent estimates still hover around 7,000. However, languages are dying out rapidly, so the number decreases over time. Including that note about endangerment and language extinction rates could be helpful. For instance, it's often stated that a language dies every few weeks. \n\nAnother point is sign languages. Does the count include them? Ethnologue includes some, but not all sources might. If the user is including sign languages, that adds more to the count, but I think the 7,000 figure typically refers to spoken languages. For thoroughness, maybe mention that there are also over 300 sign languages. \n\nSummarizing, the answer should state around 7,000, mention Ethnologue's figure, explain why the exact number varies, touch on endangerment, and possibly note sign languages as a separate category. Also, a brief mention of Papua New Guinea as the most linguistically diverse country. \n\nWait, let me verify Ethnologue's current number. As of their latest edition (25th, 2022), they list 7,168 living languages. But I should check if that's the case. Some sources might round to 7,000. Also, SIL International publishes Ethnologue, so citing them as reference makes sense. \n\nOther sources, like Glottolog, might have a different count because they use different criteria. Glottolog might list around 7,000 as well, but exact numbers vary. It's important to highlight that the count isn't exact because of differing definitions and ongoing research. \n\nIn conclusion, the approximate number is 7,000, with Ethnologue being a key source, considerations of endangerment, and the challenges in counting due to dialect vs. language distinctions. I should make sure the answer is clear, acknowledges the variability, and provides key points succinctly.
Answer: The exact number of languages in the world is challenging to determine due to differences in definitions (e.g., distinguishing languages from dialects) and ongoing documentation efforts. However, widely cited estimates suggest there are approximately **7,000 languages** globally.
Model: DeepSeek-R1
Usage:
Prompt tokens: 11
Total tokens: 897
Completion tokens: 886
参数
一般情况下,推理模型不支持在聊天完成模型中找到的以下参数:
- 温度
- 出现惩罚
- 重复惩罚
- 参数
top_p