Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

feat:add deepseek r1 think display for ollama provider (#13272)

呆萌闷油瓶0d13aee15cdc
diff --git a/api/core/model_runtime/model_providers/ollama/llm/llm.py b/api/core/model_runtime/model_providers/ollama/llm/llm.py
index 3ae728d4b36..0377731175e 100644
--- a/api/core/model_runtime/model_providers/ollama/llm/llm.py
+++ b/api/core/model_runtime/model_providers/ollama/llm/llm.py
@@ -314,6 +314,7 @@ class OllamaLargeLanguageModel(LargeLanguageModel):
"""
full_text = ""
chunk_index = 0
+ is_reasoning_started = False
def create_final_llm_result_chunk(
index: int, message: AssistantPromptMessage, finish_reason: str
@@ -367,6 +368,14 @@ class OllamaLargeLanguageModel(LargeLanguageModel):
# transform assistant message to prompt message
text = chunk_json["response"]
+ if "<think>" in text:
+ is_reasoning_started = True
+ text = text.replace("<think>", "> 💭 ")
+ elif "</think>" in text:
+ is_reasoning_started = False
+ text = text.replace("</think>", "") + "\n\n"
+ elif is_reasoning_started:
+ text = text.replace("\n", "\n> ")
assistant_prompt_message = AssistantPromptMessage(content=text)