mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-02-07 15:38:27 +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,23 +59,26 @@ class FilteredCSVLoader(CSVLoader):
|
|||||||
docs = []
|
docs = []
|
||||||
csv_reader = csv.DictReader(csvfile, **self.csv_args) # type: ignore
|
csv_reader = csv.DictReader(csvfile, **self.csv_args) # type: ignore
|
||||||
for i, row in enumerate(csv_reader):
|
for i, row in enumerate(csv_reader):
|
||||||
if self.columns_to_read[0] in row:
|
content = []
|
||||||
content = row[self.columns_to_read[0]]
|
for col in self.columns_to_read:
|
||||||
# Extract the source if available
|
if col in row:
|
||||||
source = (
|
content.append(f'{col}:{str(row[col])}')
|
||||||
row.get(self.source_column, None)
|
else:
|
||||||
if self.source_column is not None
|
raise ValueError(f"Column '{self.columns_to_read[0]}' not found in CSV file.")
|
||||||
else self.file_path
|
content = '\n'.join(content)
|
||||||
)
|
# Extract the source if available
|
||||||
metadata = {"source": source, "row": i}
|
source = (
|
||||||
|
row.get(self.source_column, None)
|
||||||
|
if self.source_column is not None
|
||||||
|
else self.file_path
|
||||||
|
)
|
||||||
|
metadata = {"source": source, "row": i}
|
||||||
|
|
||||||
for col in self.metadata_columns:
|
for col in self.metadata_columns:
|
||||||
if col in row:
|
if col in row:
|
||||||
metadata[col] = row[col]
|
metadata[col] = row[col]
|
||||||
|
|
||||||
doc = Document(page_content=content, metadata=metadata)
|
doc = Document(page_content=content, metadata=metadata)
|
||||||
docs.append(doc)
|
docs.append(doc)
|
||||||
else:
|
|
||||||
raise ValueError(f"Column '{self.columns_to_read[0]}' not found in CSV file.")
|
|
||||||
|
|
||||||
return docs
|
return docs
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user