tech-support-helpdesk-chatbot / service /data_loader_service.py
Sandei's picture
hope it works
d74109c
raw
history blame contribute delete
516 Bytes
import csv
from pathlib import Path
class CSVDataLoader:
def __init__(self, filename: str):
self.path = Path(filename)
def load_qa_pairs(self) -> list[str]:
docs = []
with self.path.open(encoding="utf-8") as f:
reader = csv.DictReader(f)
for row in reader:
q = row.get("question", "").strip()
a = row.get("answer", "").strip()
if q and a:
docs.append(f"Q: {q}\nA: {a}")
return docs