mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
fix(ollama): remap tool role to tool_responses for Gemma models
Gemma models served via Ollama expect the role "tool_responses" for tool result messages instead of the OpenAI-standard "tool" role. Without this mapping the model ignores the tool result and enters an infinite tool-calling loop. Fixes #28530
This commit is contained in:
parent
f69b9d6564
commit
81f1dcba2d
1 changed files with 7 additions and 1 deletions
|
|
@ -287,8 +287,14 @@ class OllamaChatConfig(BaseConfig):
|
|||
content_str = convert_content_list_to_str(cast(AllMessageValues, m))
|
||||
images = extract_images_from_message(cast(AllMessageValues, m))
|
||||
|
||||
role = cast(str, m.get("role"))
|
||||
# Gemma models (via Ollama) expect "tool_responses" for tool result
|
||||
# messages instead of the OpenAI-standard "tool" role. Without this,
|
||||
# the model ignores the result and loops infinitely.
|
||||
if role == "tool" and "gemma" in model.lower():
|
||||
role = "tool_responses"
|
||||
ollama_message = OllamaChatCompletionMessage(
|
||||
role=cast(str, m.get("role")),
|
||||
role=role,
|
||||
)
|
||||
if reasoning_content is not None:
|
||||
ollama_message["thinking"] = reasoning_content
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue