diff --git a/nonebot_plugin_marshoai/azure.py b/nonebot_plugin_marshoai/azure.py index 96c2dc83..c55a6b42 100644 --- a/nonebot_plugin_marshoai/azure.py +++ b/nonebot_plugin_marshoai/azure.py @@ -337,6 +337,10 @@ async def marsho( ) # await UniMessage(str(response)).send() choice = response.choices[0] + # Sprint(choice) + # 当tool_calls非空时,将finish_reason设置为TOOL_CALLS + if choice.message.tool_calls != None: + choice["finish_reason"] = CompletionsFinishReason.TOOL_CALLS if choice["finish_reason"] == CompletionsFinishReason.STOPPED: # 当对话成功时,将dict的上下文添加到上下文类中 context.append( @@ -379,6 +383,9 @@ async def marsho( function_args = json.loads( tool_call.function.arguments.replace("'", '"') ) + # 删除args的placeholder参数 + if "placeholder" in function_args: + del function_args["placeholder"] logger.info( f"调用函数 {tool_call.function.name.replace('-', '.')}\n参数:" + "\n".join([f"{k}={v}" for k, v in function_args.items()]) @@ -414,15 +421,21 @@ async def marsho( ) func_return = f"未找到函数 {tool_call.function.name.replace('-', '.')}" tool_msg.append( - ToolMessage(tool_call_id=tool_call.id, content=func_return) # type: ignore + ToolMessage(tool_call_id=tool_call.id, content=func_return).as_dict() # type: ignore ) + request_msg = context_msg + [UserMessage(content=usermsg).as_dict()] + tool_msg # type: ignore response = await make_chat( client=client, model_name=model_name, - msg=context_msg + [UserMessage(content=usermsg)] + tool_msg, # type: ignore - tools=tools.get_tools_list(), + msg=request_msg, # type: ignore + tools=( + tools_lists if tools_lists else None + ), # TODO 临时追加函数,后期优化 ) choice = response.choices[0] + # 当tool_calls非空时,将finish_reason设置为TOOL_CALLS + if choice.message.tool_calls != None: + choice["finish_reason"] = CompletionsFinishReason.TOOL_CALLS if choice["finish_reason"] == CompletionsFinishReason.STOPPED: # 对话成功 添加上下文 diff --git a/nonebot_plugin_marshoai/plugin/func_call/caller.py b/nonebot_plugin_marshoai/plugin/func_call/caller.py index f9de05a5..1a05971e 100644 --- a/nonebot_plugin_marshoai/plugin/func_call/caller.py +++ b/nonebot_plugin_marshoai/plugin/func_call/caller.py @@ -163,7 +163,13 @@ class Caller: "parameters": { "type": "object", "properties": { - key: value.data() for key, value in self._parameters.items() + **{ + key: value.data() for key, value in self._parameters.items() + }, + "placeholder": { + "type": "string", + "description": "占位符,用于显示在对话框中", # 为保证兼容性而设置的无用参数 + }, }, }, "required": [ diff --git a/nonebot_plugin_marshoai/util.py b/nonebot_plugin_marshoai/util.py index 9cda5e3e..929f694e 100755 --- a/nonebot_plugin_marshoai/util.py +++ b/nonebot_plugin_marshoai/util.py @@ -95,6 +95,7 @@ async def make_chat( messages=msg, model=model_name, tools=tools, + tool_choice="auto", temperature=config.marshoai_temperature, max_tokens=config.marshoai_max_tokens, top_p=config.marshoai_top_p,