From dced59cef849f8ff14b1b9dde4c476624bc52a62 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 8 Mar 2024 17:07:44 -0300 Subject: [PATCH] Refactor file parsing in FileComponent --- src/backend/langflow/components/data/File.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/components/data/File.py b/src/backend/langflow/components/data/File.py index dbc14abc4..4c4e42de4 100644 --- a/src/backend/langflow/components/data/File.py +++ b/src/backend/langflow/components/data/File.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional from langflow import CustomComponent -from langflow.base.data.utils import parse_file_to_record +from langflow.base.data.utils import TEXT_FILE_TYPES, parse_text_file_to_record from langflow.schema import Record @@ -25,4 +25,7 @@ class FileComponent(CustomComponent): silent_errors: bool = False, ) -> Optional[Record]: resolved_path = self.resolve_path(path) - return parse_file_to_record(resolved_path, silent_errors) + extension = resolved_path.split(".")[-1] + if extension not in TEXT_FILE_TYPES: + raise ValueError(f"Unsupported file type: {extension}") + return parse_text_file_to_record(resolved_path, silent_errors)