fix(azure-anthropic): satisfy type gates

This commit is contained in:
Soukyu 2026-10-16 00:42:47 +07:00
parent eb979f7fb3
commit 54c3710d9f
2 changed files with 24 additions and 32 deletions

View file

@ -115,24 +115,26 @@ class AzureAnthropicConfig(AnthropicConfig):
self,
model: str,
messages: list[AllMessageValues],
optional_params: dict[str, object],
litellm_params: dict[str, object],
headers: dict[str, object],
) -> dict[str, object]:
optional_params: dict,
litellm_params: dict,
headers: dict,
) -> dict:
"""
Transform request using parent AnthropicConfig, then remove unsupported params.
Azure Anthropic doesn't support extra_body, max_retries, or stream_options parameters.
"""
_promote_extra_body_to_optional_params(optional_params)
data: Final[dict[str, object]] = {
**super().transform_request(
model=model,
messages=messages,
optional_params=optional_params,
litellm_params=litellm_params,
headers=headers,
)
}
data: Final = super().transform_request(
model=model,
messages=messages,
optional_params=optional_params,
litellm_params=litellm_params,
headers=headers,
)
return {key: value for key, value in data.items() if key not in _AZURE_ANTHROPIC_NON_BODY_PARAMS}
return {
key: value
for key, value in data.items() # pyright: ignore[reportUnknownVariableType] # Anthropic base returns a bare request dict
if key not in _AZURE_ANTHROPIC_NON_BODY_PARAMS
}

View file

@ -71,9 +71,9 @@ class TestCredentialLiteLLMParamsAzureAdToken:
"azure_ad_token": "tok-123",
"api_key": None, # M2M deployment has no static key
}
rebuilt = CredentialLiteLLMParams(
**{k: v for k, v in source.items() if v is not None}
).model_dump(exclude_none=True)
rebuilt = CredentialLiteLLMParams(**{k: v for k, v in source.items() if v is not None}).model_dump(
exclude_none=True
)
assert rebuilt.get("azure_ad_token") == "tok-123"
assert rebuilt.get("api_base") == "https://my.openai.azure.com"
assert "api_key" not in rebuilt
@ -103,9 +103,7 @@ class TestRouterCredentialResolution:
]
)
credentials = router.get_deployment_credentials_with_provider(
model_id=deployment_id
)
credentials = router.get_deployment_credentials_with_provider(model_id=deployment_id)
assert credentials is not None
assert credentials.get("azure_ad_token") == "tok-azure-m2m-xyz", (
"Router credential resolution dropped azure_ad_token; the "
@ -135,9 +133,7 @@ class TestRouterCredentialResolution:
]
)
credentials = router.get_deployment_credentials_with_provider(
model_id=deployment_id
)
credentials = router.get_deployment_credentials_with_provider(model_id=deployment_id)
assert credentials is not None
assert credentials.get("api_key") == "sk-static-key"
assert "azure_ad_token" not in credentials
@ -172,9 +168,7 @@ class TestRouterCredentialResolutionS3OutputBucket:
]
)
credentials = router.get_deployment_credentials_with_provider(
model_id=deployment_id
)
credentials = router.get_deployment_credentials_with_provider(model_id=deployment_id)
assert credentials is not None
assert credentials.get("s3_output_bucket_name") == "out-bucket", (
"Router credential resolution dropped s3_output_bucket_name; "
@ -203,9 +197,7 @@ class TestRouterCredentialResolutionS3OutputBucket:
]
)
credentials = router.get_deployment_credentials_with_provider(
model_id=deployment_id
)
credentials = router.get_deployment_credentials_with_provider(model_id=deployment_id)
assert credentials is not None
assert credentials.get("s3_bucket_name") == "in-bucket"
assert "s3_output_bucket_name" not in credentials
@ -227,9 +219,7 @@ def test_azure_anthropic_request_body_does_not_include_azure_credentials() -> No
}
output_config: Final[dict[str, dict[str, str]]] = {"format": {"type": "json_object"}}
extra_body_params: Final[dict[str, str]] = {
key: value
for key, value in credential_params.items()
if key not in {"api_key", "azure_ad_token"}
key: value for key, value in credential_params.items() if key not in {"api_key", "azure_ad_token"}
}
body: Final[dict[str, object]] = AzureAnthropicConfig().transform_request(
model="claude-3-5-sonnet-20241022",