fixed types

This commit is contained in:
Lorenze Jay
2024-12-03 10:12:37 -08:00
parent 543ebbf3a4
commit aab05388d5
5 changed files with 32 additions and 6 deletions

View File

@@ -37,6 +37,9 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource):
if not isinstance(paths, list):
raise ValueError("file_path must be a Path or a list of Paths")
# Ensure all paths are Path objects
paths = [Path(path) if isinstance(path, str) else path for path in paths]
for path in paths:
if not path.exists():
self._logger.log(

View File

@@ -12,9 +12,9 @@ class ExcelKnowledgeSource(BaseFileKnowledgeSource):
pd = self._import_dependencies()
if isinstance(self.file_path, list):
file_path = self.file_path[0]
file_path = self.convert_to_path(self.file_path[0])
else:
file_path = self.file_path
file_path = self.convert_to_path(self.file_path)
df = pd.read_excel(file_path)
content = df.to_csv(index=False)

View File

@@ -15,6 +15,7 @@ class JSONKnowledgeSource(BaseFileKnowledgeSource):
content: Dict[Path, str] = {}
for path in paths:
path = self.convert_to_path(path)
with open(path, "r", encoding="utf-8") as json_file:
data = json.load(json_file)
content[path] = self._json_to_text(data)

View File

@@ -13,6 +13,7 @@ class TextFileKnowledgeSource(BaseFileKnowledgeSource):
paths = [self.file_path] if isinstance(self.file_path, Path) else self.file_path
content = {}
for path in paths:
path = Path(path)
with open(path, "r", encoding="utf-8") as f:
content[path] = f.read()
return content