mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-19 13:23:16 +08:00
Dev fix csv loader (#3404)
* fix: csv loader only load one column * csv data merge with col name
This commit is contained in:
parent
d78b14721c
commit
07b7c966ed
@ -59,8 +59,13 @@ class FilteredCSVLoader(CSVLoader):
|
||||
docs = []
|
||||
csv_reader = csv.DictReader(csvfile, **self.csv_args) # type: ignore
|
||||
for i, row in enumerate(csv_reader):
|
||||
if self.columns_to_read[0] in row:
|
||||
content = row[self.columns_to_read[0]]
|
||||
content = []
|
||||
for col in self.columns_to_read:
|
||||
if col in row:
|
||||
content.append(f'{col}:{str(row[col])}')
|
||||
else:
|
||||
raise ValueError(f"Column '{self.columns_to_read[0]}' not found in CSV file.")
|
||||
content = '\n'.join(content)
|
||||
# Extract the source if available
|
||||
source = (
|
||||
row.get(self.source_column, None)
|
||||
@ -75,7 +80,5 @@ class FilteredCSVLoader(CSVLoader):
|
||||
|
||||
doc = Document(page_content=content, metadata=metadata)
|
||||
docs.append(doc)
|
||||
else:
|
||||
raise ValueError(f"Column '{self.columns_to_read[0]}' not found in CSV file.")
|
||||
|
||||
return docs
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user