Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: Address code review feedback for citation formatting PR

LearningCircuit8c6e36e4248d
diff --git a/src/local_deep_research/text_optimization/test_citation_formatter.py b/src/local_deep_research/text_optimization/test_citation_formatter.py
index d0536ab30a..bf31970f01 100644
--- a/src/local_deep_research/text_optimization/test_citation_formatter.py
+++ b/src/local_deep_research/text_optimization/test_citation_formatter.py
@@ -41,28 +41,79 @@ The analysis reveals several important points:
print(sample_content)
print("\n" + "=" * 70 + "\n")
- # Test different citation modes
- modes = [
- (CitationMode.NUMBER_HYPERLINKS, "Numbers with hyperlinks"),
- (CitationMode.DOMAIN_HYPERLINKS, "Domain names with hyperlinks"),
- (CitationMode.NO_HYPERLINKS, "No hyperlinks"),
- ]
-
- for mode, description in modes:
- formatter = CitationFormatter(mode=mode)
- formatted = formatter.format_document(sample_content)
-
- print(f"{description}:")
- print("-" * 50)
- print(formatted)
- print("\n" + "=" * 70 + "\n")
+ # Test NUMBER_HYPERLINKS mode
+ formatter = CitationFormatter(mode=CitationMode.NUMBER_HYPERLINKS)
+ formatted = formatter.format_document(sample_content)
+
+ # Assertions for NUMBER_HYPERLINKS mode
+ assert "[[1]](https://arxiv.org/abs/2104.12345)" in formatted
+ assert (
+ "[[2]](https://www.nature.com/articles/s41586-021-03819-2)" in formatted
+ )
+ assert "[[3]](https://openai.com/research/emergent-abilities)" in formatted
+ assert "[[1]][[2]][[3]]" in formatted # Check multiple citations together
+ print("✓ NUMBER_HYPERLINKS mode assertions passed")
+
+ # Test DOMAIN_HYPERLINKS mode
+ formatter = CitationFormatter(mode=CitationMode.DOMAIN_HYPERLINKS)
+ formatted = formatter.format_document(sample_content)
+
+ # Assertions for DOMAIN_HYPERLINKS mode
+ assert "[[arxiv.org]](https://arxiv.org/abs/2104.12345)" in formatted
+ assert (
+ "[[nature.com]](https://www.nature.com/articles/s41586-021-03819-2)"
+ in formatted
+ )
+ assert (
+ "[[openai.com]](https://openai.com/research/emergent-abilities)"
+ in formatted
+ )
+ print("✓ DOMAIN_HYPERLINKS mode assertions passed")
+
+ # Test NO_HYPERLINKS mode
+ formatter = CitationFormatter(mode=CitationMode.NO_HYPERLINKS)
+ formatted = formatter.format_document(sample_content)
+
+ # Assertions for NO_HYPERLINKS mode
+ assert "[1]" in formatted
+ assert "[2]" in formatted
+ assert "[3]" in formatted
+ assert "[[1]]" not in formatted # Should not have hyperlink syntax
+ assert (
+ "https://" not in formatted.split("## Sources")[0]
+ ) # URLs should not appear in main content
+ print("✓ NO_HYPERLINKS mode assertions passed")
+
+ # Test DOMAIN_ID_HYPERLINKS mode (default)
+ formatter = CitationFormatter(mode=CitationMode.DOMAIN_ID_HYPERLINKS)
+ formatted = formatter.format_document(sample_content)
+
+ # Assertions for DOMAIN_ID_HYPERLINKS mode
+ # Should use domain names without IDs for first occurrence
+ assert (
+ "[[arxiv.org]](https://arxiv.org/abs/2104.12345)" in formatted
+ or "[[arxiv.org-1]](https://arxiv.org/abs/2104.12345)" in formatted
+ )
+ print("✓ DOMAIN_ID_HYPERLINKS mode assertions passed")
# Test LaTeX export
- print("LaTeX Export:")
+ print("\nTesting LaTeX Export:")
print("-" * 50)
exporter = LaTeXExporter()
latex_content = exporter.export_to_latex(sample_content)
- print(latex_content)
+
+ # Assertions for LaTeX export
+ assert "\\documentclass[12pt]{article}" in latex_content
+ assert "\\title{Research Report}" in latex_content
+ assert "\\date{\\today}" in latex_content
+ assert "\\begin{document}" in latex_content
+ assert "\\end{document}" in latex_content
+ assert "\\section{Key Findings}" in latex_content
+ assert "\\bibitem{ref1}" in latex_content
+ assert "\\cite{ref1}" in latex_content
+ print("✓ LaTeX export assertions passed")
+
+ print("\nAll tests passed successfully!")
if __name__ == "__main__":
diff --git a/src/local_deep_research/web/routes/research_routes.py b/src/local_deep_research/web/routes/research_routes.py
index f7e51fbc16..7833412008 100644
--- a/src/local_deep_research/web/routes/research_routes.py
+++ b/src/local_deep_research/web/routes/research_routes.py
@@ -706,7 +706,7 @@ def get_research_report(research_id):
with open(research.report_path, "r", encoding="utf-8") as f:
content = f.read()
except Exception as e:
- logger.error(
+ logger.exception(
f"Error reading report file {research.report_path}: {e}"
)
return jsonify({"error": "Error reading report file"}), 500
@@ -758,13 +758,12 @@ def export_research_report(research_id, format):
return jsonify({"error": "Research not found"}), 404
# Get the report path
- if research.report_path:
- report_path = OUTPUT_DIR / research.report_path
- else:
- # Try to construct the path
- filename = f"research_{research.query[:50].replace(' ', '_').replace('/', '_')}_{research.created_at.strftime('%Y%m%d_%H%M%S')}.md"
- report_path = OUTPUT_DIR / filename
+ if not research.report_path:
+ return jsonify(
+ {"error": "Report path not found in database"}
+ ), 404
+ report_path = OUTPUT_DIR / research.report_path
if not report_path.exists():
return jsonify({"error": "Report file not found"}), 404
@@ -782,7 +781,7 @@ def export_research_report(research_id, format):
else "text/markdown",
)
except Exception as e:
- logger.error(f"Error exporting report: {str(e)}")
+ logger.exception(f"Error exporting report: {str(e)}")
return jsonify(
{"error": f"Failed to export to {format}: {str(e)}"}
), 500
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.py
index f20f6719d3..0d0dcd9b3f 100644
--- a/src/local_deep_research/web/routes/settings_routes.py
+++ b/src/local_deep_research/web/routes/settings_routes.py
@@ -454,7 +454,7 @@ def save_all_settings():
)
-@settings_bp.route("/reset_to_defaults", methods=["GET", "POST"])
+@settings_bp.route("/reset_to_defaults", methods=["POST"])
def reset_to_defaults():
"""Reset all settings to their default values"""
db_session = get_db_session()
diff --git a/src/local_deep_research/web/services/research_service.py b/src/local_deep_research/web/services/research_service.py
index 28b0b88c16..1a2ab06b9c 100644
--- a/src/local_deep_research/web/services/research_service.py
+++ b/src/local_deep_research/web/services/research_service.py
@@ -101,19 +101,6 @@ def export_report_to_format(report_path: Path, format: str, title: str = None):
return export_path
-def export_report_to_latex(report_path: Path):
- """
- Export a markdown report to LaTeX format.
-
- Args:
- report_path: Path to the markdown report file
-
- Returns:
- Path to the generated LaTeX file
- """
- return export_report_to_format(report_path, "latex")
-
-
def save_research_strategy(research_id, strategy_name):
"""
Save the strategy used for a research to the database.
@@ -854,7 +841,7 @@ def run_research_process(
f"Exported report to {format}: {export_path}"
)
except Exception as e:
- logger.error(
+ logger.exception(
f"Failed to export to {format}: {e}"
)
@@ -979,7 +966,7 @@ def run_research_process(
f"Exported report to {format}: {export_path}"
)
except Exception as e:
- logger.error(f"Failed to export to {format}: {e}")
+ logger.exception(f"Failed to export to {format}: {e}")
# Update database
metadata = final_report["metadata"]
diff --git a/tests/text_optimization/test_integration.py b/tests/text_optimization/test_integration.py
index 5e393d095b..64d8f61be8 100644
--- a/tests/text_optimization/test_integration.py
+++ b/tests/text_optimization/test_integration.py
@@ -7,7 +7,6 @@ from unittest.mock import patch
from local_deep_research.web.services.research_service import (
get_citation_formatter,
- export_report_to_latex,
export_report_to_format,
)
from local_deep_research.text_optimization import (
@@ -74,7 +73,7 @@ This is a test with citation [1].
try:
# Export to LaTeX
- latex_path = export_report_to_latex(markdown_path)
+ latex_path = export_report_to_format(markdown_path, "latex")
# Check LaTeX file was created
assert latex_path.exists()