-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DynamicOutputComponent with configurable outputs based on input
- Loading branch information
1 parent
0bc3e19
commit 2b2635d
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# from langflow.field_typing import Data | ||
from typing import Any | ||
|
||
from langflow.custom import Component | ||
from langflow.io import BoolInput, MessageTextInput, Output | ||
from langflow.schema import Data | ||
|
||
|
||
class DynamicOutputComponent(Component): | ||
display_name = "Dynamic Output Component" | ||
description = "Use as a template to create your own component." | ||
documentation: str = "http://docs.langflow.org/components/custom" | ||
icon = "custom_components" | ||
name = "DynamicOutputComponent" | ||
|
||
inputs = [ | ||
MessageTextInput(name="input_value", display_name="Input Value", value="Hello, World!"), | ||
BoolInput(name="show_output", display_name="Show Output", value=True, real_time_refresh=True), | ||
] | ||
|
||
outputs = [ | ||
Output(display_name="Output", name="output", method="build_output"), | ||
] | ||
|
||
def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any): | ||
if field_name == "show_output": | ||
if field_value: | ||
frontend_node["outputs"].append( | ||
Output(display_name="Tool Output", name="tool_output", method="build_output") | ||
) | ||
else: | ||
# remove the output | ||
frontend_node["outputs"] = [ | ||
output for output in frontend_node["outputs"] if output["name"] != "tool_output" | ||
] | ||
return frontend_node | ||
|
||
def build_output(self) -> Data: | ||
data = Data(value=self.input_value) | ||
self.status = data | ||
return data |