Skip to content

Commit

Permalink
feat:add deepseek r1 think display for ollama provider (#13272)
Browse files Browse the repository at this point in the history
  • Loading branch information
leslie2046 authored Feb 6, 2025
1 parent 49b4144 commit 0d13aee
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/core/model_runtime/model_providers/ollama/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -367,6 +368,14 @@ def create_final_llm_result_chunk(

# 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)

Expand Down

0 comments on commit 0d13aee

Please sign in to comment.