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 3ae728d4b36985..0377731175ebbe 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 @@ def _handle_generate_stream_response( """ 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 @@ def create_final_llm_result_chunk( # transform assistant message to prompt message text = chunk_json["response"] + if "" in text: + is_reasoning_started = True + text = text.replace("", "> 💭 ") + elif "" in text: + is_reasoning_started = False + text = text.replace("", "") + "\n\n" + elif is_reasoning_started: + text = text.replace("\n", "\n> ") assistant_prompt_message = AssistantPromptMessage(content=text)