22import uuid
33from typing import Optional
44from fastapi import HTTPException , status
5- # from openai import AsyncAzureOpenAI # Commented out - replaced with Foundry SDK
65from azure .ai .projects import AIProjectClient
76from azure .ai .agents .models import MessageRole , ListSortOrder
87from common .config .config import Config
@@ -31,11 +30,9 @@ def __init__(self):
3130 and self .azure_cosmosdb_conversations_container
3231 )
3332
34- # OpenAI configuration (partially commented out - now using Foundry SDK)
35- # self.azure_openai_endpoint = config.azure_openai_endpoint # Not needed for Foundry SDK
36- # self.azure_openai_api_version = config.azure_openai_api_version # Not needed for Foundry SDK
37- self .azure_openai_deployment_name = config .azure_openai_deployment_model # Still needed for Foundry SDK model parameter
38- # self.azure_openai_resource = config.azure_openai_resource # Not needed for Foundry SDK
33+
34+ self .azure_openai_deployment_name = config .azure_openai_deployment_model
35+
3936 self .azure_client_id = config .azure_client_id
4037
4138 # AI Project configuration for Foundry SDK
@@ -62,47 +59,8 @@ def init_cosmosdb_client(self):
6259 logger .exception ("Failed to initialize CosmosDB client" )
6360 raise
6461
65- # def init_openai_client(self):
66- # """
67- # COMMENTED OUT - Replaced with Foundry SDK in generate_title method
68- # This method was used for direct OpenAI API calls, but we now use
69- # Azure AI Foundry SDK with AIProjectClient for title generation
70- # """
71- # user_agent = "GitHubSampleWebApp/AsyncAzureOpenAI/1.0.0"
72- #
73- # try:
74- # if not self.azure_openai_endpoint and not self.azure_openai_resource:
75- # raise ValueError(
76- # "AZURE_OPENAI_ENDPOINT or AZURE_OPENAI_RESOURCE is required")
77- #
78- # endpoint = self.azure_openai_endpoint or f"https://{self.azure_openai_resource}.openai.azure.com/"
79- # ad_token_provider = None
80- #
81- # logger.debug("Using Azure AD authentication for OpenAI")
82- # ad_token_provider = get_bearer_token_provider(
83- # get_azure_credential(client_id=self.azure_client_id), "https://cognitiveservices.azure.com/.default")
84- #
85- # if not self.azure_openai_deployment_name:
86- # raise ValueError("AZURE_OPENAI_MODEL is required")
87- #
88- # return AsyncAzureOpenAI(
89- # api_version=self.azure_openai_api_version,
90- # azure_ad_token_provider=ad_token_provider,
91- # default_headers={"x-ms-useragent": user_agent},
92- # azure_endpoint=endpoint,
93- # )
94- # except Exception:
95- # logger.exception("Failed to initialize Azure OpenAI client")
96- # raise
9762
9863 async def generate_title (self , conversation_messages ):
99- """
100- Generate a conversation title using Azure AI Foundry SDK.
101-
102- This method has been migrated from direct OpenAI API calls to use
103- Azure AI Foundry SDK with AIProjectClient for better resource management
104- and integration with Azure AI services.
105- """
10664 title_prompt = (
10765 "Summarize the conversation so far into a 4-word or less title. "
10866 "Do not use any quotation marks or punctuation. "
0 commit comments