reformat
All checks were successful
Security Scan / dependency-check (pull_request) Successful in 35s
Security Scan / security (pull_request) Successful in 39s
Test Suite / lint (pull_request) Successful in 30s
Test Suite / test (3.11) (pull_request) Successful in 1m26s
Test Suite / build (pull_request) Successful in 37s

This commit is contained in:
2025-08-14 08:07:50 -07:00
parent 6a995635ac
commit 4867614474
5 changed files with 79 additions and 61 deletions

View File

@@ -24,14 +24,10 @@ class NDJSONParser:
documents.append(doc)
except json.JSONDecodeError as e:
raise json.JSONDecodeError(
f"Invalid JSON on line {line_num}: {e.msg}",
e.doc,
e.pos
f"Invalid JSON on line {line_num}: {e.msg}", e.doc, e.pos
)
except KeyError as e:
raise KeyError(
f"Missing required field {e} on line {line_num}"
)
raise KeyError(f"Missing required field {e} on line {line_num}")
except (TypeError, ValueError) as e:
raise ValueError(
f"Invalid data format on line {line_num}: {str(e)}"
@@ -52,15 +48,19 @@ class NDJSONParser:
# Validate embedding format
embedding = doc_dict["embedding"]
if not isinstance(embedding, list):
raise ValueError(f"Embedding must be a list, got {type(embedding).__name__}")
raise ValueError(
f"Embedding must be a list, got {type(embedding).__name__}"
)
if not embedding:
raise ValueError("Embedding cannot be empty")
# Check that all embedding values are numbers
for i, val in enumerate(embedding):
if not isinstance(val, (int, float)) or val != val: # NaN check
raise ValueError(f"Embedding contains invalid value at index {i}: {val}")
raise ValueError(
f"Embedding contains invalid value at index {i}: {val}"
)
return Document(
id=doc_dict["id"],

View File

@@ -25,7 +25,9 @@ class DataProcessingCallbacks:
processed_data = self.processor.process_upload(contents, filename)
if processed_data.error:
error_message = self._format_error_message(processed_data.error, filename)
error_message = self._format_error_message(
processed_data.error, filename
)
return (
{"error": processed_data.error},
error_message,
@@ -80,14 +82,18 @@ class DataProcessingCallbacks:
def _format_error_message(error: str, filename: str | None = None) -> str:
"""Format error message with helpful guidance for users."""
file_part = f" in file '{filename}'" if filename else ""
# Check for common error patterns and provide helpful messages
if "embedding" in error.lower() and ("key" in error.lower() or "required field" in error.lower()):
if "embedding" in error.lower() and (
"key" in error.lower() or "required field" in error.lower()
):
return (
f"❌ Missing 'embedding' field{file_part}. "
"Each line must contain an 'embedding' field with a list of numbers."
)
elif "text" in error.lower() and ("key" in error.lower() or "required field" in error.lower()):
elif "text" in error.lower() and (
"key" in error.lower() or "required field" in error.lower()
):
return (
f"❌ Missing 'text' field{file_part}. "
"Each line must contain a 'text' field with the document content."

View File

@@ -62,4 +62,3 @@ class UploadComponent:
color="danger",
className="mb-3",
)

View File

@@ -9,7 +9,8 @@ class AppLayout:
def create_layout(self):
return dbc.Container(
[self._create_header(), self._create_main_content()] + self._create_stores(),
[self._create_header(), self._create_main_content()]
+ self._create_stores(),
fluid=True,
)