Skip to content

Commit 1afc38c

Browse files
authored
Python chat app update (#1140)
* Updating Chat App * Update app.py * switching to the 2.0.0 release * Update app.py
1 parent 901674e commit 1afc38c

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

examples/Python/ChatApp/app.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import os
1313
from azure.identity import DefaultAzureCredential
1414
from azure.appconfiguration.provider import load, SettingSelector, WatchKey
15-
from azure.ai.inference import ChatCompletionsClient
15+
from azure.ai.projects import AIProjectClient
1616
from models import AzureAIFoundryConfiguration, ChatCompletionConfiguration
1717

1818
APP_CONFIG_ENDPOINT_KEY = "AZURE_APPCONFIGURATION_ENDPOINT"
@@ -44,7 +44,8 @@ def main():
4444
azure_foundry_config = AzureAIFoundryConfiguration(
4545
endpoint=APPCONFIG.get("AzureAIFoundry:Endpoint", "")
4646
)
47-
chat_client = create_chat_client(azure_foundry_config)
47+
project_client = create_project_client(azure_foundry_config)
48+
openai_client = project_client.get_openai_client()
4849

4950
chat_conversation = []
5051

@@ -71,9 +72,10 @@ def main():
7172
chat_messages.extend(chat_conversation)
7273

7374
# Get AI response and add it to chat conversation
74-
response = chat_client.complete(
75+
response = openai_client.chat.completions.create(
7576
model=CHAT_COMPLETION_CONFIG.model,
7677
messages=chat_messages,
78+
max_completion_tokens=CHAT_COMPLETION_CONFIG.max_completion_tokens,
7779
)
7880

7981
ai_response = response.choices[0].message.content
@@ -90,14 +92,13 @@ def configure_app():
9092
CHAT_COMPLETION_CONFIG = ChatCompletionConfiguration(**APPCONFIG["ChatCompletion"])
9193

9294

93-
def create_chat_client(config: AzureAIFoundryConfiguration) -> ChatCompletionsClient:
95+
def create_project_client(config: AzureAIFoundryConfiguration) -> AIProjectClient:
9496
"""
95-
Create a ChatCompletionsClient using the configuration from Azure App Configuration.
97+
Create an AIProjectClient using the configuration from Azure App Configuration.
9698
"""
97-
return ChatCompletionsClient(
99+
return AIProjectClient(
98100
endpoint=config.endpoint,
99101
credential=CREDENTIAL,
100-
credential_scopes=["https://cognitiveservices.azure.com/.default"],
101102
)
102103

103104

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
azure-identity
22
azure-appconfiguration-provider<3.0.0
3-
azure-ai-inference
3+
azure-ai-projects>=2.0.0

0 commit comments

Comments
 (0)