Skip to content

Commit 81d361f

Browse files
committed
fix #4097
1 parent fd05b0b commit 81d361f

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

astrbot/core/star/context.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -368,25 +368,10 @@ async def send_message(
368368
def add_llm_tools(self, *tools: FunctionTool) -> None:
369369
"""添加 LLM 工具。"""
370370
tool_name = {tool.name for tool in self.provider_manager.llm_tools.func_list}
371-
module_path = ""
372371
for tool in tools:
373-
if not module_path:
374-
_parts = []
375-
module_part = tool.__module__.split(".")
376-
flags = ["packages", "plugins"]
377-
for i, part in enumerate(module_part):
378-
_parts.append(part)
379-
if part in flags and i + 1 < len(module_part):
380-
_parts.append(module_part[i + 1])
381-
break
382-
tool.handler_module_path = ".".join(_parts)
383-
module_path = tool.handler_module_path
384-
else:
385-
tool.handler_module_path = module_path
386-
logger.info(
387-
f"plugin(module_path {module_path}) added LLM tool: {tool.name}"
388-
)
389-
372+
# Set `handler_module_path` moved to astrbot/core/star/star_manager.py,
373+
# search `ft.__module__ == metadata.module_path`
374+
logger.info(f"plugin added LLM tool: {tool.name} ({tool.__module__})")
390375
if tool.name in tool_name:
391376
logger.warning("替换已存在的 LLM 工具: " + tool.name)
392377
self.provider_manager.llm_tools.remove_func(tool.name)

astrbot/core/star/star_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ async def load(self, specified_module_path=None, specified_dir_name=None):
524524
ft.handler,
525525
metadata.star_cls, # type: ignore
526526
)
527+
elif ft.__module__ == metadata.module_path:
528+
ft.handler_module_path = metadata.module_path
527529
if ft.name in inactivated_llm_tools:
528530
ft.active = False
529531

0 commit comments

Comments
 (0)