多轮对话使用插件

This commit is contained in:
tuyang.yhj
2023-05-14 20:45:03 +08:00
parent 311ae7ada5
commit 1b72dc6605
9 changed files with 175 additions and 86 deletions

View File

@@ -45,6 +45,7 @@ def execute_ai_response_json(
except (json.JSONDecodeError, ValueError, AttributeError) as e:
raise NotCommands("非可执行命令结构")
command_name, arguments = get_command(assistant_reply_json)
if cfg.speak_mode:
say_text(f"I want to execute {command_name}")
@@ -105,11 +106,16 @@ def execute_command(
or command_name == command["name"].lower()
):
try:
# 删除非定义参数
diff_ags = list(set(arguments.keys()).difference(set(command['args'].keys())))
for arg_name in arguments.keys():
if arg_name in diff_ags:
del arguments[arg_name]
print(str(arguments))
return command["function"](**arguments)
except Exception as e:
return f"Error: {str(e)}"
raise NotCommands("非可用命令" + command)
raise NotCommands("非可用命令" + command_name)
def get_command(response_json: Dict):

View File

@@ -1,3 +1,5 @@
class NotCommands(Exception):
def __init__(self, message):
super().__init__(message)
self.message = message