Load local text files of any kind - code, txts, json etc (#1076)

This commit is contained in:
Sidharth Mohanty
2023-12-29 22:26:24 +05:30
committed by GitHub
parent 6df63d9ca7
commit a544b4d3ff
6 changed files with 43 additions and 5 deletions

View File

@@ -305,7 +305,7 @@ def detect_datatype(source: Any) -> DataType:
if source.endswith(".txt"):
logging.debug(f"Source of `{formatted_source}` detected as `text`.")
return DataType.TEXT
return DataType.TEXT_FILE
if source.endswith(".pdf"):
logging.debug(f"Source of `{formatted_source}` detected as `pdf_file`.")
@@ -331,6 +331,10 @@ def detect_datatype(source: Any) -> DataType:
logging.debug(f"Source of `{formatted_source}` detected as `json`.")
return DataType.JSON
if os.path.exists(source) and is_readable(open(source).read()):
logging.debug(f"Source of `{formatted_source}` detected as `text_file`.")
return DataType.TEXT_FILE
# If the source is a valid file, that's not detectable as a type, an error is raised.
# It does not fallback to text.
raise ValueError(