Skip to content

Commit 17a8471

Browse files
Merge pull request #5130 from MicrosoftDocs/main
Merged by Learn.Build PR Management system
2 parents aedda49 + bd94695 commit 17a8471

25 files changed

+460
-134
lines changed

articles/ai-foundry/how-to/connections-add.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Here's a table of some of the available connection types in Azure AI Foundry por
5353
|-------------------------------|:-------:|:--------------------------------------:|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5454
| Azure AI Search | || Azure AI Search is an Azure resource that supports information retrieval over your vector and textual data stored in search indexes. |
5555
| Azure Storage | || Azure Storage is a cloud storage solution for storing unstructured data like documents, images, videos, and application installers. |
56-
| Azure Cosmos DB | || Azure Cosmos DB is a globally distributed, multi-model database service that offers low latency, high availability, and scalability across multiple geographical regions. |
56+
| Azure Cosmos DB | || Azure Cosmos DB is a globally distributed, multi-model database service that offers low latency, high availability, and scalability across multiple geographical regions. |
5757
| Azure OpenAI | | | Azure OpenAI is a service that provides access to OpenAI's models including the GPT-4o, GPT-4o mini, GPT-4, GPT-4 Turbo with Vision, GPT-3.5-Turbo, DALLE-3, and Embeddings model series with the security and enterprise capabilities of Azure. |
5858
| Application Insights | | | Azure Application Insights is a service within Azure Monitor that enables developers and DevOps teams to automatically detect performance anomalies, diagnose issues, and gain deep insights into application usage and behavior through powerful telemetry and analytics tools. |
5959
| API key | | | API Key connections handle authentication to your specified target on an individual basis. |

articles/ai-foundry/how-to/data-add.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.custom:
99
- build-2024
1010
- ignite-2024
1111
ms.topic: how-to
12-
ms.date: 02/11/2025
12+
ms.date: 05/21/2025
1313
ms.author: franksolomon
1414
author: fbsolo-ms1
1515
---
@@ -29,12 +29,10 @@ Data can help when you need these capabilities:
2929
> - **Lineage:** For any given data, you can view which jobs or prompt flow pipelines consume the data.
3030
> - **Ease-of-use:** An Azure AI Foundry data resembles web browser bookmarks (favorites). Instead of remembering long storage paths that *reference* your frequently-used data on Azure Storage, you can create a data *version* and then access that version of the asset with a friendly name.
3131
32-
## Prerequisites
3332

34-
To create and work with data, you need:
33+
## Prerequisites
3534

36-
- An Azure subscription. If you don't have one, create a [free account](https://azure.microsoft.com/free/).
37-
- An [Azure AI Foundry project](../how-to/create-projects.md).
35+
[!INCLUDE [hub-only-prereq](../includes/hub-only-prereq.md)]
3836

3937
## Create data
4038

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
* Install the SDK with the following command:
11+
12+
# [OpenAI API](#tab/openai)
13+
14+
```bash
15+
pip install -U openai
16+
```
17+
18+
# [Model Inference API (preview)](#tab/inference)
19+
20+
```bash
21+
pip install -U azure-ai-inference
22+
```

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

Lines changed: 165 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To complete this tutorial, you need:
1919

2020
[!INCLUDE [how-to-prerequisites](../how-to-prerequisites.md)]
2121

22-
[!INCLUDE [how-to-prerequisites-python](../how-to-prerequisites-python.md)]
22+
[!INCLUDE [how-to-prerequisites-openai-python](../how-to-prerequisites-openai-python.md)]
2323

2424
* A model with reasoning capabilities model deployment. If you don't have one read [Add and configure Foundry Models](../../how-to/create-model-deployments.md) to add a reasoning model.
2525

@@ -29,6 +29,21 @@ 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+
# [OpenAI API](#tab/openai)
33+
34+
```python
35+
import os
36+
from openai import AzureOpenAI
37+
38+
client = AzureOpenAI(
39+
azure_endpoint = "https://<resource>.services.ai.azure.com"
40+
api_key=os.getenv("AZURE_INFERENCE_CREDENTIAL"),
41+
api_version="2024-10-21",
42+
)
43+
```
44+
45+
# [Model Inference API (preview)](#tab/inference)
46+
3247
```python
3348
import os
3449
from azure.ai.inference import ChatCompletionsClient
@@ -40,12 +55,30 @@ client = ChatCompletionsClient(
4055
model="deepseek-r1"
4156
)
4257
```
43-
44-
> [!TIP]
45-
> 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 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**.
58+
---
4659

