From 37853d6a26a89845d69f52d9db0f951cc06a23d6 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 25 Oct 2024 14:36:44 -0700 Subject: [PATCH] enh: more robust tool calling --- backend/open_webui/main.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index d1978425a..22cdaa3b0 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -439,9 +439,15 @@ async def chat_completion_tools_handler( tool_function_params = result.get("parameters", {}) try: - tool_output = await tools[tool_function_name]["callable"]( - **tool_function_params - ) + tool_function = tools[tool_function_name]["callable"] + sig = inspect.signature(tool_function) + tool_function_params = { + k: v + for k, v in tool_function_params.items() + if k in sig.parameters + } + tool_output = await tool_function(**tool_function_params) + except Exception as e: tool_output = str(e)