File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,8 @@ def __init__(self) -> None:
52
52
class BaseAzureClient (BaseClient [_HttpxClientT , _DefaultStreamT ]):
53
53
_azure_endpoint : httpx .URL | None
54
54
_azure_deployment : str | None
55
+ # https://learn.microsoft.com/en-us/azure/ai-foundry/openai/api-version-lifecycle?tabs=entra#next-generation-api-1
56
+ _azure_next_supported_generation_api_version : list [str ] = ["preview" , "latest" ]
55
57
56
58
@override
57
59
def _build_request (
@@ -62,7 +64,7 @@ def _build_request(
62
64
) -> httpx .Request :
63
65
if options .url in _deployments_endpoints and is_mapping (options .json_data ):
64
66
model = options .json_data .get ("model" )
65
- if model is not None and "/deployments" not in str (self .base_url .path ):
67
+ if model is not None and self . _api_version not in self . _azure_next_supported_generation_api_version and "/deployments" not in str (self .base_url .path ): # pylint: disable=no-member
66
68
options .url = f"/deployments/{ model } { options .url } "
67
69
68
70
return super ()._build_request (options , retries_taken = retries_taken )
Original file line number Diff line number Diff line change @@ -802,3 +802,25 @@ def test_client_sets_base_url(client: Client) -> None:
802
802
)
803
803
)
804
804
assert req .url == "https://example-resource.azure.openai.com/openai/models?api-version=2024-02-01"
805
+
806
+ @pytest .mark .parametrize ("api_version" , ["preview" , "latest" ])
807
+ def test_client_sets_base_url_with_new_generation_api_version (api_version : str ) -> None :
808
+ client = AzureOpenAI (
809
+ api_version = api_version ,
810
+ api_key = "example API key" ,
811
+ base_url = "https://example-resource.azure.openai.com/openai/v1/"
812
+ )
813
+ assert client .base_url == "https://example-resource.azure.openai.com/openai/v1/"
814
+
815
+
816
+ req = client ._build_request (
817
+ FinalRequestOptions .construct (
818
+ method = "post" ,
819
+ url = "/chat/completions" ,
820
+ json_data = {"model" : "placeholder" },
821
+ )
822
+ )
823
+ assert (
824
+ req .url
825
+ == f"https://example-resource.azure.openai.com/openai/v1/chat/completions?api-version={ api_version } "
826
+ )
You can’t perform that action at this time.
0 commit comments