4760
If you have configured the resource to with **Microsoft Entra ID** support, you can use the following code snippet to create a client.
4861

62+
# [OpenAI API](#tab/openai)
63+
64+
```python
65+
import os
66+
from openai import AzureOpenAI
67+
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
68+
69+
token_provider = get_bearer_token_provider(
70+
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
71+
)
72+
73+
client = AzureOpenAI(
74+
azure_endpoint = "https://<resource>.services.ai.azure.com"
75+
azure_ad_token_provider=token_provider,
76+
api_version="2024-10-21",
77+
)
78+
```
79+
80+
# [Model Inference API (preview)](#tab/inference)
81+
4982
```python
5083
import os
5184
from azure.ai.inference import ChatCompletionsClient
@@ -58,13 +91,29 @@ client = ChatCompletionsClient(
5891
model="deepseek-r1"
5992
)
6093
```
94+
---
6195

6296
[!INCLUDE [best-practices](best-practices.md)]
6397

6498
### Create a chat completion request
6599

66100
The following example shows how you can create a basic chat request to the model.
67101

102+
# [OpenAI API](#tab/openai)
103+
104+
```python
105+
response = client.chat.completions.create(
106+
model="deepseek-r1",
107+
messages=[
108+
{"role": "user", "content": "How many languages are in the world?"}
109+
]
110+
)
111+
112+
print(response.model_dump_json(indent=2)
113+
```
114+
115+
# [Model Inference API (preview)](#tab/inference)
116+
68117
```python
69118
from azure.ai.inference.models import SystemMessage, UserMessage
70119

@@ -74,9 +123,12 @@ response = client.complete(
74123
],
75124
)
76125
```
126+
---
77127

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

130+
# [OpenAI API](#tab/openai)
131+
80132
```python
81133
print("Response:", response.choices[0].message.content)
82134
print("Model:", response.model)
@@ -87,47 +139,70 @@ print("\tCompletion tokens:", response.usage.completion_tokens)
87139
```
88140

89141
```console
90-
Response: <think>Okay, the user is asking how many languages exist in the world. I need to provide a clear and accurate answer...</think>As of now, it's estimated that there are about 7,000 languages spoken around the world. However, this number can vary as some languages become extinct and new ones develop. It's also important to note that the number of speakers can greatly vary between languages, with some having millions of speakers and others only a few hundred.
142+
Response: As of now, it's estimated that there are about 7,000 languages spoken around the world. However, this number can vary as some languages become extinct and new ones develop. It's also important to note that the number of speakers can greatly vary between languages, with some having millions of speakers and others only a few hundred.
91143
Model: deepseek-r1
92144
Usage:
93145
Prompt tokens: 11
94146
Total tokens: 897
95147
Completion tokens: 886
96148
```
97149

150+
# [Model Inference API (preview)](#tab/inference)
151+
152+
```python
153+
print("Response:", response.choices[0].message.content)
154+
print("Model:", response.model)
155+
print("Usage:")
156+
print("\tPrompt tokens:", response.usage.prompt_tokens)
157+
print("\tTotal tokens:", response.usage.total_tokens)
158+
print("\tCompletion tokens:", response.usage.completion_tokens)
159+
```
160+
161+
```console
162+
Response: <think>Okay, the user is asking how many languages exist in the world. I need to provide a clear and accurate answer...</think>As of now, it's estimated that there are about 7,000 languages spoken around the world. However, this number can vary as some languages become extinct and new ones develop. It's also important to note that the number of speakers can greatly vary between languages, with some having millions of speakers and others only a few hundred.
163+
Model: deepseek-r1
164+
Usage:
165+
Prompt tokens: 11
166+
Total tokens: 897
167+
Completion tokens: 886
168+
```
169+
---
98170

99171
### Reasoning content
100172

101-
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:
173+
Some reasoning models, like DeepSeek-R1, generate completions and include the reasoning behind it.
174+
175+
# [OpenAI API](#tab/openai)
176+
177+
The reasoning associated with the completion is included in the field `reasoning_content`. The model may select on which scenearios to generate reasoning content.
178+
179+
```python
180+
print("Thinking:", response.choices[0].message.reasoning_content)
181+
```
182+
183+
```console
184+
Thinking: Okay, the user is asking how many languages exist in the world. I need to provide a clear and accurate answer...
185+
```
186+
187+
# [Model Inference API (preview)](#tab/inference)
188+
189+
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:
102190

