diff --git a/examples/Python/ChatApp/app.py b/examples/Python/ChatApp/app.py index 7717f8a4..ae6bf1cd 100644 --- a/examples/Python/ChatApp/app.py +++ b/examples/Python/ChatApp/app.py @@ -12,7 +12,7 @@ import os from azure.identity import DefaultAzureCredential from azure.appconfiguration.provider import load, SettingSelector, WatchKey -from azure.ai.inference import ChatCompletionsClient +from azure.ai.projects import AIProjectClient from models import AzureAIFoundryConfiguration, ChatCompletionConfiguration APP_CONFIG_ENDPOINT_KEY = "AZURE_APPCONFIGURATION_ENDPOINT" @@ -44,7 +44,8 @@ def main(): azure_foundry_config = AzureAIFoundryConfiguration( endpoint=APPCONFIG.get("AzureAIFoundry:Endpoint", "") ) - chat_client = create_chat_client(azure_foundry_config) + project_client = create_project_client(azure_foundry_config) + openai_client = project_client.get_openai_client() chat_conversation = [] @@ -71,9 +72,10 @@ def main(): chat_messages.extend(chat_conversation) # Get AI response and add it to chat conversation - response = chat_client.complete( + response = openai_client.chat.completions.create( model=CHAT_COMPLETION_CONFIG.model, messages=chat_messages, + max_completion_tokens=CHAT_COMPLETION_CONFIG.max_completion_tokens, ) ai_response = response.choices[0].message.content @@ -90,14 +92,13 @@ def configure_app(): CHAT_COMPLETION_CONFIG = ChatCompletionConfiguration(**APPCONFIG["ChatCompletion"]) -def create_chat_client(config: AzureAIFoundryConfiguration) -> ChatCompletionsClient: +def create_project_client(config: AzureAIFoundryConfiguration) -> AIProjectClient: """ - Create a ChatCompletionsClient using the configuration from Azure App Configuration. + Create an AIProjectClient using the configuration from Azure App Configuration. """ - return ChatCompletionsClient( + return AIProjectClient( endpoint=config.endpoint, credential=CREDENTIAL, - credential_scopes=["https://cognitiveservices.azure.com/.default"], ) diff --git a/examples/Python/ChatApp/requirements.txt b/examples/Python/ChatApp/requirements.txt index cc67535d..c59da157 100644 --- a/examples/Python/ChatApp/requirements.txt +++ b/examples/Python/ChatApp/requirements.txt @@ -1,3 +1,3 @@ azure-identity azure-appconfiguration-provider<3.0.0 -azure-ai-inference +azure-ai-projects>=2.0.0