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.

studio: handle reasoning_content in GGUF streaming

Daniel Han961720c1b17d
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index 21a25d51b2e..2f68958bbd8 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -592,6 +592,7 @@ class LlamaCppBackend:
url = f"{self.base_url}/v1/chat/completions"
cumulative = ""
+ in_thinking = False
try:
with httpx.Client(timeout = None) as client:
@@ -615,6 +616,9 @@ class LlamaCppBackend:
if not line:
continue
if line == "data: [DONE]":
+ if in_thinking:
+ cumulative += "</think>"
+ yield cumulative
return
if not line.startswith("data: "):
continue
@@ -624,8 +628,23 @@ class LlamaCppBackend:
choices = data.get("choices", [])
if choices:
delta = choices[0].get("delta", {})
+
+ # Handle reasoning/thinking tokens
+ # llama-server sends these as "reasoning_content"
+ # Wrap in <think> tags for the frontend parser
+ reasoning = delta.get("reasoning_content", "")
+ if reasoning:
+ if not in_thinking:
+ cumulative += "<think>"
+ in_thinking = True
+ cumulative += reasoning
+ yield cumulative
+
token = delta.get("content", "")
if token:
+ if in_thinking:
+ cumulative += "</think>"
+ in_thinking = False
cumulative += token
yield cumulative
except json.JSONDecodeError: