|
| 1 | +# -------------------------------------------------------------------------------------------- |
| 2 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | +# -------------------------------------------------------------------------------------------- |
| 5 | + |
| 6 | + |
| 7 | +from typing import Tuple |
| 8 | + |
| 9 | +from .base import LLMProvider, is_valid_url, non_empty |
| 10 | + |
| 11 | + |
| 12 | +def is_valid_api_base(v: str) -> bool: |
| 13 | + if not v.startswith("https://"): |
| 14 | + return False |
| 15 | + return is_valid_url(v) |
| 16 | + |
| 17 | + |
| 18 | +class AzureEntraIDProvider(LLMProvider): |
| 19 | + @property |
| 20 | + def readable_name(self) -> str: |
| 21 | + return "Azure OpenAI (Microsoft Entra ID)" |
| 22 | + |
| 23 | + @property |
| 24 | + def model_route(self) -> str: |
| 25 | + return "azure" |
| 26 | + |
| 27 | + @property |
| 28 | + def parameter_schema(self): |
| 29 | + return { |
| 30 | + "model": { |
| 31 | + "secret": False, |
| 32 | + "default": None, |
| 33 | + "hint": "ensure your deployment name is the same as the model name, e.g., gpt-5", |
| 34 | + "validator": non_empty, |
| 35 | + "alias": "deployment_name" |
| 36 | + }, |
| 37 | + "api_base": { |
| 38 | + "secret": False, |
| 39 | + "default": None, |
| 40 | + "validator": is_valid_api_base |
| 41 | + }, |
| 42 | + "api_version": { |
| 43 | + "secret": False, |
| 44 | + "default": "2025-04-01-preview", |
| 45 | + "hint": None, |
| 46 | + "validator": non_empty |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + def validate_connection(self, params: dict) -> Tuple[str, str]: |
| 51 | + api_base = params.get("api_base") |
| 52 | + api_version = params.get("api_version") |
| 53 | + deployment_name = params.get("model") |
| 54 | + |
| 55 | + if not all([api_base, api_version, deployment_name]): |
| 56 | + return "Missing required Azure parameters.", "retry_input" |
| 57 | + |
| 58 | + return None, "save" |
0 commit comments