From 5f384da4894799107cf177c49f336ce8944a8abb Mon Sep 17 00:00:00 2001 From: minecraft1024a Date: Sat, 1 Nov 2025 19:31:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(chat):=20=E7=AE=80=E5=8C=96=E6=97=A5?= =?UTF-8?q?=E7=A8=8B=E7=8A=B6=E6=80=81=E6=8F=90=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除了在日程活动时间范围之外的冗余状态判断。现在,无论当前时间是否在活动时间段内,都会统一计算并展示活动的开始、结束、已进行和剩余时间,简化了代码逻辑并确保了信息展示的一致性。反正LLM自己会判断的,不需要咱操心那么多啦。 --- src/chat/replyer/default_generator.py | 9 +++------ src/llm_models/model_client/openai_client.py | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/chat/replyer/default_generator.py b/src/chat/replyer/default_generator.py index 106295ca9..5b214aade 100644 --- a/src/chat/replyer/default_generator.py +++ b/src/chat/replyer/default_generator.py @@ -1468,18 +1468,15 @@ class DefaultReplyer: if now < start_time: now += timedelta(days=1) - if start_time <= now < end_time: - duration_minutes = (now - start_time).total_seconds() / 60 - remaining_minutes = (end_time - now).total_seconds() / 60 - schedule_block = ( + duration_minutes = (now - start_time).total_seconds() / 60 + remaining_minutes = (end_time - now).total_seconds() / 60 + schedule_block = ( f"你当前正在进行“{activity}”," f"计划时间从{start_time.strftime('%H:%M')}到{end_time.strftime('%H:%M')}。" f"这项活动已经开始了{duration_minutes:.0f}分钟," f"预计还有{remaining_minutes:.0f}分钟结束。" "(此为你的当前状态,仅供参考。除非被直接询问,否则不要在对话中主动提及。)" ) - else: - schedule_block = f"你当前正在进行“{activity}”。(此为你的当前状态,仅供参考。除非被直接询问,否则不要在对话中主动提及。)" except (ValueError, AttributeError): schedule_block = f"你当前正在进行“{activity}”。(此为你的当前状态,仅供参考。除非被直接询问,否则不要在对话中主动提及。)" diff --git a/src/llm_models/model_client/openai_client.py b/src/llm_models/model_client/openai_client.py index 3b6055b45..efa1785d9 100644 --- a/src/llm_models/model_client/openai_client.py +++ b/src/llm_models/model_client/openai_client.py @@ -350,10 +350,10 @@ def _default_normal_response_parser( api_response.tool_calls = [] for call in message_part.tool_calls: try: - arguments = orjson.loads(repair_json(call.function.arguments)) + arguments = orjson.loads(repair_json(call.function.arguments)) # type: ignore if not isinstance(arguments, dict): raise RespParseException(resp, "响应解析失败,工具调用参数无法解析为字典类型") - api_response.tool_calls.append(ToolCall(call.id, call.function.name, arguments)) + api_response.tool_calls.append(ToolCall(call.id, call.function.name, arguments)) # type: ignore except orjson.JSONDecodeError as e: raise RespParseException(resp, "响应解析失败,无法解析工具调用参数") from e