fix(ollama): check for tools before resolving the ollama route

The ternary that turned tools into a bool tripped the SIM210 strict-rule
budget. A plain if in completion() avoids both that and passing the untyped
tool lists into a typed helper
This commit is contained in:
Meryem Sakin 2026-09-11 00:11:18 +03:00
parent b55377352e
commit 5476e05bbe
2 changed files with 8 additions and 11 deletions

View file

@ -11,14 +11,12 @@ class OllamaError(BaseLLMException):
super().__init__(status_code=status_code, message=message, headers=headers)
def resolve_ollama_tool_calling_provider(
custom_llm_provider: str, has_tools: bool, add_function_to_prompt: bool
) -> str:
def resolve_ollama_tool_calling_provider(custom_llm_provider: str, add_function_to_prompt: bool) -> str:
"""
/api/generate has no native tool calling, so ollama/ tool requests go through the ollama_chat
adapter unless add_function_to_prompt opts back into the legacy JSON prompt emulation
For requests with tools: /api/generate has no native tool calling, so ollama/ goes through the
ollama_chat adapter unless add_function_to_prompt opts back into the legacy JSON prompt emulation
"""
if custom_llm_provider == "ollama" and has_tools and not add_function_to_prompt:
if custom_llm_provider == "ollama" and not add_function_to_prompt:
return "ollama_chat"
return custom_llm_provider

View file

@ -5308,11 +5308,10 @@ def completion(
GenericLiteLLMParams(**_supplemental_provider_params) if _supplemental_provider_params else None
),
)
custom_llm_provider = resolve_ollama_tool_calling_provider( # rebind-ok: ollama tools use the chat adapter
custom_llm_provider,
has_tools=True if tools or functions else False,
add_function_to_prompt=litellm.add_function_to_prompt,
)
if tools or functions:
custom_llm_provider = resolve_ollama_tool_calling_provider( # rebind-ok: ollama tools use the chat adapter
custom_llm_provider, add_function_to_prompt=litellm.add_function_to_prompt
)
## RESPONSES API BRIDGE LOGIC ## - check early and normalize model name
responses_api_model_info, model = responses_api_bridge_check(