From b08bb56f6c1f5c3316d93241301b9abb37387039 Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Wed, 12 Feb 2025 15:43:13 +0800 Subject: [PATCH] Display thinking for deepseek r1 (#4904) ### What problem does this PR solve? #4903 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- deepdoc/vision/operators.py | 2 +- rag/llm/chat_model.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/deepdoc/vision/operators.py b/deepdoc/vision/operators.py index bfe6c726a..d7162522a 100644 --- a/deepdoc/vision/operators.py +++ b/deepdoc/vision/operators.py @@ -108,7 +108,7 @@ class NormalizeImage(object): def __init__(self, scale=None, mean=None, std=None, order='chw', **kwargs): if isinstance(scale, str): - scale = np.float32(scale) if scale != 'None' else None + scale = eval(scale) self.scale = np.float32(scale if scale is not None else 1.0 / 255.0) mean = mean if mean is not None else [0.485, 0.456, 0.406] std = std if std is not None else [0.229, 0.224, 0.225] diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py index e4cf3a6ad..83a4fc37e 100644 --- a/rag/llm/chat_model.py +++ b/rag/llm/chat_model.py @@ -73,7 +73,13 @@ class Base(ABC): continue if not resp.choices[0].delta.content: resp.choices[0].delta.content = "" - ans += resp.choices[0].delta.content + if hasattr(resp.choices[0].delta, "reasoning_content") and resp.choices[0].delta.reasoning_content: + if ans.find("") < 0: + ans += "" + ans = ans.replace("", "") + ans += resp.choices[0].delta.reasoning_content + "" + else: + ans += resp.choices[0].delta.content tol = self.total_token_count(resp) if not tol: