Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

Convert BibTeX in shared direct text ingestion after #1371

Bingxi Zhao (Frank)19618d859821
diff --git a/deeptutor/services/rag/file_routing.py b/deeptutor/services/rag/file_routing.py
index 2333506f6..24c57a981 100644
--- a/deeptutor/services/rag/file_routing.py
+++ b/deeptutor/services/rag/file_routing.py
@@ -294,12 +294,20 @@ class FileTypeRouter:
for encoding in cls.TEXT_DECODING_CANDIDATES:
try:
with open(file_path, "r", encoding=encoding) as f:
- return f.read()
+ text = f.read()
+ break
except UnicodeDecodeError:
continue
- with open(file_path, "rb") as f:
- return f.read().decode("utf-8", errors="replace")
+ else:
+ with open(file_path, "rb") as f:
+ text = f.read().decode("utf-8", errors="replace")
+
+ if Path(file_path).suffix.lower() == ".bib":
+ from deeptutor.utils.bibtex_converter import bibtex_to_markdown
+
+ return bibtex_to_markdown(text, Path(file_path).stem)
+ return text
@classmethod
def needs_parser(cls, file_path: str) -> bool:
diff --git a/tests/services/rag/test_file_routing.py b/tests/services/rag/test_file_routing.py
index c9a75dfb8..8847a9524 100644
--- a/tests/services/rag/test_file_routing.py
+++ b/tests/services/rag/test_file_routing.py
@@ -214,3 +214,12 @@ class TestReadTextFile:
path.write_bytes("中文测试".encode("gbk"))
content = asyncio.run(FileTypeRouter.read_text_file(str(path)))
assert "中文" in content
+
+
+def test_bibtex_uses_readable_reference_text_in_direct_rag_route(tmp_path: Path) -> None:
+ path = tmp_path / "references.bib"
+ path.write_text("@article{example, title={A Test Paper}, author={Doe, Jane}, year={2026}}")
+ content = asyncio.run(FileTypeRouter.read_text_file(str(path)))
+ assert "A Test Paper" in content
+ assert "Jane Doe" in content
+ assert "@article" not in content