|
41 | 41 | def get_azure_ai_project_endpoint(): |
42 | 42 | """Get Azure AI Project endpoint from environment variables""" |
43 | 43 | azure_ai_endpoint = os.getenv('AZURE_AI_PROJECT_ENDPOINT') |
| 44 | + azure_ai_project_name = os.getenv('AZURE_AI_PROJECT_NAME') |
| 45 | + |
44 | 46 | if not azure_ai_endpoint: |
45 | 47 | raise ValueError("AZURE_AI_PROJECT_ENDPOINT environment variable is required") |
| 48 | + if not azure_ai_project_name: |
| 49 | + raise ValueError("AZURE_AI_PROJECT_NAME environment variable is required") |
46 | 50 |
|
47 | | - # Azure AI Foundry endpoint should be a direct URL |
48 | | - if azure_ai_endpoint.startswith('https://'): |
49 | | - return azure_ai_endpoint |
| 51 | + # Extract the AI Foundry resource name from the endpoint |
| 52 | + # Format: https://az-tda-foundry-wgznky2irncfe.cognitiveservices.azure.com/ |
| 53 | + if azure_ai_endpoint.startswith('https://') and 'cognitiveservices.azure.com' in azure_ai_endpoint: |
| 54 | + # Extract resource name from URL |
| 55 | + resource_name = azure_ai_endpoint.replace('https://', '').replace('.cognitiveservices.azure.com/', '').replace('.cognitiveservices.azure.com', '') |
| 56 | + # Format for Azure AI Agents: https://<resource-name>.services.ai.azure.com/api/projects/<project-name> |
| 57 | + agents_endpoint = f"https://{resource_name}.services.ai.azure.com/api/projects/{azure_ai_project_name}" |
| 58 | + return agents_endpoint |
50 | 59 |
|
51 | | - # Handle legacy Azure ML format if still present |
52 | | - if ';' in azure_ai_endpoint: |
53 | | - # Format: "westus.api.azureml.ms;subscription;resourcegroup;projectname" |
54 | | - parts = azure_ai_endpoint.split(';') |
55 | | - if len(parts) >= 4: |
56 | | - # Extract region from "westus.api.azureml.ms" |
57 | | - region = parts[0].split('.')[0] |
58 | | - project_name = parts[3] |
59 | | - return (f"https://{region}.api.azureml.ms/api/projects/" |
60 | | - f"{project_name}") |
| 60 | + # If already in correct format, return as-is |
| 61 | + if '/api/projects/' in azure_ai_endpoint: |
| 62 | + return azure_ai_endpoint |
61 | 63 |
|
62 | 64 | raise ValueError(f"Invalid AZURE_AI_PROJECT_ENDPOINT format: {azure_ai_endpoint}") |
63 | 65 |
|
|
0 commit comments