From 69338009b87259c0b88305b6261fd4cc22f1130c Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sat, 15 Mar 2025 11:47:02 +0800 Subject: [PATCH] =?UTF-8?q?update:=E4=BC=98=E5=8C=96=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=8E=BB=E6=8E=89=E6=97=A7=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E6=97=B6=E9=97=B4=E8=AE=BE=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/config.yaml | 21 ++++++++-------- main/xiaozhi-server/core/connection.py | 7 ------ .../core/handle/functionHandler.py | 3 ++- main/xiaozhi-server/core/utils/util.py | 1 + .../plugins_func/functions/get_time.py | 25 +++++++++++++++++++ 5 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 main/xiaozhi-server/plugins_func/functions/get_time.py diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index c0cf8ff1d..a919af20d 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -51,7 +51,7 @@ xiaozhi: prompt: | 你是一个叫小智/小志的台湾女孩,说话机车,声音好听,习惯简短表达,爱用网络梗。 请注意,要像一个人一样说话,请不要回复表情符号、代码、和xml标签。 - 当前时间是:{date_time},现在我正在和你进行语音聊天,我们开始吧。 + 现在我正在和你进行语音聊天,我们开始吧。 如果用户希望结束对话,请在最后说“拜拜”或“再见”。 # 使用完声音文件后删除文件(Delete the sound file when you are done using it) delete_audio: true @@ -65,13 +65,6 @@ CMD_exit: - "退出" - "关闭" -# plugin下的模块,可以通过配置,选择加载哪个模块,加载后对话支持相应的function调用 -# 系统默认已经记载“handle_exit_intent(退出识别)”、“play_music(音乐播放)”插件,请勿重复加载 -# 下面是加载查天气、角色切换的插件示例 -functions: - - change_role - - get_weather - # 具体处理时选择的模块(The module selected for specific processing) selected_module: # 语音活动检测模块,默认使用SileroVAD模型 @@ -94,14 +87,20 @@ selected_module: Intent: # 不使用意图识别 nointent: - # 不需要动 + # 不需要动type type: nointent intent_llm: - # 不需要动 + # 不需要动type type: intent_llm function_call: - # 不需要动 + # 不需要动type type: nointent + # plugins_func/functions下的模块,可以通过配置,选择加载哪个模块,加载后对话支持相应的function调用 + # 系统默认已经记载“handle_exit_intent(退出识别)”、“play_music(音乐播放)”插件,请勿重复加载 + # 下面是加载查天气、角色切换的插件示例 + functions: + - change_role + - get_weather Memory: mem0ai: diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index bba25371e..52596ba65 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -189,10 +189,6 @@ class ConnectionHandler: self.prompt = self.config["prompt"] if self.private_config: self.prompt = self.private_config.private_config.get("prompt", self.prompt) - # 赋予LLM时间观念 - if "{date_time}" in self.prompt: - date_time = time.strftime("%Y-%m-%d %H:%M", time.localtime()) - self.prompt = self.prompt.replace("{date_time}", date_time) self.dialogue.put(Message(role="system", content=self.prompt)) def change_system_prompt(self, prompt): @@ -200,9 +196,6 @@ class ConnectionHandler: # 找到原来的role==system,替换原来的系统提示 for m in self.dialogue.dialogue: if m.role == "system": - if "{date_time}" in self.prompt: - date_time = time.strftime("%Y-%m-%d %H:%M", time.localtime()) - self.prompt = self.prompt.replace("{date_time}", date_time) m.content = prompt async def _check_and_broadcast_auth_code(self): diff --git a/main/xiaozhi-server/core/handle/functionHandler.py b/main/xiaozhi-server/core/handle/functionHandler.py index a96291733..8d54fe8aa 100644 --- a/main/xiaozhi-server/core/handle/functionHandler.py +++ b/main/xiaozhi-server/core/handle/functionHandler.py @@ -49,10 +49,11 @@ class FunctionHandler: self.function_registry.register_function("handle_exit_intent") self.function_registry.register_function("play_music") self.function_registry.register_function("plugin_loader") + self.function_registry.register_function("get_time") def register_config_functions(self): """注册配置中的函数,可以不同客户端使用不同的配置""" - for func in self.config.get("functions", []): + for func in self.config["Intent"]["function_call"].get("functions", []): self.function_registry.register_function(func) def get_function(self, name): diff --git a/main/xiaozhi-server/core/utils/util.py b/main/xiaozhi-server/core/utils/util.py index 60b986653..4e2ebaf75 100644 --- a/main/xiaozhi-server/core/utils/util.py +++ b/main/xiaozhi-server/core/utils/util.py @@ -1,5 +1,6 @@ import os import json +from datetime import datetime import yaml import socket import subprocess diff --git a/main/xiaozhi-server/plugins_func/functions/get_time.py b/main/xiaozhi-server/plugins_func/functions/get_time.py new file mode 100644 index 000000000..1d141ed2c --- /dev/null +++ b/main/xiaozhi-server/plugins_func/functions/get_time.py @@ -0,0 +1,25 @@ +from datetime import datetime +from plugins_func.register import register_function, ToolType, ActionResponse, Action + +get_time_function_desc = { + "type": "function", + "function": { + "name": "get_time", + "description": "获取当前时间、日期、星期几", + "parameters": {} + } +} + + +@register_function('get_time', get_time_function_desc, ToolType.WAIT) +def get_time(): + """ + 获取当前时间、日期、星期几 + """ + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + current_date = now.strftime("%Y-%m-%d") + current_weekday = now.strftime("%A") + response_text = f"当前日期: {current_date},当前时间: {current_time},星期: {current_weekday}" + + return ActionResponse(Action.REQLLM, response_text, None) \ No newline at end of file