mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-11 08:38:24 +00:00
fix(responses): drop metadata from compact requests to OpenAI and Azure
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
ee6ca049b3
commit
dce01d84c5
2 changed files with 46 additions and 1 deletions
|
|
@ -63,6 +63,7 @@ _PROVIDERS_VALIDATING_TOOL_CALL_ITEM_IDS: Final = frozenset({LlmProviders.AZURE,
|
|||
_PROVIDERS_REPLAYING_ONLY_THEIR_OWN_REASONING: Final = _PROVIDERS_VALIDATING_TOOL_CALL_ITEM_IDS
|
||||
_ROLES_READING_PROMPT_CACHE_BREAKPOINTS: Final = frozenset({"system", "developer", "user"})
|
||||
_PART_TYPES_READING_PROMPT_CACHE_BREAKPOINTS: Final = frozenset({"input_text", "input_image", "input_file"})
|
||||
_COMPACT_UNSUPPORTED_PARAMS: Final = frozenset({"metadata"})
|
||||
_INPUT_ITEM: Final[TypeAdapter[Mapping[str, object]]] = TypeAdapter(Mapping[str, object])
|
||||
_CONTENT_PARTS: Final[TypeAdapter[Sequence[Mapping[str, object]]]] = TypeAdapter(Sequence[Mapping[str, object]])
|
||||
|
||||
|
|
@ -1163,7 +1164,14 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):
|
|||
if sanitized_tools is not None:
|
||||
response_api_optional_request_params["tools"] = sanitized_tools
|
||||
data: Final = dict(
|
||||
ResponsesAPIRequestParams(model=model, input=replay_safe_input, **response_api_optional_request_params)
|
||||
ResponsesAPIRequestParams(
|
||||
model=model,
|
||||
input=replay_safe_input,
|
||||
**cast( # cast-ok: the inherited base signature leaves caller parameters untyped
|
||||
"ResponsesAPIOptionalRequestParams",
|
||||
{key: value for key, value in request_params.items() if key not in _COMPACT_UNSUPPORTED_PARAMS},
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
return url, data
|
||||
|
|
|
|||
|
|
@ -1630,6 +1630,43 @@ class TestTransformListInputItemsRequest:
|
|||
assert data["model"] == "gpt-4o"
|
||||
assert data["input"] == "hello"
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("config", "api_base"),
|
||||
[
|
||||
pytest.param(
|
||||
OpenAIResponsesAPIConfig(),
|
||||
"https://api.openai.com/v1/responses",
|
||||
id="openai",
|
||||
),
|
||||
pytest.param(
|
||||
AzureOpenAIResponsesAPIConfig(),
|
||||
"https://x.openai.azure.com/openai/v1/responses?api-version=preview",
|
||||
id="azure",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_compact_response_request_omits_metadata(
|
||||
self,
|
||||
config: OpenAIResponsesAPIConfig | AzureOpenAIResponsesAPIConfig,
|
||||
api_base: str,
|
||||
) -> None:
|
||||
_, data = config.transform_compact_response_api_request(
|
||||
model="gpt-5-mini",
|
||||
input="hi",
|
||||
response_api_optional_request_params={
|
||||
"metadata": {"a": "b"},
|
||||
"instructions": "be brief",
|
||||
"previous_response_id": "resp_1",
|
||||
},
|
||||
api_base=api_base,
|
||||
litellm_params=GenericLiteLLMParams(),
|
||||
headers={},
|
||||
)
|
||||
|
||||
assert "metadata" not in data
|
||||
assert data["instructions"] == "be brief"
|
||||
assert data["previous_response_id"] == "resp_1"
|
||||
|
||||
def test_azure_transform_list_input_items_request_minimal(self):
|
||||
"""Test Azure implementation with minimal parameters"""
|
||||
# Setup
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue