From 700c8dfa6f5c8c06d90bd89a2e7decedc8eca625 Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Wed, 27 Aug 2025 18:16:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(chat):=20=E5=A4=84=E7=90=86=E6=88=AA?= =?UTF-8?q?=E6=96=AD=E6=B6=88=E6=81=AF=E6=97=B6message=E4=B8=BANone?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 `truncate_message` 函数中,如果传入的 `message` 参数为 `None`,会导致 `len(message)` 抛出 `TypeError`。本次提交增加了对 `None` 值的检查,确保在处理 `None` 时函数能正常返回空字符串,从而提高代码的健壮性。 --- src/chat/utils/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/chat/utils/utils.py b/src/chat/utils/utils.py index f9807b16a..5629a224b 100644 --- a/src/chat/utils/utils.py +++ b/src/chat/utils/utils.py @@ -449,6 +449,8 @@ def find_similar_topics_simple(text: str, topics: list, top_k: int = 5) -> list: def truncate_message(message: str, max_length=20) -> str: """截断消息,使其不超过指定长度""" + if message is None: + return "" return f"{message[:max_length]}..." if len(message) > max_length else message