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,