From 85dbb24f3acdee4f0602f3e7310526a6195eb42d Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 12 Mar 2025 23:37:24 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=87=8D=E8=BD=BD=E6=8F=92=E4=BB=B6=E6=97=B6=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E5=8F=AF=E8=83=BD=E5=A4=9A=E6=AC=A1=E5=AE=B6?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/provider/func_tool_manager.py | 11 +++++++---- astrbot/core/star/register/star_handler.py | 2 -- astrbot/core/star/star_manager.py | 4 +--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/astrbot/core/provider/func_tool_manager.py b/astrbot/core/provider/func_tool_manager.py index 0022d2773..42b88cae2 100644 --- a/astrbot/core/provider/func_tool_manager.py +++ b/astrbot/core/provider/func_tool_manager.py @@ -2,7 +2,7 @@ import json import textwrap from typing import Dict, List, Awaitable from dataclasses import dataclass - +from astrbot import logger @dataclass class FuncTool: @@ -46,14 +46,16 @@ class FuncCall: desc: str, handler: Awaitable, ) -> None: - """ - 为函数调用(function-calling / tools-use)添加工具。 + """添加函数调用工具 @param name: 函数名 @param func_args: 函数参数列表,格式为 [{"type": "string", "name": "arg_name", "description": "arg_description"}, ...] @param desc: 函数描述 @param func_obj: 处理函数 """ + # check if the tool has been added before + self.remove_func(name) + params = { "type": "object", # hard-coded here "properties": {}, @@ -70,13 +72,14 @@ class FuncCall: handler=handler, ) self.func_list.append(_func) + logger.info(f"添加了函数调用工具({len(self.func_list)}): {name} - {desc}") def remove_func(self, name: str) -> None: """ 删除一个函数调用工具。 """ for i, f in enumerate(self.func_list): - if f["name"] == name: + if f.name == name: self.func_list.pop(i) break diff --git a/astrbot/core/star/register/star_handler.py b/astrbot/core/star/register/star_handler.py index 4e2f9d176..86620cae6 100644 --- a/astrbot/core/star/register/star_handler.py +++ b/astrbot/core/star/register/star_handler.py @@ -360,8 +360,6 @@ def register_llm_tool(name: str = None): ) md = get_handler_or_create(awaitable, EventType.OnCallingFuncToolEvent) llm_tools.add_func(llm_tool_name, args, docstring.description, md.handler) - - logger.debug(f"LLM 函数工具 {llm_tool_name} 已注册") return awaitable return decorator diff --git a/astrbot/core/star/star_manager.py b/astrbot/core/star/star_manager.py index 4a7938605..9fa27798b 100644 --- a/astrbot/core/star/star_manager.py +++ b/astrbot/core/star/star_manager.py @@ -485,7 +485,7 @@ class PluginManager: for handler in star_handlers_registry.get_handlers_by_module_name( plugin_module_path ): - logger.debug(f"unbind handler {handler.handler_name} from {plugin_name}") + logger.info(f"移除了插件 {plugin_name} 的处理函数 {handler.handler_name} ({len(star_handlers_registry)})") star_handlers_registry.remove(handler) keys_to_delete = [ k @@ -493,8 +493,6 @@ class PluginManager: if k.startswith(plugin_module_path) ] for k in keys_to_delete: - v = star_handlers_registry.star_handlers_map[k] - logger.debug(f"unbind handler {v.handler_name} from {plugin_name} (map)") try: del star_handlers_registry.star_handlers_map[k] except KeyError: