Dynamic Custom Component #5364
Replies: 1 comment 2 replies
-
Hey there, @noodleslove! I'm here to help you out while you wait for a human maintainer. Let's tackle this issue together! Yes, it is possible to create a custom component that takes a JSON input, parses it, and dynamically adds additional input fields based on the JSON structure. You can use a class similar to the from langflow.custom import Component
from langflow.io import StrInput, Output
from langflow.schema import Data
import json
class DynamicInputComponent(Component):
display_name = "Dynamic Input Component"
description = "Parses JSON input and dynamically adds input fields."
inputs = [
StrInput(name="json_input", display_name="JSON Input", value="{}", input_types=["Data"]),
]
outputs = [
Output(display_name="Output", name="output", method="build_output"),
]
async def build_output(self) -> Data:
try:
json_data = json.loads(self.json_input)
# Logic to dynamically add input fields based on json_data
for input_field in json_data.get("inputs", []):
# Add logic to create input fields dynamically
print(f"Name: {input_field['name']}, Type: {input_field['type']}")
self.status = "Inputs created successfully"
return Data(value=json_data)
except json.JSONDecodeError:
self.status = "Invalid JSON input"
return Data(value={}) This component takes a JSON string as input, parses it, and can be extended to dynamically create input fields based on the parsed JSON structure [1]. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
Is it possible to create a custom component that takes in a JSON input, then parse the JSON object and add additional input fields to itself. For instance, this component initially has one input fields which should take in a JSON object.
Once the component receives the JSON input, it adds additional "message" and "name" to its input fields. Is it possible to do this?
Beta Was this translation helpful? Give feedback.
All reactions