mirror of
https://github.com/tcsenpai/agenticSeek.git
synced 2025-06-06 11:05:26 +00:00
feat: better fileFinder read
This commit is contained in:
parent
ed76c8415b
commit
f17dc0550b
@ -38,12 +38,13 @@ class FileFinder(Tools):
|
|||||||
Returns:
|
Returns:
|
||||||
str: The content of the file in markdown format
|
str: The content of the file in markdown format
|
||||||
"""
|
"""
|
||||||
|
mime_type, _ = mimetypes.guess_type(file_path)
|
||||||
|
if mime_type:
|
||||||
|
if mime_type.startswith(('image/', 'video/', 'audio/')):
|
||||||
|
return "can't read file type: image, video, or audio files are not supported."
|
||||||
content_raw = self.read_file(file_path)
|
content_raw = self.read_file(file_path)
|
||||||
language = ["python", "bash", "javascript", "html", "css", "json"]
|
|
||||||
if "text" in file_type:
|
if "text" in file_type:
|
||||||
content = content_raw
|
content = content_raw
|
||||||
elif any(lang in file_type for lang in language):
|
|
||||||
content = content_raw
|
|
||||||
elif "pdf" in file_type:
|
elif "pdf" in file_type:
|
||||||
from pypdf import PdfReader
|
from pypdf import PdfReader
|
||||||
reader = PdfReader(file_path)
|
reader = PdfReader(file_path)
|
||||||
@ -51,7 +52,7 @@ class FileFinder(Tools):
|
|||||||
elif "binary" in file_type:
|
elif "binary" in file_type:
|
||||||
content = content_raw.decode('utf-8', errors='replace')
|
content = content_raw.decode('utf-8', errors='replace')
|
||||||
else:
|
else:
|
||||||
content = f"Can't read file: "
|
content = content_raw
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def get_file_info(self, file_path: str) -> str:
|
def get_file_info(self, file_path: str) -> str:
|
||||||
@ -178,7 +179,7 @@ if __name__ == "__main__":
|
|||||||
tool = FileFinder()
|
tool = FileFinder()
|
||||||
result = tool.execute(["""
|
result = tool.execute(["""
|
||||||
action=read
|
action=read
|
||||||
name=cover_letter_martin_legrand.pdf
|
name=tools.py
|
||||||
"""], False)
|
"""], False)
|
||||||
print("Execution result:")
|
print("Execution result:")
|
||||||
print(result)
|
print(result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user