feat(contentPlugin): 完成基本的内容函数调用功能

This commit is contained in:
RockChinQ
2023-07-28 19:03:02 +08:00
parent caa72fa40c
commit ae6994e241
11 changed files with 700 additions and 166 deletions
+37
View File
@@ -0,0 +1,37 @@
# 封装了function calling的一些支持函数
import logging
from pkg.plugin.host import __callable_functions__, __function_inst_map__
class ContentFunctionNotFoundError(Exception):
pass
def get_func_schema_list() -> list:
"""从plugin包中的函数结构中获取并处理成受GPT支持的格式"""
schemas = __callable_functions__
return schemas
def get_func(name: str) -> callable:
if name not in __function_inst_map__:
raise ContentFunctionNotFoundError("没有找到内容函数: {}".format(name))
return __function_inst_map__[name]
def get_func_schema(name: str) -> dict:
for func in __callable_functions__:
if func['name'] == name:
return func
raise ContentFunctionNotFoundError("没有找到内容函数: {}".format(name))
def execute_function(name: str, kwargs: dict) -> any:
"""执行函数调用"""
logging.debug("executing function: name='{}', kwargs={}".format(name, kwargs))
func = get_func(name)
return func(**kwargs)