mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-25 08:33:53 +08:00
Merge pull request #3176 from xinnan-tech/perf-tool-add-online-search
Perf:新增联网搜索工具类、修复新闻描述配置获取源问题
This commit is contained in:
@@ -87,6 +87,11 @@ class ServerPluginExecutor(ToolExecutor):
|
||||
func_item.description["function"][
|
||||
"description"
|
||||
] = fun_description
|
||||
|
||||
# 新闻插件:根据配置更新新闻源参数描述
|
||||
if func_name == "get_news_from_newsnow":
|
||||
self._init_news_source_description(func_item, func_name)
|
||||
|
||||
tools[func_name] = ToolDefinition(
|
||||
name=func_name,
|
||||
description=func_item.description,
|
||||
@@ -98,3 +103,20 @@ class ServerPluginExecutor(ToolExecutor):
|
||||
def has_tool(self, tool_name: str) -> bool:
|
||||
"""检查是否有指定的服务端插件工具"""
|
||||
return tool_name in all_function_registry
|
||||
|
||||
def _init_news_source_description(self, func_item, func_name):
|
||||
"""根据连接配置初始化新闻工具的参数描述"""
|
||||
news_sources = (
|
||||
self.config.get("plugins", {})
|
||||
.get(func_name, {})
|
||||
.get("news_sources", "")
|
||||
)
|
||||
if not news_sources:
|
||||
news_sources = "澎湃新闻;百度热搜;财联社"
|
||||
sources_str = news_sources.replace(";", "、")
|
||||
try:
|
||||
func_item.description["function"]["parameters"]["properties"]["source"][
|
||||
"description"
|
||||
] = f"新闻源的标准中文名称,例如{sources_str}等。可选参数,如果不提供则使用默认新闻源"
|
||||
except (KeyError, TypeError):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user