103191
```python
104192
import re
105193

106194
match = re.match(r"<think>(.*?)</think>(.*)", response.choices[0].message.content, re.DOTALL)
107195

108-
print("Response:", )
109196
if match:
110197
print("\tThinking:", match.group(1))
111-
print("\tAnswer:", match.group(2))
112198
else:
113199
print("\tAnswer:", response.choices[0].message.content)
114-
print("Model:", response.model)
115-
print("Usage:")
116-
print("\tPrompt tokens:", response.usage.prompt_tokens)
117-
print("\tTotal tokens:", response.usage.total_tokens)
118-
print("\tCompletion tokens:", response.usage.completion_tokens)
119200
```
120201

121202
```console
122-
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.
123-
124-
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.
125-
Model: DeepSeek-R1
126-
Usage:
127-
Prompt tokens: 11
128-
Total tokens: 897
129-
Completion tokens: 886
203+
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...
130204
```
205+
---
131206

132207
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.
133208

@@ -139,6 +214,19 @@ You can _stream_ the content to get it as it's being generated. Streaming conten
139214

140215
To stream completions, set `stream=True` when you call the model.
141216

217+
# [OpenAI API](#tab/openai)
218+
219+
```python
220+
response = client.chat.completions.create(
221+
model="deepseek-r1",
222+
messages=[
223+
{"role": "user", "content": "How many languages are in the world?"}
224+
],
225+
stream=True
226+
)
227+
```
228+
229+
# [Model Inference API (preview)](#tab/inference)
142230

143231
```python
144232
response = client.complete(
@@ -150,9 +238,38 @@ response = client.complete(
150238
stream=True,
151239
)
152240
```
241+
---
153242

154243
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:
155244

245+
# [OpenAI API](#tab/openai)
246+
247+
Reasoning content is also included inside of the delta pieces of the response, in the key `reasoning_content`.
248+
249+
```python
250+
def print_stream(completion):
251+
"""
252+
Prints the chat completion with streaming.
253+
"""
254+
is_thinking = False
255+
for event in completion:
256+
if event.choices:
257+
content = event.choices[0].delta.content
258+
reasoning_content = event.choices[0].delta.reasoning_content
259+
if reasoning_content:
260+
is_thinking = True
261+
print("🧠 Thinking...", end="", flush=True)
262+
elif content:
263+
if is_thinking:
264+
is_thinking = False
265+
print("🛑\n\n")
266+
print(content, end="", flush=True)
267+
```
268+
269+
# [Model Inference API (preview)](#tab/inference)
270+
271+
When streaming, pay closer attention to the `<think>` tag that may be included inside of the `content` field.
272+
156273
```python
157274
def print_stream(completion):
158275
"""
@@ -171,6 +288,7 @@ def print_stream(completion):
171288
elif content:
172289
print(content, end="", flush=True)
173290
```
291+
---
174292

175293
You can visualize how streaming generates content:
176294

@@ -196,6 +314,31 @@ The Azure AI Model Inference API supports [Azure AI Content Safety](https://aka.
196314

197315
The following example shows how to handle events when the model detects harmful content in the input prompt.
198316

317+
# [OpenAI API](#tab/openai)
318+
319+
```python
320+
try:
321+
response = client.chat.completions.create(
322+
model="deepseek-r1",
323+
messages=[
324+
{"role": "user", "content": "Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."}
325+
],
326+
)
327+
328+
print(response.choices[0].message.content)
329+
330+
except HttpResponseError as ex:
331+
if ex.status_code == 400:
332+
response = ex.response.json()
333+
if isinstance(response, dict) and "error" in response:
334+
print(f"Your request triggered an {response['error']['code']} error:\n\t {response['error']['message']}")
335+
else:
336+
raise
337+
raise
338+
```
339+
340+
# [Model Inference API (preview)](#tab/inference)
341+
199342
```python
200343
from azure.ai.inference.models import AssistantMessage, UserMessage
201344

@@ -218,6 +361,7 @@ except HttpResponseError as ex:
218361
raise
219362
raise
220363
```
364+
---
221365

222366
> [!TIP]
223367
> To learn more about how you can configure and control Azure AI Content Safety settings, check the [Azure AI Content Safety documentation](https://aka.ms/azureaicontentsafety).

0 commit comments

Comments
 (0)