From 2aafbe390b80748edbd67e31935af17375a21dc2 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 8 Mar 2024 13:16:12 -0800 Subject: [PATCH 1/4] (feat) read passed api_version --- litellm/proxy/proxy_server.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 19ac5c96118..d9642b81037 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -2670,6 +2670,11 @@ async def chat_completion( except: data = json.loads(body_str) + # Azure OpenAI only: check if user passed api-version + query_params = dict(request.query_params) + if "api-version" in query_params: + data["api_version"] = query_params["api-version"] + # Include original request and headers in the data data["proxy_server_request"] = { "url": str(request.url), From d67c63b0c3f13215b91e5c0fa9719b1e97ac8427 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 8 Mar 2024 13:33:58 -0800 Subject: [PATCH 2/4] (fix) use azure api_version --- litellm/llms/azure.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/litellm/llms/azure.py b/litellm/llms/azure.py index 01b54987b2d..6a0c1ec1fbb 100644 --- a/litellm/llms/azure.py +++ b/litellm/llms/azure.py @@ -333,10 +333,17 @@ class AzureChatCompletion(BaseLLM): azure_client_params["api_key"] = api_key elif azure_ad_token is not None: azure_client_params["azure_ad_token"] = azure_ad_token + + # setting Azure client if client is None: azure_client = AsyncAzureOpenAI(**azure_client_params) else: azure_client = client + if api_version is not None and isinstance( + azure_client._custom_query, dict + ): + # set api_version to version passed by user + azure_client._custom_query.setdefault("api-version", api_version) ## LOGGING logging_obj.pre_call( input=data["messages"], From 2f6e15655a093777b912e59f92ee78a3cfc6acc6 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 8 Mar 2024 13:38:29 -0800 Subject: [PATCH 3/4] (feat) set api_version for Azure --- litellm/llms/azure.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/litellm/llms/azure.py b/litellm/llms/azure.py index 6a0c1ec1fbb..9f5b04a0413 100644 --- a/litellm/llms/azure.py +++ b/litellm/llms/azure.py @@ -270,6 +270,14 @@ class AzureChatCompletion(BaseLLM): azure_client = AzureOpenAI(**azure_client_params) else: azure_client = client + if api_version is not None and isinstance( + azure_client._custom_query, dict + ): + # set api_version to version passed by user + azure_client._custom_query.setdefault( + "api-version", api_version + ) + response = azure_client.chat.completions.create(**data, timeout=timeout) # type: ignore stringified_response = response.model_dump() ## LOGGING @@ -408,6 +416,10 @@ class AzureChatCompletion(BaseLLM): azure_client = AzureOpenAI(**azure_client_params) else: azure_client = client + azure_client = client + if api_version is not None and isinstance(azure_client._custom_query, dict): + # set api_version to version passed by user + azure_client._custom_query.setdefault("api-version", api_version) ## LOGGING logging_obj.pre_call( input=data["messages"], @@ -461,6 +473,11 @@ class AzureChatCompletion(BaseLLM): azure_client = AsyncAzureOpenAI(**azure_client_params) else: azure_client = client + if api_version is not None and isinstance( + azure_client._custom_query, dict + ): + # set api_version to version passed by user + azure_client._custom_query.setdefault("api-version", api_version) ## LOGGING logging_obj.pre_call( input=data["messages"], From 65ccfc35ca5b5de0386b4fd6b432d1c351b7d4e5 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 8 Mar 2024 13:44:39 -0800 Subject: [PATCH 4/4] (fix) azure extra setting client --- litellm/llms/azure.py | 1 - 1 file changed, 1 deletion(-) diff --git a/litellm/llms/azure.py b/litellm/llms/azure.py index 9f5b04a0413..0f678690277 100644 --- a/litellm/llms/azure.py +++ b/litellm/llms/azure.py @@ -415,7 +415,6 @@ class AzureChatCompletion(BaseLLM): if client is None: azure_client = AzureOpenAI(**azure_client_params) else: - azure_client = client azure_client = client if api_version is not None and isinstance(azure_client._custom_query, dict): # set api_version to version passed by user