1515from azure .search .documents import SearchClient
1616from azure .search .documents .indexes import SearchIndexClient
1717from azure .storage .filedatalake import DataLakeServiceClient
18- # Removed: from openai import AzureOpenAI (migrated to Azure AI Foundry)
18+ # Removed:
1919from azure .ai .projects import AIProjectClient
2020from content_understanding_client import AzureContentUnderstandingClient
2121from azure_credential_utils import get_azure_credential
@@ -62,7 +62,7 @@ def __init__(self, endpoint: str, credential, project_name: str):
6262
6363 def _get_headers (self ) -> Dict [str , str ]:
6464 """Get authorization headers for API calls."""
65- token = self .credential .get_token ('https://ml .azure.com/.default' ).token
65+ token = self .credential .get_token ('https://ai .azure.com/.default' ).token
6666 return {
6767 'Authorization' : f'Bearer { token } ' ,
6868 'Content-Type' : 'application/json'
@@ -191,17 +191,17 @@ def create_ai_foundry_client():
191191 try :
192192 credential = get_azure_credential (client_id = MANAGED_IDENTITY_CLIENT_ID )
193193
194- # Extract subscription ID and resource group from AI Foundry endpoint or use defaults
194+ # Extract subscription ID and resource group from environment or use defaults
195195 subscription_id = os .getenv ("AZURE_SUBSCRIPTION_ID" ) or "1d5876cd-7603-407a-96d2-ae5ca9a9c5f3"
196196 resource_group_name = os .getenv ("AZURE_RESOURCE_GROUP" ) or "rg-kmgensdkR041"
197197
198198 # Create the base project client with required parameters
199199 project_client = AIProjectClient (
200200 endpoint = ai_foundry_endpoint ,
201- credential = credential ,
202- project_name = ai_foundry_project_name ,
203- subscription_id = subscription_id ,
204- resource_group_name = resource_group_name
201+ credential = credential ,
202+ subscription_id = subscription_id ,
203+ resource_group_name = resource_group_name ,
204+ project_name = ai_foundry_project_name
205205 )
206206
207207 # Add our custom assistants wrapper to bypass the broken agents interface
@@ -226,24 +226,20 @@ def get_embeddings(text: str, ai_foundry_endpoint=None, ai_foundry_project=None)
226226 from azure .ai .inference import EmbeddingsClient
227227 from azure .identity import get_bearer_token_provider
228228
229- # Use the AI Foundry endpoint for embeddings
230- endpoint = ai_foundry_endpoint or ai_foundry_endpoint
229+ # Use the global AI Foundry endpoint for embeddings
230+ endpoint = ai_foundry_endpoint or globals (). get ( ' ai_foundry_endpoint' )
231231 model_id = "text-embedding-3-small" # Updated to newer model
232232
233233 credential = get_azure_credential (client_id = MANAGED_IDENTITY_CLIENT_ID )
234234
235235 # Create token provider with correct scope for Azure AI services
236236 token_provider = get_bearer_token_provider (credential , "https://ai.azure.com/.default" )
237237
238- # Create AI Foundry EmbeddingsClient with token provider
239- client = EmbeddingsClient (
240- endpoint = f"{ endpoint } /models" ,
241- token_provider = token_provider ,
242- model = model_id
243- )
238+ # Create AI Foundry EmbeddingsClient with credential (not token provider)
239+ client = EmbeddingsClient (endpoint = endpoint , credential = credential )
244240
245241 # Generate embedding using AI Foundry
246- response = client .embed (input = [text ])
242+ response = client .embed (input = [text ], model = model_id )
247243 embedding = response .data [0 ].embedding
248244
249245 logger .info ("Successfully generated embedding using Azure AI Foundry" )
@@ -636,7 +632,9 @@ def get_mined_topic_mapping(input_text, list_of_topics):
636632 credential = DefaultAzureCredential ()
637633 ai_project_client = AIProjectClient (
638634 endpoint = ai_foundry_endpoint ,
639- credential = credential ,
635+ credential = credential ,
636+ subscription_id = os .getenv ('AZURE_SUBSCRIPTION_ID' ),
637+ resource_group_name = os .getenv ('AZURE_RESOURCE_GROUP' ),
640638 project_name = ai_foundry_project_name
641639 )
642640 logger .info ("✅ Azure AI Foundry client initialized successfully." )
0 commit comments