Skip to content

Commit 43e0f69

Browse files
committed
feat: tutorial
1 parent 4fd371d commit 43e0f69

File tree

9 files changed

+238
-2
lines changed

9 files changed

+238
-2
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
manager: nitinme
3+
ms.service: azure-ai-model-inference
4+
ms.topic: include
5+
ms.date: 1/21/2025
6+
ms.author: fasantia
7+
author: santiagxf
8+
---
9+
10+
# [Python](#tab/python)
11+
12+
```python
13+
from azure.ai.inference.models import SystemMessage, UserMessage
14+
15+
response = client.complete(
16+
messages=[
17+
UserMessage(content="Explain Riemann's conjecture in 1 paragraph"),
18+
],
19+
model="DeepSeek-R1"
20+
)
21+
22+
print(response.choices[0].message.content)
23+
```
24+
25+
# [JavaScript](#tab/javascript)
26+
27+
```javascript
28+
var messages = [
29+
{ role: "user", content: "Explain Riemann's conjecture in 1 paragraph" },
30+
];
31+
32+
var response = await client.path("/chat/completions").post({
33+
body: {
34+
messages: messages,
35+
model: "DeepSeek-R1"
36+
}
37+
});
38+
39+
console.log(response.choices[0].message.content)
40+
```
41+
42+
# [C#](#tab/csharp)
43+
44+
```csharp
45+
requestOptions = new ChatCompletionsOptions()
46+
{
47+
Messages = {
48+
new ChatRequestUserMessage("Explain Riemann's conjecture in 1 paragraph")
49+
},
50+
Model = "DeepSeek-R1"
51+
};
52+
53+
response = client.Complete(requestOptions);
54+
Console.WriteLine($"Response: {response.Value.Content}");
55+
```
56+
57+
# [Java](#tab/java)
58+
59+
```java
60+
List<ChatRequestMessage> chatMessages = new ArrayList<>();
61+
chatMessages.add(new ChatRequestUserMessage("Explain Riemann's conjecture in 1 paragraph"));
62+
63+
ChatCompletions chatCompletions = client.complete(new ChatCompletionsOptions(chatMessages, "DeepSeek-R1"));
64+
65+
for (ChatChoice choice : chatCompletions.getChoices()) {
66+
ChatResponseMessage message = choice.getMessage();
67+
System.out.println("Response:" + message.getContent());
68+
}
69+
```
70+
71+
# [REST](#tab/rest)
72+
73+
__Request__
74+
75+
```HTTP/1.1
76+
POST https://<resource>.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview
77+
api-key: <api-key>
78+
Content-Type: application/json
79+
```
80+
81+
```JSON
82+
{
83+
"messages": [
84+
{
85+
"role": "user",
86+
"content": "Explain Riemann's conjecture in 1 paragraph"
87+
}
88+
],
89+
"model": "DeepSeek-R1"
90+
}
91+
```
92+
93+
---

articles/ai-foundry/model-inference/includes/use-chat-reasoning/about-reasoning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ author: santiagxf
1111

1212
Reasoning models can reach higher levels of performance in domains like math, coding, science, strategy, and logistics. The way these models produces outputs is by explicitly using chain of thought to explore all possible paths before generating an answer. They verify their answers as they produce them which helps them to arrive to better more accurate conclusions. This means that reasoning models may require less context in prompting in order to produce effective results.
1313

14-
Such way of scaling model's performance is referred as *inference compute time* as it trades performance against higher latency and cost. It contrasts to other approaches that scale through *training compute time*.
14+
Such way of scaling model's performance is referred as *inference compute time* as it trades performance against higher latency and cost. It contrasts to other approaches that scale through *training compute time*.
1515

1616
Reasoning models then produce two types of outputs:
1717

articles/ai-foundry/model-inference/includes/use-chat-reasoning/best-practices.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ When building prompts for reasoning models, take the following into consideratio
1414
> * Built-in reasoning capabilities make simple zero-shot prompts as effective as more complex methods.
1515
> * When providing additional context or documents, like in RAG scenarios, including only the most relevant information may help preventing the model from over-complicating its response.
1616
> * Reasoning models may support the use of system messages. However, they may not follow them as strictly as other non-reasoning models.
17-
> * When creating multi-turn applications, consider only appending the final answer from the model, without it's reasoning content as explained at [Reasoning content](#reasoning-content) section.
17+
> * When creating multi-turn applications, consider only appending the final answer from the model, without it's reasoning content as explained at [Reasoning content](#reasoning-content) section.
18+
19+
Notice that reasoning models can take longer times to generate responses. They use long reasoning chains of thought that enabled deeper and more structured problem-solving. They also perform self-verification to cross-check its own answers and correct its own mistakes, showcasing emergent self-reflective behaviors.
2.39 MB
Loading
2.15 MB
Loading
1.89 MB
Loading
59.5 KB
Loading

