Skip to content

Commit 90bd89c

Browse files
feat(ollama_chat/): add 'think' param support + output parse '<think>' content into 'reasoning_content'
Ensures consistent use of thinking
1 parent 3a68ca5 commit 90bd89c

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

litellm/llms/ollama/chat/transformation.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,31 @@ def transform_response(
349349

350350
## RESPONSE OBJECT
351351
model_response.choices[0].finish_reason = "stop"
352+
response_json_message = response_json.get("message")
353+
if response_json_message is not None:
354+
if "thinking" in response_json_message:
355+
# remap 'thinking' to 'reasoning_content'
356+
response_json_message["reasoning_content"] = response_json_message[
357+
"thinking"
358+
]
359+
del response_json_message["thinking"]
360+
elif response_json_message.get("content") is not None:
361+
# parse reasoning content from content
362+
from litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response import (
363+
_parse_content_for_reasoning,
364+
)
365+
366+
reasoning_content, content = _parse_content_for_reasoning(
367+
response_json_message["content"]
368+
)
369+
response_json_message["reasoning_content"] = reasoning_content
370+
response_json_message["content"] = content
371+
352372
if (
353373
request_data.get("format", "") == "json"
354374
and litellm_params.get("function_name") is not None
355375
):
356-
function_call = json.loads(response_json["message"]["content"])
376+
function_call = json.loads(response_json_message["content"])
357377
message = litellm.Message(
358378
content=None,
359379
tool_calls=[
@@ -370,11 +390,13 @@ def transform_response(
370390
"type": "function",
371391
}
372392
],
393+
reasoning_content=response_json_message.get("reasoning_content"),
373394
)
374395
model_response.choices[0].message = message # type: ignore
375396
model_response.choices[0].finish_reason = "tool_calls"
376397
else:
377-
_message = litellm.Message(**response_json["message"])
398+
399+
_message = litellm.Message(**response_json_message)
378400
model_response.choices[0].message = _message # type: ignore
379401
model_response.created = int(time.time())
380402
model_response.model = "ollama_chat/" + model
File renamed without changes.

litellm/proxy/_experimental/out/onboarding.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

litellm/proxy/_new_secret_config.yaml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
model_list:
2-
- model_name: fake-openai-endpoint
3-
litellm_params:
4-
model: openai/fake
5-
api_key: fake-key
6-
api_base: https://exampleopenaiendpoint-production.up.railway.app/
7-
- model_name: gpt-5-mini
8-
litellm_params:
9-
model: azure/gpt-5-mini
10-
api_base: os.environ/AZURE_GPT_5_MINI_API_BASE # runs os.getenv("AZURE_API_BASE")
11-
api_key: os.environ/AZURE_GPT_5_MINI_API_KEY # runs os.getenv("AZURE_API_KEY")
12-
stream_timeout: 60
13-
merge_reasoning_content_in_choices: true
14-
model_info:
15-
mode: chat
2+
- model_name: fake-openai-endpoint
3+
litellm_params:
4+
model: openai/fake
5+
api_key: fake-key
6+
api_base: https://exampleopenaiendpoint-production.up.railway.app/
7+
- model_name: gpt-5-mini
8+
litellm_params:
9+
model: azure/gpt-5-mini
10+
api_base: os.environ/AZURE_GPT_5_MINI_API_BASE # runs os.getenv("AZURE_API_BASE")
11+
api_key: os.environ/AZURE_GPT_5_MINI_API_KEY # runs os.getenv("AZURE_API_KEY")
12+
stream_timeout: 60
13+
merge_reasoning_content_in_choices: true
14+
model_info:
15+
mode: chat
16+
- model_name: ollama-deepseek-r1
17+
litellm_params:
18+
model: ollama_chat/deepseek-r1:1.5b
19+
model_info:
20+
mode: chat
1621

1722
router_settings:
1823
model_group_alias: {"my-fake-gpt-4": "fake-openai-endpoint"}

0 commit comments

Comments
 (0)