From ac9849013dcaeb30e023eebeafe3e07429ed943d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 22 Feb 2024 18:04:55 -0300 Subject: [PATCH] Add RunnableExecutor component --- .../components/utilities/RunnableExecutor.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/backend/langflow/components/utilities/RunnableExecutor.py diff --git a/src/backend/langflow/components/utilities/RunnableExecutor.py b/src/backend/langflow/components/utilities/RunnableExecutor.py new file mode 100644 index 000000000..f83f352b4 --- /dev/null +++ b/src/backend/langflow/components/utilities/RunnableExecutor.py @@ -0,0 +1,42 @@ +from langchain_core.runnables import Runnable + +from langflow import CustomComponent +from langflow.field_typing import Text + + +class RunnableExecComponent(CustomComponent): + documentation: str = "http://docs.langflow.org/components/custom" + display_name = "Runnable Executor" + beta = True + + def build_config(self): + return { + "input_key": { + "display_name": "Input Key", + "info": "The key to use for the input.", + }, + "inputs": { + "display_name": "Inputs", + "info": "The inputs to pass to the runnable.", + }, + "runnable": { + "display_name": "Runnable", + "info": "The runnable to execute.", + }, + "output_key": { + "display_name": "Output Key", + "info": "The key to use for the output.", + }, + } + + def build( + self, + input_key: str, + inputs: str, + runnable: Runnable, + output_key: str = "output", + ) -> Text: + result = runnable.invoke({input_key: inputs}) + result = result.get(output_key) + self.status = result + return result