From e5d3048fb2bcf93f2de9d8ef91ca32059e417e5a Mon Sep 17 00:00:00 2001 From: Sakura-RanChen <1908198662@qq.com> Date: Tue, 29 Jul 2025 09:55:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=B6=E9=97=B4=E8=A2=AB=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/utils/dialogue.py | 4 ++++ main/xiaozhi-server/core/utils/prompt_manager.py | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/main/xiaozhi-server/core/utils/dialogue.py b/main/xiaozhi-server/core/utils/dialogue.py index fbbf7302..f135d930 100644 --- a/main/xiaozhi-server/core/utils/dialogue.py +++ b/main/xiaozhi-server/core/utils/dialogue.py @@ -73,6 +73,10 @@ class Dialogue: if system_message: # 基础系统提示 enhanced_system_prompt = system_message.content + # 替换时间占位符 + enhanced_system_prompt = enhanced_system_prompt.replace( + "{{current_time}}", datetime.now().strftime("%H:%M") + ) # 添加说话人个性化描述 try: diff --git a/main/xiaozhi-server/core/utils/prompt_manager.py b/main/xiaozhi-server/core/utils/prompt_manager.py index 79c92921..3f6c429a 100644 --- a/main/xiaozhi-server/core/utils/prompt_manager.py +++ b/main/xiaozhi-server/core/utils/prompt_manager.py @@ -120,7 +120,6 @@ class PromptManager: from datetime import datetime now = datetime.now() - current_time = now.strftime("%H:%M") today_date = now.strftime("%Y-%m-%d") today_weekday = WEEKDAY_MAP[now.strftime("%A")] today_lunar = cnlunar.Lunar(now, godType="8char") @@ -130,7 +129,7 @@ class PromptManager: today_lunar.lunarDayCn, ) - return current_time, today_date, today_weekday, lunar_date + return today_date, today_weekday, lunar_date def _get_location_info(self, client_ip: str) -> str: """获取位置信息""" @@ -199,7 +198,7 @@ class PromptManager: try: # 获取最新的时间信息(不缓存) - current_time, today_date, today_weekday, lunar_date = ( + today_date, today_weekday, lunar_date = ( self._get_current_time_info() ) @@ -224,7 +223,7 @@ class PromptManager: template = Template(self.base_prompt_template) enhanced_prompt = template.render( base_prompt=user_prompt, - current_time=current_time, + current_time="{{current_time}}", today_date=today_date, today_weekday=today_weekday, lunar_date=lunar_date,