From 3afd66d50f50dd2761f28cb3bfd20b8ede6cc468 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 4 Sep 2024 18:59:50 +0200 Subject: [PATCH] fix: tools & functions import --- backend/open_webui/apps/webui/utils.py | 30 ++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/apps/webui/utils.py b/backend/open_webui/apps/webui/utils.py index 6b66258da..a5ccad831 100644 --- a/backend/open_webui/apps/webui/utils.py +++ b/backend/open_webui/apps/webui/utils.py @@ -54,9 +54,20 @@ def load_toolkit_module_by_id(toolkit_id): if not os.path.exists(toolkit_path): tool = Tools.get_tool_by_id(toolkit_id) - if tool: + + if tool and not os.path.exists(f"{toolkit_path}.error"): with open(toolkit_path, "w") as file: - file.write(tool.content) + content = tool.content + content = content.replace("from utils", "from open_webui.utils") + content = content.replace("from apps", "from open_webui.apps") + content = content.replace("from main", "from open_webui.main") + content = content.replace("from config", "from open_webui.config") + + if tool.content != content: + print(f"Replaced imports for: {toolkit_id}") + Tools.update_tool_by_id(toolkit_id, {"content": content}) + + file.write(content) else: raise Exception(f"Toolkit not found: {toolkit_id}") @@ -84,9 +95,20 @@ def load_function_module_by_id(function_id): if not os.path.exists(function_path): function = Functions.get_function_by_id(function_id) - if function: + + if function and not os.path.exists(f"{function_path}.error"): with open(function_path, "w") as file: - file.write(function.content) + content = function.content + content = content.replace("from utils", "from open_webui.utils") + content = content.replace("from apps", "from open_webui.apps") + content = content.replace("from main", "from open_webui.main") + content = content.replace("from config", "from open_webui.config") + + if function.content != content: + print(f"Replaced imports for: {function_id}") + Functions.update_function_by_id(function_id, {"content": content}) + + file.write(content) else: raise Exception(f"Function not found: {function_id}")