From 63c709ee1d172b155b9ea57febadd133af003c31 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 22 Feb 2024 16:38:01 -0300 Subject: [PATCH] Add PythonFunctionComponent to langflow utilities --- .../components/utilities/PythonFunction.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/backend/langflow/components/utilities/PythonFunction.py 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