From 8e48e7201912f6706f295806adf50d05d738678c Mon Sep 17 00:00:00 2001 From: KawaiiYusora <40208202+SaigyoujiYusora@users.noreply.github.com> Date: Wed, 5 Mar 2025 09:27:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=8B=E6=9F=A5=E7=BC=BA=E8=A1=A5?= =?UTF-8?q?=E6=BC=8F=20(#53)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/models/utils_model.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugins/models/utils_model.py b/src/plugins/models/utils_model.py index 4741d259..3ba873d7 100644 --- a/src/plugins/models/utils_model.py +++ b/src/plugins/models/utils_model.py @@ -60,8 +60,15 @@ class LLM_request: result = await response.json() if "choices" in result and len(result["choices"]) > 0: - content = result["choices"][0]["message"]["content"] - reasoning_content = result["choices"][0]["message"].get("reasoning_content", "") + message = result["choices"][0]["message"] + content = message.get("content", "") + think_match = None + reasoning_content = message.get("reasoning_content", "") + if not reasoning_content: + think_match = re.search(r'(.*?)', content, re.DOTALL) + if think_match: + reasoning_content = think_match.group(1).strip() + content = re.sub(r'.*?', '', content, flags=re.DOTALL).strip() return content, reasoning_content return "没有返回结果", ""