mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
fix(azure): honor base_url client param and drop stale api-version on v1 image routes
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
5802cf0d8d
commit
1cf683c980
4 changed files with 24 additions and 7 deletions
|
|
@ -1091,9 +1091,10 @@ class AzureChatCompletion(BaseAzureLLM, BaseLLM):
|
|||
AzureFoundryMAIImageGenerationConfig,
|
||||
)
|
||||
|
||||
api_base: str = azure_client_params.get("azure_endpoint", "") # "https://example-endpoint.openai.azure.com"
|
||||
if api_base.endswith("/"):
|
||||
api_base = api_base.rstrip("/")
|
||||
# deployment-scoped endpoints are moved to "base_url" by select_azure_base_url_or_endpoint
|
||||
api_base: str = (azure_client_params.get("azure_endpoint") or azure_client_params.get("base_url") or "").rstrip(
|
||||
"/"
|
||||
)
|
||||
api_version: Final[str] = azure_client_params.get("api_version", "")
|
||||
if model is None:
|
||||
model = ""
|
||||
|
|
|
|||
|
|
@ -794,7 +794,8 @@ class BaseAzureLLM(BaseOpenAILLM):
|
|||
def get_azure_v1_image_url(api_base: str, api_version: str | None, route: str) -> str | None:
|
||||
"""
|
||||
Azure's v1 surface serves images at ``/openai/v1/images/{generations,edits}`` and routes by
|
||||
``model`` in the request body, so any deployment path in ``api_base`` has to be dropped.
|
||||
``model`` in the request body, so any deployment path and stale ``api-version`` in
|
||||
``api_base`` have to be dropped.
|
||||
|
||||
Returns None when ``api_version`` is a dated one, which still uses the deployment route.
|
||||
"""
|
||||
|
|
@ -803,8 +804,11 @@ class BaseAzureLLM(BaseOpenAILLM):
|
|||
|
||||
base_url: Final = httpx.URL(api_base)
|
||||
openai_path_start: Final = base_url.path.find("/openai")
|
||||
resource_base: Final = (
|
||||
api_base if openai_path_start == -1 else str(base_url.copy_with(path=base_url.path[:openai_path_start]))
|
||||
resource_base: Final = str(
|
||||
base_url.copy_with(
|
||||
path=base_url.path if openai_path_start == -1 else base_url.path[:openai_path_start],
|
||||
params=httpx.QueryParams({k: v for k, v in base_url.params.items() if k != "api-version"}),
|
||||
)
|
||||
)
|
||||
return BaseAzureLLM._get_base_azure_url(
|
||||
api_base=resource_base,
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ def test_v1_api_version_replaces_deployment_scoped_api_base(monkeypatch):
|
|||
|
||||
url = AzureImageEditConfig().get_complete_url(
|
||||
model=_FALLBACK_MODEL,
|
||||
api_base=f"{_FALLBACK_API_BASE}/openai/deployments/{_FALLBACK_MODEL}/images/edits",
|
||||
api_base=f"{_FALLBACK_API_BASE}/openai/deployments/{_FALLBACK_MODEL}/images/edits?api-version=2024-10-21",
|
||||
litellm_params={"api_version": "preview"},
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -477,3 +477,15 @@ def test_azure_image_generation_v1_api_version_replaces_deployment_scoped_api_ba
|
|||
base_model=None,
|
||||
)
|
||||
assert url == "https://my-resource.openai.azure.com/openai/v1/images/generations?api-version=preview"
|
||||
|
||||
|
||||
def test_azure_image_generation_v1_api_version_uses_base_url_client_param():
|
||||
url = AzureChatCompletion().create_azure_base_url(
|
||||
azure_client_params={
|
||||
"base_url": "https://my-resource.openai.azure.com/openai/deployments/gpt-image-1?api-version=2024-10-21",
|
||||
"api_version": "preview",
|
||||
},
|
||||
model="gpt-image-1",
|
||||
base_model=None,
|
||||
)
|
||||
assert url == "https://my-resource.openai.azure.com/openai/v1/images/generations?api-version=preview"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue