docpipe / src /agents /text_agent.py
NandiniKodali988
initial implementation - pdf + chromadb indexing
1c484d0
Raw History Blame Contribute Delete
673 Bytes
from pathlib import Path
class TextAgent:
SUPPORTED_EXTENSIONS = {".txt", ".md", ".rst"}
def process(self, file_path: Path) -> dict:
content = file_path.read_text(encoding="utf-8", errors="replace")
if file_path.suffix == ".txt":
title = file_path.stem.replace("_", " ").replace("-", " ")
markdown = f"# {title}\n\n{content}"
else:
markdown = content
return {
"markdown": markdown,
"metadata": {
"source_file": str(file_path),
"file_type": file_path.suffix.lstrip("."),
"title": file_path.stem,
},
}