Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat: implement Ollama thinking mode with user control

tombiif97c2f151e27
diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.py
index b682ef9434..090d3f90c9 100644
--- a/src/local_deep_research/config/llm_config.py
+++ b/src/local_deep_research/config/llm_config.py
@@ -706,20 +706,33 @@ def get_llm(
if context_window_size is not None:
ollama_params["num_ctx"] = context_window_size
- # Handle reasoning/thinking content from models like deepseek-r1
- # When reasoning=True, thinking content is excluded from the main
- # response and stored in additional_kwargs["reasoning_content"]
- reasoning_mode = get_setting_from_snapshot(
- "llm.ollama.reasoning",
- True, # Default to True to exclude thinking from responses
+ # Thinking/reasoning handling for models like deepseek-r1:
+ # The 'reasoning' parameter controls both:
+ # 1. Whether the model performs thinking (makes it smarter when True)
+ # 2. Whether thinking is separated from the answer (always separated when True)
+ #
+ # When reasoning=True:
+ # - Model performs thinking/reasoning
+ # - Thinking goes to additional_kwargs["reasoning_content"] (discarded by LDR)
+ # - Only the final answer appears in response.content
+ #
+ # When reasoning=False:
+ # - Model does NOT perform thinking (faster but less smart)
+ # - Gives direct answers
+
+ enable_thinking = get_setting_from_snapshot(
+ "llm.ollama.enable_thinking",
+ True, # Default: enable thinking (smarter responses)
settings_snapshot=settings_snapshot,
)
- if reasoning_mode is not None and isinstance(
- reasoning_mode, bool
+
+ if enable_thinking is not None and isinstance(
+ enable_thinking, bool
):
- ollama_params["reasoning"] = reasoning_mode
+ ollama_params["reasoning"] = enable_thinking
logger.debug(
- f"Ollama reasoning mode set to: {reasoning_mode}"
+ f"Ollama thinking enabled: {enable_thinking} "
+ f"(thinking will be {'shown internally but discarded' if enable_thinking else 'disabled'})"
)
llm = ChatOllama(
diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.json
index 688b506c7d..0b11302292 100644
--- a/src/local_deep_research/defaults/default_settings.json
+++ b/src/local_deep_research/defaults/default_settings.json
@@ -402,13 +402,13 @@
"value": "http://localhost:11434",
"visible": true
},
- "llm.ollama.reasoning": {
+ "llm.ollama.enable_thinking": {
"category": "llm",
- "description": "Separate reasoning/thinking content from main response for models like deepseek-r1. When enabled (recommended), thinking is excluded from the final answer.",
+ "description": "Enable thinking/reasoning mode for models like deepseek-r1 and qwen3. When enabled, the model shows its reasoning process. When disabled, the model gives direct answers without showing reasoning steps.",
"editable": true,
"max_value": null,
"min_value": null,
- "name": "Ollama Reasoning Mode",
+ "name": "Ollama Enable Thinking",
"options": null,
"step": null,
"type": "LLM",
diff --git a/src/local_deep_research/utilities/search_utilities.py b/src/local_deep_research/utilities/search_utilities.py
index 8afcfca335..c03f6ffb36 100644
--- a/src/local_deep_research/utilities/search_utilities.py
+++ b/src/local_deep_research/utilities/search_utilities.py
@@ -5,8 +5,12 @@ from loguru import logger
def remove_think_tags(text: str) -> str:
- text = re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL).strip()
- return text
+ # Remove paired <think>...</think> tags
+ text = re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL)
+ # Remove any orphaned opening or closing think tags
+ text = re.sub(r"</think>", "", text)
+ text = re.sub(r"<think>", "", text)
+ return text.strip()
def extract_links_from_search_results(search_results: List[Dict]) -> List[Dict]: