Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

CLI: show a thinking model's reasoning with --think when attached to a running Unsloth (#11956)

breken06bfeb903b98
diff --git a/unsloth_cli/_inference.py b/unsloth_cli/_inference.py
index 423d0f61420..97ced9e1c86 100644
--- a/unsloth_cli/_inference.py
+++ b/unsloth_cli/_inference.py
@@ -1009,7 +1009,9 @@ class HttpChatBackend:
def cumulative():
# Accumulate SSE deltas into the full-text-so-far convention the stream helpers expect.
+ # The server splits reasoning into delta.reasoning_content: re-wrap it in <think> for visible_text.
text = ""
+ thinking = False
with resp:
for raw_line in resp:
line = raw_line.decode("utf-8", "replace").strip()
@@ -1034,12 +1036,21 @@ class HttpChatBackend:
if choice.get("finish_reason") is not None:
self.reply_hit_token_limit = choice["finish_reason"] == "length"
try:
+ reasoning = choice["delta"].get("reasoning_content")
delta = choice["delta"].get("content")
except (KeyError, AttributeError, TypeError):
continue
- if not delta:
+ if reasoning:
+ if not thinking:
+ text += _THINK_OPEN
+ thinking = True
+ text += reasoning
+ if delta and thinking:
+ text += "</think>"
+ thinking = False
+ if not (reasoning or delta):
continue
- text += delta
+ text += delta or ""
# An emoji can arrive split across two deltas as lone surrogate halves: hold back a trailing
# half, merge pairs.
visible = text
diff --git a/unsloth_cli/tests/test_inference_chat.py b/unsloth_cli/tests/test_inference_chat.py
index 8dfd908ecd3..8296c13ca77 100644
--- a/unsloth_cli/tests/test_inference_chat.py
+++ b/unsloth_cli/tests/test_inference_chat.py
@@ -1300,6 +1300,35 @@ def test_http_backend_reports_whether_a_reply_ran_out_of_budget(monkeypatch):
assert _http_finish(monkeypatch, "stop")[0] is False
+def _http_reasoning_reply(monkeypatch):
+ # The server's shape for a thinking model: reasoning-only deltas carry content "".
+ deltas = [
+ {"role": "assistant", "content": ""},
+ {"content": "", "reasoning_content": "Two plus "},
+ {"content": "", "reasoning_content": "two."},
+ {"content": "It is "},
+ {"content": "4."},
+ ]
+ lines = [f"data: {json.dumps({'choices': [{'delta': delta}]})}\n".encode() for delta in deltas]
+ backend = HttpChatBackend("http://localhost:8888", "token")
+ monkeypatch.setattr(
+ backend, "_request", lambda *a, **k: _FakeSSEResponse([*lines, b"data: [DONE]\n"])
+ )
+ return backend.stream(
+ [{"role": "user", "content": "2+2?"}], **{**_STREAM_KWARGS, "enable_thinking": True}
+ )
+
+
+def test_http_backend_shows_server_reasoning_with_think(monkeypatch):
+ stream = _http_reasoning_reply(monkeypatch)
+ assert collect_stream(stream, show_thinking = True) == "<think>Two plus two.</think>It is 4."
+
+
+def test_http_backend_hides_server_reasoning_without_think(monkeypatch):
+ stream = _http_reasoning_reply(monkeypatch)
+ assert collect_stream(stream, show_thinking = False) == "It is 4."
+
+
class _FakeLoadResponse:
"""A /api/inference/load reply that records whether its body was drained.