mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-19 00:01:29 +00:00
test fixing azure
This commit is contained in:
parent
a3f6cbf6bb
commit
1872906e6c
2 changed files with 27 additions and 7 deletions
|
|
@ -133,14 +133,32 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
response_api_optional_request_params["tools"] = new_tools
|
||||
|
||||
# Azure Responses API expects context_management as an object with "strategies" key,
|
||||
# but OpenAI/litellm uses array format [{"type": "compaction", "compact_threshold": N}].
|
||||
# See: "Invalid type for 'context_management': expected an object, but got an array instead."
|
||||
# See: "Missing required parameter: 'context_management.strategies'."
|
||||
# and strategy items use "token_threshold" (not OpenAI's "compact_threshold").
|
||||
# Inferred from Azure error messages; OpenAI uses array + compact_threshold.
|
||||
# Ref: https://learn.microsoft.com/azure/ai-foundry/openai/reference
|
||||
if "context_management" in response_api_optional_request_params:
|
||||
cm = response_api_optional_request_params["context_management"]
|
||||
|
||||
def _normalize_strategy(item: Any) -> Dict[str, Any]:
|
||||
if isinstance(item, dict):
|
||||
strategy = dict(item)
|
||||
if "compact_threshold" in strategy:
|
||||
strategy["token_threshold"] = strategy.pop(
|
||||
"compact_threshold"
|
||||
)
|
||||
return strategy
|
||||
return item # type: ignore
|
||||
|
||||
if isinstance(cm, list):
|
||||
strategies = [_normalize_strategy(item) for item in cm]
|
||||
response_api_optional_request_params["context_management"] = {
|
||||
"strategies": cm
|
||||
"strategies": strategies
|
||||
}
|
||||
elif isinstance(cm, dict) and "strategies" in cm:
|
||||
strategies = [_normalize_strategy(s) for s in cm["strategies"]]
|
||||
response_api_optional_request_params["context_management"] = {
|
||||
**cm,
|
||||
"strategies": strategies,
|
||||
}
|
||||
|
||||
return super().transform_responses_api_request(
|
||||
|
|
|
|||
|
|
@ -517,11 +517,11 @@ class TestAzureResponsesAPIConfig:
|
|||
|
||||
assert "context_management" in result
|
||||
assert result["context_management"] == {
|
||||
"strategies": [{"type": "compaction", "compact_threshold": 200000}]
|
||||
"strategies": [{"type": "compaction", "token_threshold": 200000}]
|
||||
}
|
||||
|
||||
def test_azure_responses_api_context_management_already_object(self):
|
||||
"""Test that context_management already in object format is passed through."""
|
||||
"""Test that context_management in object format has compact_threshold mapped to token_threshold."""
|
||||
from litellm.types.router import GenericLiteLLMParams
|
||||
|
||||
context_management = {"strategies": [{"type": "compaction", "compact_threshold": 200000}]}
|
||||
|
|
@ -536,4 +536,6 @@ class TestAzureResponsesAPIConfig:
|
|||
headers={},
|
||||
)
|
||||
|
||||
assert result["context_management"] == context_management
|
||||
assert result["context_management"] == {
|
||||
"strategies": [{"type": "compaction", "token_threshold": 200000}]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue