Skip to content

Commit 25b08b9

Browse files
committed
Update quickstart-chat-completion-python.md
1 parent 940833a commit 25b08b9

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

articles/azure-app-configuration/quickstart-chat-completion-python.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.devlang: python
99
ms.custom: devx-track-python, mode-other
1010
ms.topic: quickstart
1111
ms.tgt_pltfrm: Python
12-
ms.date: 03/04/2026
12+
ms.date: 03/11/2026
1313
ms.update-cycle: 180-days
1414
ms.author: mametcal
1515
ms.collection: ce-skilling-ai-copilot
@@ -40,7 +40,7 @@ The full sample source code is available in the [Azure App Configuration GitHub
4040
```console
4141
pip install azure-appconfiguration-provider
4242
pip install azure-identity
43-
pip install azure-ai-inference
43+
pip install azure-ai-projects
4444
```
4545

4646
1. Create a file named `app.py` and add the following import statements:
@@ -49,7 +49,7 @@ The full sample source code is available in the [Azure App Configuration GitHub
4949
import os
5050
from azure.appconfiguration.provider import load, SettingSelector, WatchKey
5151
from azure.identity import DefaultAzureCredential
52-
from azure.ai.inference import ChatCompletionsClient
52+
from azure.ai.projects import AIProjectClient
5353
```
5454

5555
1. Create a function to load configuration from Azure App Configuration.
@@ -101,18 +101,18 @@ The full sample source code is available in the [Azure App Configuration GitHub
101101
102102
1. Create the main function that configures the chat client and runs the chat loop.
103103
104-
Create an instance of the `ChatCompletionsClient` to connect to your Azure AI Foundry project. You use `DefaultAzureCredential` to authenticate. Assign the **Cognitive Services OpenAI User** role to the identity represented by `DefaultAzureCredential`. For detailed steps, refer to the [Role-based access control for Azure OpenAI service](/azure/ai-services/openai/how-to/role-based-access-control) guide. Be sure to allow sufficient time for the permission to propagate before running your application.
104+
Create an instance of the `AIProjectClient` to connect to your Azure AI Foundry project. You use `DefaultAzureCredential` to authenticate. Assign the **Cognitive Services OpenAI User** role to the identity represented by `DefaultAzureCredential`. For detailed steps, refer to the [Role-based access control for Azure OpenAI service](/azure/ai-services/openai/how-to/role-based-access-control) guide. Be sure to allow sufficient time for the permission to propagate before running your application.
105105
106106
```python
107107
def main():
108108
config = load_azure_app_configuration()
109109
110-
# Create a chat client using Microsoft Entra ID
111-
client = ChatCompletionsClient(
110+
# Create a project client using Microsoft Entra ID
111+
project_client = AIProjectClient(
112112
endpoint=config["AzureAIFoundry:Endpoint"],
113113
credential=credential,
114-
credential_scopes=["https://cognitiveservices.azure.com/.default"],
115114
)
115+
openai_client = project_client.get_openai_client()
116116
117117
# Initialize chat conversation
118118
chat_conversation = []
@@ -134,7 +134,7 @@ The full sample source code is available in the [Azure App Configuration GitHub
134134
chat_conversation.append({"role": "user", "content": user_input})
135135
136136
# Get AI response and add it to chat conversation
137-
response = get_ai_response(client, config, chat_conversation)
137+
response = get_ai_response(openai_client, config, chat_conversation)
138138
print(f"AI: {response}")
139139
chat_conversation.append({"role": "assistant", "content": response})
140140
@@ -150,7 +150,7 @@ The full sample source code is available in the [Azure App Configuration GitHub
150150
import os
151151
from azure.appconfiguration.provider import load, SettingSelector, WatchKey
152152
from azure.identity import DefaultAzureCredential
153-
from azure.ai.inference import ChatCompletionsClient
153+
from azure.ai.projects import AIProjectClient
154154
155155
credential = DefaultAzureCredential()
156156
@@ -185,22 +185,23 @@ The full sample source code is available in the [Azure App Configuration GitHub
185185
messages.extend(chat_conversation)
186186
187187
# Create chat completion
188-
response = client.complete(
188+
response = client.chat.completions.create(
189189
model=chat_completion_config["model"],
190190
messages=messages,
191+
max_completion_tokens=chat_completion_config["max_completion_tokens"],
191192
)
192193
return response.choices[0].message.content
193194
194195
195196
def main():
196197
config = load_azure_app_configuration()
197198
198-
# Create a chat client using Microsoft Entra ID
199-
client = ChatCompletionsClient(
199+
# Create a project client using Microsoft Entra ID
200+
project_client = AIProjectClient(
200201
endpoint=config["AzureAIFoundry:Endpoint"],
201202
credential=credential,
202-
credential_scopes=["https://cognitiveservices.azure.com/.default"],
203203
)
204+
openai_client = project_client.get_openai_client()
204205
205206
# Initialize chat conversation
206207
chat_conversation = []
@@ -222,7 +223,7 @@ The full sample source code is available in the [Azure App Configuration GitHub
222223
chat_conversation.append({"role": "user", "content": user_input})
223224
224225
# Get AI response and add it to chat conversation
225-
response = get_ai_response(client, config, chat_conversation)
226+
response = get_ai_response(openai_client, config, chat_conversation)
226227
print(f"AI: {response}")
227228
chat_conversation.append({"role": "assistant", "content": response})
228229

0 commit comments

Comments
 (0)