Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions examples/Python/ChatApp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 = []

Expand All @@ -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
Expand All @@ -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"],
)


Expand Down
2 changes: 1 addition & 1 deletion examples/Python/ChatApp/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
azure-identity
azure-appconfiguration-provider<3.0.0
azure-ai-inference
azure-ai-projects>=2.0.0
Loading