mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix: map file_url -> file_id in Responses->Completions translation
This commit is contained in:
parent
7833eee344
commit
4b5ca49cd2
2 changed files with 339 additions and 243 deletions
|
|
@ -1202,22 +1202,32 @@ class LiteLLMCompletionResponsesConfig:
|
|||
|
||||
return [chat_completion_response_message]
|
||||
|
||||
@staticmethod
|
||||
def _resolve_file_id(item: Dict[str, Any]) -> Optional[str]:
|
||||
"""
|
||||
Return the effective file_id for a Responses API input_file item.
|
||||
Explicit file_id takes precedence; file_url is used as fallback so
|
||||
downstream providers (Anthropic, Gemini) can handle the URL natively.
|
||||
"""
|
||||
return item.get("file_id") or item.get("file_url") or None
|
||||
|
||||
@staticmethod
|
||||
def _transform_input_file_item_to_file_item(item: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Transform a Responses API input_file item to a Chat Completion file item
|
||||
|
||||
Args:
|
||||
item: Dictionary containing input_file type with file_id and/or file_data
|
||||
item: Dictionary containing input_file type with file_id, file_data, and/or file_url
|
||||
|
||||
Returns:
|
||||
Dictionary with transformed file structure for Chat Completion
|
||||
"""
|
||||
file_dict: Dict[str, Any] = {}
|
||||
keys = ["file_id", "file_data"]
|
||||
for key in keys:
|
||||
if item.get(key):
|
||||
file_dict[key] = item.get(key)
|
||||
file_id = LiteLLMCompletionResponsesConfig._resolve_file_id(item)
|
||||
if file_id:
|
||||
file_dict["file_id"] = file_id
|
||||
if item.get("file_data"):
|
||||
file_dict["file_data"] = item["file_data"]
|
||||
|
||||
new_item: Dict[str, Any] = {"type": "file", "file": file_dict}
|
||||
return new_item
|
||||
|
|
@ -2113,9 +2123,9 @@ class LiteLLMCompletionResponsesConfig:
|
|||
hasattr(completion_details, "reasoning_tokens")
|
||||
and completion_details.reasoning_tokens is not None
|
||||
):
|
||||
output_details_dict[
|
||||
"reasoning_tokens"
|
||||
] = completion_details.reasoning_tokens
|
||||
output_details_dict["reasoning_tokens"] = (
|
||||
completion_details.reasoning_tokens
|
||||
)
|
||||
else:
|
||||
output_details_dict["reasoning_tokens"] = 0
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue