mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
Fix ruff PLR0915 error
This commit is contained in:
parent
7c168ab173
commit
8cb3a0f1d2
2 changed files with 58 additions and 38 deletions
|
|
@ -409,6 +409,24 @@ async def _call_aresponses(
|
|||
return await aresponses(input=input, model=model, tools=tools, **kwargs)
|
||||
|
||||
|
||||
def _prepare_emulated_file_search_call(
|
||||
kwargs: Dict[str, Any],
|
||||
) -> Tuple[bool, Dict[str, Any]]:
|
||||
include_items: List[str] = list(kwargs.get("include") or [])
|
||||
include_search_results = "file_search_call.results" in include_items
|
||||
|
||||
original_stream = kwargs.get("stream")
|
||||
updated_kwargs = kwargs
|
||||
if original_stream:
|
||||
verbose_logger.debug(
|
||||
"Streaming is not yet supported for emulated file_search. "
|
||||
"Disabling stream for this request."
|
||||
)
|
||||
updated_kwargs = {**kwargs, "stream": False}
|
||||
|
||||
return include_search_results, updated_kwargs
|
||||
|
||||
|
||||
async def aresponses_with_emulated_file_search(
|
||||
input: Any,
|
||||
model: str,
|
||||
|
|
@ -423,17 +441,7 @@ async def aresponses_with_emulated_file_search(
|
|||
runs vector search, and synthesizes an OpenAI-format response.
|
||||
"""
|
||||
# Determine whether caller wants search_results populated in the output.
|
||||
_include: List[str] = list(kwargs.get("include") or [])
|
||||
_include_search_results = "file_search_call.results" in _include
|
||||
|
||||
# Disable streaming for emulated file_search (not yet supported)
|
||||
_original_stream = kwargs.get("stream")
|
||||
if _original_stream:
|
||||
verbose_logger.debug(
|
||||
"Streaming is not yet supported for emulated file_search. "
|
||||
"Disabling stream for this request."
|
||||
)
|
||||
kwargs = {**kwargs, "stream": False}
|
||||
_include_search_results, kwargs = _prepare_emulated_file_search_call(kwargs=kwargs)
|
||||
|
||||
# 1. Replace file_search tools with function tool
|
||||
transformed_tools, all_vs_ids = _replace_file_search_tools(tools)
|
||||
|
|
|
|||
|
|
@ -668,6 +668,43 @@ def _resolve_model_provider_for_responses(
|
|||
return model, custom_llm_provider
|
||||
|
||||
|
||||
def _apply_managed_file_id_mapping(
|
||||
input: Union[str, ResponseInputParam],
|
||||
tools: Optional[Iterable[ToolParam]],
|
||||
kwargs: Dict[str, Any],
|
||||
local_vars: Dict[str, Any],
|
||||
) -> tuple[Union[str, ResponseInputParam], Optional[Iterable[ToolParam]]]:
|
||||
model_file_id_mapping = kwargs.get("model_file_id_mapping")
|
||||
model_info_id = (
|
||||
kwargs.get("model_info", {}).get("id")
|
||||
if isinstance(kwargs.get("model_info"), dict)
|
||||
else None
|
||||
)
|
||||
|
||||
input = cast(
|
||||
Union[str, ResponseInputParam],
|
||||
update_responses_input_with_model_file_ids(
|
||||
input=input,
|
||||
model_id=model_info_id,
|
||||
model_file_id_mapping=model_file_id_mapping,
|
||||
),
|
||||
)
|
||||
local_vars["input"] = input
|
||||
|
||||
if tools:
|
||||
tools = cast(
|
||||
Optional[Iterable[ToolParam]],
|
||||
update_responses_tools_with_model_file_ids(
|
||||
tools=cast(Optional[List[Dict[str, Any]]], tools),
|
||||
model_id=model_info_id,
|
||||
model_file_id_mapping=model_file_id_mapping,
|
||||
),
|
||||
)
|
||||
local_vars["tools"] = tools
|
||||
|
||||
return input, tools
|
||||
|
||||
|
||||
@client
|
||||
def responses(
|
||||
input: Union[str, ResponseInputParam],
|
||||
|
|
@ -764,35 +801,10 @@ def responses(
|
|||
#########################################################
|
||||
# Update input and tools with provider-specific file IDs if managed files are used
|
||||
#########################################################
|
||||
model_file_id_mapping = kwargs.get("model_file_id_mapping")
|
||||
model_info_id = (
|
||||
kwargs.get("model_info", {}).get("id")
|
||||
if isinstance(kwargs.get("model_info"), dict)
|
||||
else None
|
||||
input, tools = _apply_managed_file_id_mapping(
|
||||
input=input, tools=tools, kwargs=kwargs, local_vars=local_vars
|
||||
)
|
||||
|
||||
input = cast(
|
||||
Union[str, ResponseInputParam],
|
||||
update_responses_input_with_model_file_ids(
|
||||
input=input,
|
||||
model_id=model_info_id,
|
||||
model_file_id_mapping=model_file_id_mapping,
|
||||
),
|
||||
)
|
||||
local_vars["input"] = input
|
||||
|
||||
# Update tools with provider-specific file IDs if needed
|
||||
if tools:
|
||||
tools = cast(
|
||||
Optional[Iterable[ToolParam]],
|
||||
update_responses_tools_with_model_file_ids(
|
||||
tools=cast(Optional[List[Dict[str, Any]]], tools),
|
||||
model_id=model_info_id,
|
||||
model_file_id_mapping=model_file_id_mapping,
|
||||
),
|
||||
)
|
||||
local_vars["tools"] = tools
|
||||
|
||||
#########################################################
|
||||
# Native MCP Responses API
|
||||
#########################################################
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue