Add RunnableExecutor component

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-22 18:04:55 -03:00
commit ac9849013d

View file

@ -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