diff --git a/backend/apps/webui/models/functions.py b/backend/apps/webui/models/functions.py index ac12ab9e3..91fbdb769 100644 --- a/backend/apps/webui/models/functions.py +++ b/backend/apps/webui/models/functions.py @@ -64,7 +64,6 @@ class FunctionResponse(BaseModel): class FunctionForm(BaseModel): id: str name: str - type: str content: str meta: FunctionMeta @@ -75,12 +74,13 @@ class FunctionsTable: self.db.create_tables([Function]) def insert_new_function( - self, user_id: str, form_data: FunctionForm + self, user_id: str, type: str, form_data: FunctionForm ) -> Optional[FunctionModel]: function = FunctionModel( **{ **form_data.model_dump(), "user_id": user_id, + "type": type, "updated_at": int(time.time()), "created_at": int(time.time()), } diff --git a/backend/apps/webui/routers/functions.py b/backend/apps/webui/routers/functions.py index 1021cc10a..ea5fde336 100644 --- a/backend/apps/webui/routers/functions.py +++ b/backend/apps/webui/routers/functions.py @@ -69,12 +69,12 @@ async def create_new_function( with open(function_path, "w") as function_file: function_file.write(form_data.content) - function_module = load_function_module_by_id(form_data.id) + function_module, function_type = load_function_module_by_id(form_data.id) FUNCTIONS = request.app.state.FUNCTIONS FUNCTIONS[form_data.id] = function_module - function = Functions.insert_new_function(user.id, form_data) + function = Functions.insert_new_function(user.id, function_type, form_data) function_cache_dir = Path(CACHE_DIR) / "functions" / form_data.id function_cache_dir.mkdir(parents=True, exist_ok=True) @@ -132,12 +132,12 @@ async def update_toolkit_by_id( with open(function_path, "w") as function_file: function_file.write(form_data.content) - function_module = load_function_module_by_id(id) + function_module, function_type = load_function_module_by_id(id) FUNCTIONS = request.app.state.FUNCTIONS FUNCTIONS[id] = function_module - updated = {**form_data.model_dump(exclude={"id"})} + updated = {**form_data.model_dump(exclude={"id"}), "type": function_type} print(updated) function = Functions.update_function_by_id(id, updated) diff --git a/backend/apps/webui/utils.py b/backend/apps/webui/utils.py index 64d116f11..3e075a8a8 100644 --- a/backend/apps/webui/utils.py +++ b/backend/apps/webui/utils.py @@ -33,9 +33,9 @@ def load_function_module_by_id(function_id): spec.loader.exec_module(module) print(f"Loaded module: {module.__name__}") if hasattr(module, "Pipe"): - return module.Pipe() + return module.Pipe(), "pipe" elif hasattr(module, "Filter"): - return module.Filter() + return module.Filter(), "filter" else: raise Exception("No Function class found") except Exception as e: diff --git a/src/lib/components/workspace/Functions.svelte b/src/lib/components/workspace/Functions.svelte index ebadce50c..aeb53bde0 100644 --- a/src/lib/components/workspace/Functions.svelte +++ b/src/lib/components/workspace/Functions.svelte @@ -74,7 +74,7 @@