Skip to content

Commit 741114c

Browse files
committed
restore
1 parent 0ffc001 commit 741114c

File tree

1 file changed

+2
-117
lines changed
  • articles/ai-foundry/model-inference/includes/use-chat-reasoning

1 file changed

+2
-117
lines changed

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

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
manager: nitinme
33
ms.service: azure-ai-model-inference
44
ms.topic: include
5-
ms.date: 04/09/2025
5+
ms.date: 1/31/2025
66
ms.author: fasantia
77
author: santiagxf
88
---
@@ -29,50 +29,18 @@ To complete this tutorial, you need:
2929

3030
First, create the client to consume the model. The following code uses an endpoint URL and key that are stored in environment variables.
3131

32-
# [API version 2025-04-01](#tab/2025-04-01)
33-
3432
```csharp
3533
ChatCompletionsClient client = new ChatCompletionsClient(
3634
new Uri("https://<resource>.services.ai.azure.com/models"),
3735
new AzureKeyCredential(Environment.GetEnvironmentVariable("AZURE_INFERENCE_CREDENTIAL"))
3836
);
3937
```
4038

41-
# [API version 2024-05-01-preview](#tab/2024-05-01-preview)
42-
43-
```csharp
44-
ChatCompletionsClient client = new ChatCompletionsClient(
45-
new Uri("https://<resource>.services.ai.azure.com/models"),
46-
new AzureKeyCredential(Environment.GetEnvironmentVariable("AZURE_INFERENCE_CREDENTIAL")),
47-
new AzureAIInferenceClientOptions(ApiVersion="2024-05-01-preview");
48-
);
49-
```
50-
51-
---
52-
5339
> [!TIP]
5440
> Verify that you have deployed the model to Azure AI Services resource with the Azure AI model inference API. `Deepseek-R1` is also available as Serverless API Endpoints. 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**.
5541
5642
If you have configured the resource to with **Microsoft Entra ID** support, you can use the following code snippet to create a client.
5743

58-
# [API version 2025-04-01](#tab/2025-04-01)
59-
60-
```csharp
61-
TokenCredential credential = new DefaultAzureCredential(includeInteractiveCredentials: true);
62-
AzureAIInferenceClientOptions clientOptions = new AzureAIInferenceClientOptions();
63-
BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy(credential);
64-
65-
clientOptions.AddPolicy(tokenPolicy, HttpPipelinePosition.PerRetry);
66-
67-
client = new ChatCompletionsClient(
68-
new Uri("https://<resource>.services.ai.azure.com/models"),
69-
credential,
70-
clientOptions,
71-
);
72-
```
73-
74-
# [API version 2024-05-01-preview](#tab/2024-05-01-preview)
75-
7644
```csharp
7745
TokenCredential credential = new DefaultAzureCredential(includeInteractiveCredentials: true);
7846
AzureAIInferenceClientOptions clientOptions = new AzureAIInferenceClientOptions();
@@ -87,8 +55,6 @@ client = new ChatCompletionsClient(
8755
);
8856
```
8957

90-
---
91-
9258
### Create a chat completion request
9359

9460
The following example shows how you can create a basic chat request to the model.
@@ -109,29 +75,6 @@ Response<ChatCompletions> response = client.Complete(requestOptions);
10975

11076
The response is as follows, where you can see the model's usage statistics:
11177

112-
# [API version 2025-04-01](#tab/2025-04-01)
113-
114-
```csharp
115-
Console.WriteLine($"Response: {response.Value.Content}");
116-
Console.WriteLine($"Model: {response.Value.Model}");
117-
Console.WriteLine("Usage:");
118-
Console.WriteLine($"\tPrompt tokens: {response.Value.Usage.PromptTokens}");
119-
Console.WriteLine($"\tTotal tokens: {response.Value.Usage.TotalTokens}");
120-
Console.WriteLine($"\tCompletion tokens: {response.Value.Usage.CompletionTokens}");
121-
```
122-
123-
```console
124-
Response: 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.
125-
Model: deepseek-r1
126-
Usage:
127-
Prompt tokens: 11
128-
Total tokens: 897
129-
Completion tokens: 886
130-
```
131-
132-
133-
# [API version 2024-05-01-preview](#tab/2024-05-01-preview)
134-
13578
```csharp
13679
Console.WriteLine($"Response: {response.Value.Content}");
13780
Console.WriteLine($"Model: {response.Value.Model}");
@@ -150,28 +93,9 @@ Usage:
15093
Completion tokens: 886
15194
```
15295

153-
---
154-
15596
### Reasoning content
15697

157-
Some reasoning models, like DeepSeek-R1, generate completions and include the reasoning behind it.
158-
159-
# [API version 2025-04-01](#tab/2025-04-01)
160-
161-
The reasoning associated with the completion is included in the response's `ReasoningContent` field. The model may select on which scenarios to generate reasoning content.
162-
163-
```csharp
164-
Console.WriteLine($"Thinking: {response.Value.ReasoningContent}");
165-
```
166-
167-
```console
168-
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.
169-
```
170-
171-
172-
# [API version 2024-05-01-preview](#tab/2024-05-01-preview)
173-
174-
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. You can extract the reasoning content from the response to understand the model's thought process as follows:
98+
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. You can extract the reasoning content from the response to understand the model's thought process as follows:
17599

176100
```csharp
177101
Regex regex = new Regex(pattern, RegexOptions.Singleline);
@@ -204,8 +128,6 @@ Usage:
204128
Completion tokens: 886
205129
```
206130

207-
---
208-
209131
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.
210132

211133
### Stream content
@@ -234,41 +156,6 @@ static async Task StreamMessageAsync(ChatCompletionsClient client)
234156

235157
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:
236158

237-
# [API version 2025-04-01](#tab/2025-04-01)
238-
239-
```csharp
240-
static void PrintStream(StreamingResponse<StreamingChatCompletionsUpdate> response)
241-
{
242-
bool isThinking = false;
243-
await foreach (StreamingChatCompletionsUpdate chatUpdate in response)
244-
{
245-
if (!string.IsNullOrEmpty(chatUpdate.ContentUpdate))
246-
{
247-
string content = chatUpdate.ContentUpdate;
248-
string reasoningContent = chatUpdate.ReasoningContentUpdate;
249-
if (!string.IsNullOrEmpty(reasoningContent))
250-
{
251-
isThinking = true;
252-
Console.Write("🧠 Thinking...");
253-
Console.Out.Flush();
254-
}
255-
else if (string.IsNullOrEmpty(reasoningContent))
256-
{
257-
isThinking = false;
258-
Console.WriteLine("🛑\n\n");
259-
}
260-
else if (!string.IsNullOrEmpty(content))
261-
{
262-
Console.Write(content);
263-
Console.Out.Flush();
264-
}
265-
}
266-
}
267-
}
268-
```
269-
270-
# [API version 2024-05-01-preview](#tab/2024-05-01-preview)
271-
272159
```csharp
273160
static void PrintStream(StreamingResponse<StreamingChatCompletionsUpdate> response)
274161
{
@@ -299,8 +186,6 @@ static void PrintStream(StreamingResponse<StreamingChatCompletionsUpdate> respon
299186
}
300187
```
301188

302-
---
303-
304189
You can visualize how streaming generates content:
305190

306191

0 commit comments

Comments
 (0)