1212import os
1313from azure .identity import DefaultAzureCredential
1414from azure .appconfiguration .provider import load , SettingSelector , WatchKey
15- from azure .ai .inference import ChatCompletionsClient
15+ from azure .ai .projects import AIProjectClient
1616from models import AzureAIFoundryConfiguration , ChatCompletionConfiguration
1717
1818APP_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
0 commit comments