From 5476e05bbe50f20fc63cee8108c3d3cc190d64ad Mon Sep 17 00:00:00 2001 From: Meryem Sakin Date: Fri, 11 Sep 2026 00:11:18 +0300 Subject: [PATCH] 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 --- litellm/llms/ollama/common_utils.py | 10 ++++------ litellm/main.py | 9 ++++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/litellm/llms/ollama/common_utils.py b/litellm/llms/ollama/common_utils.py index 0111340ca8e..36fe39982a5 100644 --- a/litellm/llms/ollama/common_utils.py +++ b/litellm/llms/ollama/common_utils.py @@ -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 diff --git a/litellm/main.py b/litellm/main.py index 6db13ddcdb7..18e397a1f6d 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -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(