articles/ai-foundry/model-inference/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ items:
2424
href: ./how-to/quickstart-github-models.md
2525
- name: Configure AI projects to work with Azure AI model inference
2626
href: ./how-to/quickstart-ai-project.md
27+
- name: Tutorials
28+
items:
29+
- name: Get started with DeepSeek-R1 reasoning model
30+
href: ./tutorials/get-started-deepseek-r1.md
2731
- name: Concepts
2832
items:
2933
- name: Available models
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
title: "Tutorial: Getting started with DeepSeek-R1 reasoning model in Azure AI model inference"
3+
titleSuffix: Azure AI Foundry
4+
description: Learn about the reasoning capabilities of DeepSeek-R1 in Azure AI model inference.
5+
manager: scottpolly
6+
ms.service: azure-ai-model-inference
7+
ms.topic: tutorial
8+
ms.date: 03/01/2025
9+
ms.reviewer: fasantia
10+
ms.author: msakande
11+
author: mopeakande
12+
---
13+
14+
# Tutorial: Get started with DeepSeek-R1 reasoning model in Azure AI model inference
15+
16+
In this tutorial, you learn:
17+
18+
> [!div class="checklist"]
19+
> * How to create and configure the Azure resources to use DeepSeek-R1 model in Azure AI model inference.
20+
> * How to configure the model deployment.
21+
> * How to use DeepSeek-R1 using the Azure AI Inference SDK or REST APIs.
22+
> * How to use DeepSeek-R1 using other SDKs.
23+
24+
## Prerequisites
25+
26+
To complete this article, you need:
27+
28+
* An Azure subscription. If you're using [GitHub Models](https://docs.github.com/en/github-models/), you can upgrade your experience and create an Azure subscription in the process. Read [Upgrade from GitHub Models to Azure AI model inference](../../how-to/quickstart-github-models.md) if that's your case.
29+
30+
[!INCLUDE [about-reasoning](../includes/use-chat-reasoning/about-reasoning.md)]
31+
32+
## Create the resources
33+
34+
Azure AI model inference is a capability in Azure AI Services resources in Azure. You can create model deployments under the resource to consume their predictions. You can also connect the resource to Azure AI Hubs and Projects in Azure AI Foundry to create intelligent applications if needed. The following picture shows the high level architecture.
35+
36+
:::image type="content" source="../media/quickstart-get-started-deepseek-r1/resources-architecture.png" alt-text="A diagram showing the high level architecture of the resources created in the tutorial." lightbox="../media/quickstart-get-started-deepseek-r1/resources-architecture.png":::
37+
38+
To create an Azure AI project that supports model inference for DeepSeek-R1, follow these steps:
39+
40+
1. Go to [Azure AI Foundry portal](https://ai.azure.com) and log in with your account.
41+
42+
2. On the landing page, select **Create project**.
43+
44+
3. Give the project a name, for example "my-project".
45+
46+
4. In this tutorial, we create a brand new project under a new AI hub, hence, select **Create new hub**. Hubs are containers for multiple projects and allow you to share resources across all the projects.
47+
48+
5. Give the hub a name, for example "my-hub" and select **Next**.
49+
50+
6. The wizard updates with details about the resources that are going to be created. Select **Azure resources to be created** to see the details.
51+
52+
:::image type="content" source="../media/create-resources/create-project-with-hub-details.png" alt-text="Screenshot showing the details of the project and hub to be created." lightbox="../media/create-resources/create-project-with-hub-details.png":::
53+
54+
7. You can see that the following resources are created:
55+
56+
| Property | Description |
57+
| -------------- | ----------- |
58+
| Resource group | The main container for all the resources in Azure. This helps get resources that work together organized. It also helps to have a scope for the costs associated with the entire project. |
59+
| Location | The region of the resources that you're creating. |
60+
| Hub | The main container for AI projects in Azure AI Foundry. Hubs promote collaboration and allow you to store information for your projects. |
61+
| AI Services | The resource enabling access to the flagship models in Azure AI model catalog. In this tutorial, a new account is created, but Azure AI services resources can be shared across multiple hubs and projects. Hubs use a connection to the resource to have access to the model deployments available there. To learn how, you can create connections between projects and Azure AI Services to consume Azure AI model inference you can read [Connect your AI project](../../how-to/configure-project-connection.md). |
62+
63+
8. Select **Create**. The resources creation process starts.
64+
65+
9. Once completed, your project is ready to be configured.
66+
67+
10. Azure AI model inference is a Preview feature that needs to be turned on in Azure AI Foundry. At the top navigation bar, over the right corner, select the **Preview features** icon. A contextual blade shows up at the right of the screen.
68+
69+
11. Turn the feature **Deploy models to Azure AI model inference service** on.
70+
71+
:::image type="content" source="../media/quickstart-ai-project/ai-project-inference-endpoint.gif" alt-text="An animation showing how to turn on the Azure AI model inference service deploy models feature in Azure AI Foundry portal." lightbox="../media/quickstart-ai-project/ai-project-inference-endpoint.gif":::
72+
73+
12. Close the panel.
74+
75+
76+
## Add DeepSeek-R1 model deployment
77+
78+
Let's now create a new model deployment for DeepSeek-R1:
79+
80+
1. Go to **Model catalog** section in [Azure AI Foundry portal](https://ai.azure.com/explore/models) and find the model [DeepSeek-R1]() model.
81+
82+
3. You can review the details of the model in the model card.
83+
84+
4. Select **Deploy**.
85+
86+
5. The wizard shows the model's terms and conditions. DeepSeek-R1 is offered as a Microsoft first party consumption service. You can review our privacy and security commitments under [Data, privacy, and Security](). Accept the terms on those cases by selecting **Subscribe and deploy**.
87+
88+
:::image type="content" source="../media/quickstart-get-started-deepseek-r1/models-deploy-agree.png" alt-text="Screenshot showing how to agree the terms and conditions of a DeepSeek-R1 model." lightbox="../media/quickstart-get-started-deepseek-r1/models-deploy-agree.png":::
89+
90+
6. You can configure the deployment settings at this time. By default, the deployment receives the name of the model you're deploying. The deployment name is used in the `model` parameter for request to route to this particular model deployment. This allows you to also configure specific names for your models when you attach specific configurations.
91+
92+
7. We automatically select an Azure AI Services connection depending on your project. Use the **Customize** option to change the connection based on your needs. DeepSeek-R1 is currently offered under the **Global Standard** deployment type which offers higher throughput and performance.
93+
94+
8. Select **Deploy**.
95+
96+
:::image type="content" source="../media/quickstart-get-started-deepseek-r1/models-deploy.png" alt-text="Screenshot showing how to deploy the model." lightbox="../media/quickstart-get-started-deepseek-r1/models-deploy.png":::
97+
98+
9. Once the deployment completes, the new model is listed in the page and it's ready to be used.
99+
100+
## Use the model in playground
101+
102+
You can get started by using the model in the playground to have an idea of the model capabilities.
103+
104+
1. On the deployment details page, select **Open in playground** option in the top bar.
105+
106+
2. In the **Deployment** drop down, the deployment you created has been automatically selected.
107+
108+
3. Configure the system prompt as needed. In general, reasoning models don't use system messages in the same way that other types of models.
109+
110+
:::image type="content" source="../media/quickstart-get-started-deepseek-r1/playground-chat-models.png" alt-text="Screenshot showing how to select a model deployment to use in playground, configure the system message, and test it out." lightbox="../media/quickstart-get-started-deepseek-r1/playground-chat-models.png":::
111+
112+
4. Type your prompt and see the outputs.
113+
114+
5. Additionally, you can use **View code** so see details about how to access the model deployment programmatically.
115+
116+
[!INCLUDE [best-practices](../includes/use-chat-reasoning/best-practices.md)]
117+
118+
## Use the model in code
119+
120+
[!INCLUDE [code-chat-reasoning](../includes/code-create-chat-reasoning.md)]
121+
122+
Reasoning may generate longer responses and consume a larger amount of tokens. You can see the [rate limits](../quotas-limits.md) that apply to DeepSeek-R1 models. Consider having a retry strategy to handle rate limits being applied. You can also [request increases to the default limits](../quotas-limits.md#request-increases-to-the-default-limits).
123+
124+
### Parameters
125+
126+
In general, reasoning models don't support the following parameters you can find in chat completion models:
127+
128+
* Temperature
129+
* Presence penalty
130+
* Repetition penalty
131+
* Parameter `top_p`
132+
133+
## Related content
134+
135+
* [Use chat reasoning models](../how-to/use-chat-reasoning.md)
136+
* [Use image embedding models](../how-to/use-image-embeddings.md)
137+
* [Azure AI Model Inference API](.././reference/reference-model-inference-api.md)

0 commit comments

Comments
 (0)