diff --git a/src/backend/langflow/components/utilities/PythonFunction.py b/src/backend/langflow/components/utilities/PythonFunction.py new file mode 100644 index 000000000..fdbc40cbd --- /dev/null +++ b/src/backend/langflow/components/utilities/PythonFunction.py @@ -0,0 +1,24 @@ +from typing import Callable + +from langflow import CustomComponent +from langflow.field_typing import Code +from langflow.interface.custom.utils import get_function + + +class PythonFunctionComponent(CustomComponent): + display_name = "Python Function" + description = "Define a Python function." + + def build_config(self): + return { + "function_code": { + "display_name": "Code", + "info": "The code for the function.", + "show": True, + }, + } + + def build(self, function_code: Code) -> Callable: + self.status = function_code + func = get_function(function_code) + return func