mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
fix(responses/): filter metadata to be openai-compatible
prevents optional params for responses api from including invalid args / litellm internal information Closes https://github.com/BerriAI/litellm/pull/11632#issuecomment-2971076684
This commit is contained in:
parent
0e10e73f31
commit
eb272f0784
3 changed files with 19 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
"""
|
||||
Handler for transforming /chat/completions api requests to litellm.responses requests
|
||||
"""
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Coroutine, TypedDict, Union
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -163,6 +164,7 @@ class ResponsesToCompletionBridgeHandler:
|
|||
headers=headers,
|
||||
litellm_logging_obj=logging_obj,
|
||||
)
|
||||
|
||||
result = await aresponses(
|
||||
**request_data,
|
||||
aresponses=True,
|
||||
|
|
|
|||
|
|
@ -87,6 +87,13 @@ class ResponsesAPIRequestUtils:
|
|||
)
|
||||
filtered_params["previous_response_id"] = decoded_previous_response_id
|
||||
|
||||
if "metadata" in filtered_params:
|
||||
from litellm.utils import add_openai_metadata
|
||||
|
||||
filtered_params["metadata"] = add_openai_metadata(
|
||||
filtered_params["metadata"]
|
||||
)
|
||||
|
||||
return cast(ResponsesAPIOptionalRequestParams, filtered_params)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -7147,6 +7147,16 @@ def add_openai_metadata(metadata: dict) -> dict:
|
|||
if k != "hidden_params" and isinstance(v, (str))
|
||||
}
|
||||
|
||||
# max 16 keys allowed by openai - trim down to 16
|
||||
if len(visible_metadata) > 16:
|
||||
filtered_metadata = {}
|
||||
idx = 0
|
||||
for k, v in visible_metadata.items():
|
||||
if idx < 16:
|
||||
filtered_metadata[k] = v
|
||||
idx += 1
|
||||
visible_metadata = filtered_metadata
|
||||
|
||||
return visible_metadata.copy()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue