xiaozhi-esp32-server/main/xiaozhi-server/plugins_func/functions/plugin_loader.py
欣南科技 2e182626b9
Function插件自动装载 (#351)
* function call功能完善,增加天气查询,支持插件式扩展

* 增加角色切换功能,通过切换system提示词,修改角色认知

* 增加插件管理系统,可以通过语音加载和卸载插件

* docs: 添加命令操作 (#329)

* docs: 添加命令操作

* feat: 添加 docker-setup.sh 脚本以简化服务端部署

- 新增 docker-setup.sh 脚本,自动创建目录结构、下载语音识别模型和配置文件,并检查文件完整性。
- 更新 Deployment.md 文档,提供一键执行脚本的说明和使用示例。

* docs: 更新 Deployment.md,添加环境访问 GitHub 的注意事项

* refactor: 更新 docker-setup.sh 脚本以支持多操作系统下载命令

- 修改脚本以检测操作系统类型,并根据不同系统选择合适的下载命令(curl 或 wget)。
- 优化错误处理,确保在下载失败时提供清晰的提示信息。
- 更新 Deployment.md 文档,调整懒人脚本的使用说明,增加手动部署的步骤。

* Update docker-setup.sh

* Update docker-setup.sh

---------

Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com>

* update:优化插件加载的配置提示

* update:增加自动安装脚本的操作说明

* update:优化插件配置,去掉旧版本的时间设定

---------

Co-authored-by: 玄凤科技 <eric230308@gmail.com>
Co-authored-by: TinsFox <fox@tinsfox.com>
Co-authored-by: hrz <1710360675@qq.com>
2025-03-15 11:48:14 +08:00

51 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from plugins_func.register import register_function,ToolType, ActionResponse, Action
from config.logger import setup_logging
TAG = __name__
logger = setup_logging()
plugin_loader_function_desc = {
"type": "function",
"function": {
"name": "plugin_loader",
"description": "当用户想加载或卸载插件/function时,调用此函数:支持的插件列表为[plugins]",
"parameters": {
"type": "object",
"properties": {
"oper": {
"type": "string",
"description": "load or unload"
},
"name":{
"type": "string",
"description": "要加载或卸载的插件名字"
}
},
"required": ["oper","name"]
}
}
}
@register_function('plugin_loader', plugin_loader_function_desc, ToolType.SYSTEM_CTL)
def plugin_loader(conn, oper: str, name: str):
"""插件加载"""
if oper not in ["load", "unload"]:
return ActionResponse(action=Action.RESPONSE, result="插件操作失败", response="不支持的操作")
cur_support = conn.func_handler.current_support_functions()
if oper == "load":
if name in cur_support:
return ActionResponse(action=Action.RESPONSE, result="插件加载失败", response=f"{name}插件已加载,无需重复加载")
func = conn.func_handler.function_registry.register_function(name)
if not func:
return ActionResponse(action=Action.RESPONSE, result="插件加载失败", response="插件未找到")
res = f"{name}插件加载成功"
else:
if name not in cur_support:
return ActionResponse(action=Action.RESPONSE, result="插件卸载失败", response=f"{name}插件未加载")
bOK = conn.func_handler.function_registry.unregister_function(name)
if not bOK:
return ActionResponse(action=Action.RESPONSE, result="插件卸载失败", response="插件未找到")
res = f"{name}插件卸载成功"
conn.func_handler.upload_functions_desc()
return ActionResponse(action=Action.RESPONSE, result="插件操作成功", response=res)