fix: restore args = locals() at original position to avoid leaking extra vars

Reverts the deferred locals() change. The deferred call at line 1286/1291
captured ~50 extra local variables and caused a TypeError on the
batch_completion_models path (deployments passed as both explicit kwarg
and in **locals()). Restores args = locals() at its original position
before kwargs unpacking. Keeps the LlmProvidersSet and minimal
{"messages": messages} changes which are safe.
This commit is contained in:
Ryan Crabbe 2026-02-17 12:31:02 -08:00
parent 4a878ccc64
commit c575ac7813

View file

@ -1104,6 +1104,7 @@ def completion( # type: ignore # noqa: PLR0915
# validate optional params
stop = validate_openai_optional_params(stop=stop)
args = locals()
######### unpacking kwargs #####################
skip_mcp_handler = kwargs.pop("_skip_mcp_handler", False)
if not skip_mcp_handler and tools:
@ -1283,12 +1284,12 @@ def completion( # type: ignore # noqa: PLR0915
logging: LiteLLMLoggingObj = cast(LiteLLMLoggingObj, litellm_logging_obj)
fallbacks = fallbacks or litellm.model_fallbacks
if fallbacks is not None:
return completion_with_fallbacks(**locals())
return completion_with_fallbacks(**args)
if model_list is not None:
deployments = [
m["litellm_params"] for m in model_list if m["model_name"] == model
]
return litellm.batch_completion_models(deployments=deployments, **locals())
return litellm.batch_completion_models(deployments=deployments, **args)
if litellm.model_alias_map and model in litellm.model_alias_map:
model = litellm.model_alias_map[
model