Skip to content

Commit bcd37e6

Browse files
committed
cleanups
1 parent 63c26bd commit bcd37e6

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

backend/app/api/routes/evaluation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ async def upload_dataset(
170170

171171
# Normalize headers for case-insensitive matching
172172
clean_headers = {
173-
field.strip().lower(): field.strip() for field in csv_reader.fieldnames
173+
field.strip().lower(): field for field in csv_reader.fieldnames
174174
}
175175

176176
# Validate required headers (case-insensitive)
177177
if "question" not in clean_headers or "answer" not in clean_headers:
178178
raise HTTPException(
179179
status_code=422,
180180
detail=f"CSV must contain 'question' and 'answer' columns "
181-
f"(case-insensitive). Found columns: {csv_reader.fieldnames}",
181+
f"Found columns: {csv_reader.fieldnames}",
182182
)
183183

184184
# Get the actual column names from the CSV

backend/app/crud/evaluations/langfuse.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,23 +254,30 @@ def upload_dataset_to_langfuse_from_csv(
254254
# Parse CSV content
255255
csv_text = csv_content.decode("utf-8")
256256
csv_reader = csv.DictReader(io.StringIO(csv_text))
257-
csv_reader.fieldnames = [name.strip() for name in csv_reader.fieldnames]
258257

259-
# Validate CSV headers
260-
if (
261-
"question" not in csv_reader.fieldnames
262-
or "answer" not in csv_reader.fieldnames
263-
):
258+
# Normalize headers for case-insensitive matching
259+
# Note: We keep the original field name as value because
260+
# csv.DictReader uses original fieldnames as keys in row dictionaries
261+
clean_headers = {
262+
field.strip().lower(): field for field in csv_reader.fieldnames
263+
}
264+
265+
# Validate CSV headers (case-insensitive)
266+
if "question" not in clean_headers or "answer" not in clean_headers:
264267
raise ValueError(
265-
f"CSV must contain 'question' and 'answer' columns. "
268+
f"CSV must contain 'question' and 'answer' columns (case-insensitive). "
266269
f"Found columns: {csv_reader.fieldnames}"
267270
)
268271

272+
# Get the actual column names from the CSV
273+
question_col = clean_headers["question"]
274+
answer_col = clean_headers["answer"]
275+
269276
# Read all rows from CSV
270277
original_items = []
271278
for row in csv_reader:
272-
question = row.get("question", "").strip()
273-
answer = row.get("answer", "").strip()
279+
question = row.get(question_col, "").strip()
280+
answer = row.get(answer_col, "").strip()
274281

275282
if not question or not answer:
276283
logger.warning(

0 commit comments

Comments
 (0)