feat: Add text key option to CSVToDataComponent (#5935)
Enhance CSV to Data component by introducing a configurable text key parameter, allowing users to specify the column used for text extraction when converting CSV data to Data objects.
This commit is contained in:
parent
f6c8750d15
commit
fb0696c526
1 changed files with 7 additions and 1 deletions
|
|
@ -31,6 +31,12 @@ class CSVToDataComponent(Component):
|
||||||
display_name="CSV String",
|
display_name="CSV String",
|
||||||
info="Paste a CSV string directly to convert to a list of Data objects",
|
info="Paste a CSV string directly to convert to a list of Data objects",
|
||||||
),
|
),
|
||||||
|
MessageTextInput(
|
||||||
|
name="text_key",
|
||||||
|
display_name="Text Key",
|
||||||
|
info="The key to use for the text column. Defaults to 'text'.",
|
||||||
|
value="text",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
outputs = [
|
outputs = [
|
||||||
|
|
@ -66,7 +72,7 @@ class CSVToDataComponent(Component):
|
||||||
|
|
||||||
if csv_data:
|
if csv_data:
|
||||||
csv_reader = csv.DictReader(io.StringIO(csv_data))
|
csv_reader = csv.DictReader(io.StringIO(csv_data))
|
||||||
result = [Data(data=row) for row in csv_reader]
|
result = [Data(data=row, text_key=self.text_key) for row in csv_reader]
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
self.status = "The CSV data is empty."
|
self.status = "The CSV data is empty."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue