mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
fix(azure_ai): keep a deployment named like the first native path segment in the relayed URL
This commit is contained in:
parent
a25eccafc9
commit
8627576c9c
2 changed files with 19 additions and 0 deletions
|
|
@ -62,6 +62,10 @@ def foundry_root(api_base: str) -> str:
|
|||
return str(url.copy_with(path="/" + "/".join(root_segments), query=None)).rstrip("/")
|
||||
|
||||
|
||||
def is_repeated_native_prefix(native_segments: tuple[str, ...], overlap: int) -> bool:
|
||||
return overlap == len(native_segments) or native_segments[0] == "openai"
|
||||
|
||||
|
||||
def without_repeated_native_prefix(root: str, native_endpoint: str) -> str:
|
||||
url: Final = httpx.URL(root)
|
||||
root_segments: Final = tuple(segment for segment in url.path.split("/") if segment)
|
||||
|
|
@ -71,6 +75,7 @@ def without_repeated_native_prefix(root: str, native_endpoint: str) -> str:
|
|||
length
|
||||
for length in range(min(len(root_segments), len(native_segments)), 0, -1)
|
||||
if tuple(segment.casefold() for segment in root_segments[-length:]) == native_segments[:length]
|
||||
and is_repeated_native_prefix(native_segments, length)
|
||||
),
|
||||
0,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -153,6 +153,20 @@ def test_deployment_root_api_base_is_not_repeated_when_the_relay_carries_the_dep
|
|||
assert base == "https://my-resource.openai.azure.com"
|
||||
|
||||
|
||||
def test_deployment_named_like_the_first_native_segment_keeps_its_deployment_root():
|
||||
url, base = AzureAIPassthroughConfig().get_complete_url(
|
||||
api_base="https://my-resource.openai.azure.com/openai/deployments/chat",
|
||||
api_key="key",
|
||||
model="chat",
|
||||
endpoint="aoai-chat/chat/completions",
|
||||
request_query_params={"api-version": "2024-10-21"},
|
||||
litellm_params={"litellm_metadata": {"model_group": "aoai-chat"}},
|
||||
)
|
||||
|
||||
assert str(url) == "https://my-resource.openai.azure.com/openai/deployments/chat/chat/completions?api-version=2024-10-21"
|
||||
assert base == "https://my-resource.openai.azure.com/openai/deployments/chat"
|
||||
|
||||
|
||||
def test_parse_relay_under_a_models_api_base_targets_the_foundry_root():
|
||||
url, _ = AzureAIPassthroughConfig().get_complete_url(
|
||||
api_base=f"{FOUNDRY_BASE}/models",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue