55from datetime import datetime , timezone
66from typing import Any , Dict , List , Optional , Tuple
77
8- import aiohttp
98from azure .core .credentials import AzureKeyCredential
109from azure .core .exceptions import (
1110 ClientAuthenticationError ,
2423
2524from common .config .app_config import config
2625from common .database .database_base import DatabaseBase
26+ from v3 .common .services .foundry_service import FoundryService
2727
2828
2929class TeamService :
@@ -39,12 +39,6 @@ def __init__(self, memory_context: Optional[DatabaseBase] = None):
3939
4040 self .search_credential = config .get_azure_credentials ()
4141
42- # Model validation configuration
43- self .subscription_id = config .AZURE_AI_SUBSCRIPTION_ID
44- self .resource_group = config .AZURE_AI_RESOURCE_GROUP
45- self .project_name = config .AZURE_AI_PROJECT_NAME
46- self .project_endpoint = config .AZURE_AI_PROJECT_ENDPOINT
47-
4842 async def validate_and_parse_team_config (
4943 self , json_data : Dict [str , Any ], user_id : str
5044 ) -> TeamConfiguration :
@@ -279,65 +273,6 @@ async def delete_team_configuration(self, team_id: str, user_id: str) -> bool:
279273 self .logger .error ("Error deleting team configuration: %s" , str (e ))
280274 return False
281275
282- # -----------------------
283- # Model validation methods
284- # -----------------------
285-
286- async def list_model_deployments (self ) -> List [Dict [str , Any ]]:
287- """
288- List all model deployments in the Azure AI project using the REST API.
289- """
290- if not all ([self .subscription_id , self .resource_group , self .project_name ]):
291- self .logger .error ("Azure AI project configuration is incomplete" )
292- return []
293-
294- try :
295- token = await config .get_access_token ()
296-
297- url = (
298- f"https://management.azure.com/subscriptions/{ self .subscription_id } /"
299- f"resourceGroups/{ self .resource_group } /providers/Microsoft.MachineLearningServices/"
300- f"workspaces/{ self .project_name } /onlineEndpoints"
301- )
302-
303- headers = {
304- "Authorization" : f"Bearer { token } " ,
305- "Content-Type" : "application/json" ,
306- }
307- params = {"api-version" : "2024-10-01" }
308-
309- async with aiohttp .ClientSession () as session :
310- async with session .get (url , headers = headers , params = params ) as response :
311- if response .status == 200 :
312- data = await response .json ()
313- deployments = data .get ("value" , [])
314- deployment_info : List [Dict [str , Any ]] = []
315- for deployment in deployments :
316- deployment_info .append (
317- {
318- "name" : deployment .get ("name" ),
319- "model" : deployment .get ("properties" , {}).get (
320- "model" , {}
321- ),
322- "status" : deployment .get ("properties" , {}).get (
323- "provisioningState"
324- ),
325- "endpoint_uri" : deployment .get (
326- "properties" , {}
327- ).get ("scoringUri" ),
328- }
329- )
330- return deployment_info
331- else :
332- error_text = await response .text ()
333- self .logger .error (
334- f"Failed to list deployments. Status: { response .status } , Error: { error_text } "
335- )
336- return []
337- except Exception as e :
338- self .logger .error (f"Error listing model deployments: { e } " )
339- return []
340-
341276 def extract_models_from_agent (self , agent : Dict [str , Any ]) -> set :
342277 """
343278 Extract all possible model references from a single agent configuration.
@@ -397,7 +332,8 @@ async def validate_team_models(
397332 ) -> Tuple [bool , List [str ]]:
398333 """Validate that all models required by agents in the team config are deployed."""
399334 try :
400- deployments = await self .list_model_deployments ()
335+ foundry_service = FoundryService ()
336+ deployments = await foundry_service .list_model_deployments ()
401337 available_models = [
402338 d .get ("name" , "" ).lower ()
403339 for d in deployments
@@ -434,7 +370,8 @@ async def validate_team_models(
434370 async def get_deployment_status_summary (self ) -> Dict [str , Any ]:
435371 """Get a summary of deployment status for debugging/monitoring."""
436372 try :
437- deployments = await self .list_model_deployments ()
373+ foundry_service = FoundryService ()
374+ deployments = await foundry_service .list_model_deployments ()
438375 summary : Dict [str , Any ] = {
439376 "total_deployments" : len (deployments ),
440377 "successful_deployments" : [],
0 commit comments