You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/ai-foundry/model-inference/includes/use-chat-reasoning/rest.md
+120-8Lines changed: 120 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,22 +27,41 @@ To complete this tutorial, you need:
27
27
28
28
First, create the client to consume the model. The following code uses an endpoint URL and key that are stored in environment variables.
29
29
30
+
# [OpenAI API](#tab/openai)
31
+
30
32
```http
31
-
POST https://<resource>.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview
33
+
POST https://<resource>.services.ai.azure.com/openai/deployments/deepseek-r1/chat/completions?api-version=2024-10-21
32
34
Content-Type: application/json
33
35
api-key: <key>
34
36
```
35
37
36
-
> [!TIP]
37
-
> Verify that you have deployed the model to Azure AI Services resource with the Azure AI Foundry Models API. `Deepseek-R1` is also available as standard deployments. However, those endpoints don't take the parameter `model` as explained in this tutorial. You can verify that by going to [Azure AI Foundry portal]() > Models + endpoints, and verify that the model is listed under the section **Azure AI Services**.
38
+
# [Model Inference API (preview)](#tab/inference)
39
+
40
+
```http
41
+
POST https://<resource>.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview
42
+
Content-Type: application/json
43
+
api-key: <key>
44
+
```
45
+
---
38
46
39
47
If you have configured the resource with **Microsoft Entra ID** support, pass you token in the `Authorization` header with the format `Bearer <token>`. Use scope `https://cognitiveservices.azure.com/.default`.
40
48
49
+
# [OpenAI API](#tab/openai)
50
+
51
+
```http
52
+
POST https://<resource>.services.ai.azure.com/openai/deployments/deepseek-r1/chat/completions?api-version=2024-10-21
53
+
Content-Type: application/json
54
+
Authorization: Bearer <token>
55
+
```
56
+
57
+
# [Model Inference API (preview)](#tab/inference)
58
+
41
59
```http
42
60
POST https://<resource>.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview
43
61
Content-Type: application/json
44
62
Authorization: Bearer <token>
45
63
```
64
+
---
46
65
47
66
Using Microsoft Entra ID may require additional configuration in your resource to grant access. Learn how to [configure key-less authentication with Microsoft Entra ID](../../how-to/configure-entra-id.md).
48
67
@@ -66,6 +85,36 @@ The following example shows how you can create a basic chat request to the model
66
85
67
86
The response is as follows, where you can see the model's usage statistics:
68
87
88
+
# [OpenAI API](#tab/openai)
89
+
90
+
```json
91
+
{
92
+
"id": "0a1234b5de6789f01gh2i345j6789klm",
93
+
"object": "chat.completion",
94
+
"created": 1718726686,
95
+
"model": "DeepSeek-R1",
96
+
"choices": [
97
+
{
98
+
"index": 0,
99
+
"message": {
100
+
"role": "assistant",
101
+
"reasoning_content": "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.\n",
102
+
"content": "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.",
103
+
"tool_calls": null
104
+
},
105
+
"finish_reason": "stop"
106
+
}
107
+
],
108
+
"usage": {
109
+
"prompt_tokens": 11,
110
+
"total_tokens": 897,
111
+
"completion_tokens": 886
112
+
}
113
+
}
114
+
```
115
+
116
+
# [Model Inference API (preview)](#tab/inference)
117
+
69
118
```json
70
119
{
71
120
"id": "0a1234b5de6789f01gh2i345j6789klm",
@@ -90,10 +139,21 @@ The response is as follows, where you can see the model's usage statistics:
90
139
}
91
140
}
92
141
```
142
+
---
93
143
94
144
### Reasoning content
95
145
96
-
Some reasoning models, like DeepSeek-R1, generate completions and include the reasoning behind it. The reasoning associated with the completion is included in the response's content within the tags `<think>` and `</think>`. The model may select on which scenarios to generate reasoning content.
146
+
Some reasoning models, like DeepSeek-R1, generate completions and include the reasoning behind it.
147
+
148
+
# [OpenAI API](#tab/openai)
149
+
150
+
The reasoning associated with the completion is included in the field `reasoning_content`. The model may select on which scenearios to generate reasoning content.
151
+
152
+
# [Model Inference API (preview)](#tab/inference)
153
+
154
+
The reasoning associated with the completion is included in the response's content within the tags `<think>` and `</think>`. The model may select on which scenarios to generate reasoning content.
155
+
156
+
---
97
157
98
158
When making multi-turn conversations, it's useful to avoid sending the reasoning content in the chat history as reasoning tends to generate long explanations.
99
159
@@ -110,10 +170,6 @@ To stream completions, set `"stream": true` when you call the model.
110
170
{
111
171
"model": "DeepSeek-R1",
112
172
"messages": [
113
-
{
114
-
"role": "system",
115
-
"content": "You are a helpful assistant."
116
-
},
117
173
{
118
174
"role": "user",
119
175
"content": "How many languages are in the world?"
@@ -126,6 +182,8 @@ To stream completions, set `"stream": true` when you call the model.
126
182
127
183
To visualize the output, define a helper function to print the stream. The following example implements a routing that stream only the answer without the reasoning content:
128
184
185
+
# [OpenAI API](#tab/openai)
186
+
129
187
```json
130
188
{
131
189
"id": "23b54589eba14564ad8a2e6978775a39",
@@ -137,6 +195,7 @@ To visualize the output, define a helper function to print the stream. The follo
137
195
"index": 0,
138
196
"delta": {
139
197
"role": "assistant",
198
+
"reasoning_content": "Okay,",
140
199
"content": ""
141
200
},
142
201
"finish_reason": null,
@@ -146,8 +205,60 @@ To visualize the output, define a helper function to print the stream. The follo
146
205
}
147
206
```
148
207
208
+
# [Model Inference API (preview)](#tab/inference)
209
+
210
+
```json
211
+
{
212
+
"id": "23b54589eba14564ad8a2e6978775a39",
213
+
"object": "chat.completion.chunk",
214
+
"created": 1718726371,
215
+
"model": "DeepSeek-R1",
216
+
"choices": [
217
+
{
218
+
"index": 0,
219
+
"delta": {
220
+
"role": "assistant",
221
+
"content": "<think>Okay,"
222
+
},
223
+
"finish_reason": null,
224
+
"logprobs": null
225
+
}
226
+
]
227
+
}
228
+
```
229
+
---
230
+
149
231
The last message in the stream has `finish_reason` set, indicating the reason for the generation process to stop.
150
232
233
+
# [OpenAI API](#tab/openai)
234
+
235
+
```json
236
+
{
237
+
"id": "23b54589eba14564ad8a2e6978775a39",
238
+
"object": "chat.completion.chunk",
239
+
"created": 1718726371,
240
+
"model": "DeepSeek-R1",
241
+
"choices": [
242
+
{
243
+
"index": 0,
244
+
"delta": {
245
+
"reasoning_content": "",
246
+
"content": ""
247
+
},
248
+
"finish_reason": "stop",
249
+
"logprobs": null
250
+
}
251
+
],
252
+
"usage": {
253
+
"prompt_tokens": 11,
254
+
"total_tokens": 897,
255
+
"completion_tokens": 886
256
+
}
257
+
}
258
+
```
259
+
260
+
# [Model Inference API (preview)](#tab/inference)
261
+
151
262
```json
152
263
{
153
264
"id": "23b54589eba14564ad8a2e6978775a39",
@@ -171,6 +282,7 @@ The last message in the stream has `finish_reason` set, indicating the reason fo
0 commit comments