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 path handling for reports.

Daniel Petti71f9d8419c3e
diff --git a/src/local_deep_research/web/services/research_service.py b/src/local_deep_research/web/services/research_service.py
index 73fb0acce6..ba3d6666b3 100644
--- a/src/local_deep_research/web/services/research_service.py
+++ b/src/local_deep_research/web/services/research_service.py
@@ -1,8 +1,8 @@
import hashlib
import json
-import os
import threading
from datetime import datetime
+from pathlib import Path
from loguru import logger
@@ -15,7 +15,7 @@ from ..models.database import add_log_to_db, calculate_duration, get_db_connecti
from .socket_service import emit_to_subscribers
# Output directory for research results
-OUTPUT_DIR = "research_outputs"
+OUTPUT_DIR = Path("research_outputs")
def start_research_process(
@@ -68,7 +68,7 @@ def start_research_process(
return thread
-def _generate_report_path(query: str) -> str:
+def _generate_report_path(query: str) -> Path:
"""
Generates a path for a new report file based on the query.
@@ -82,9 +82,8 @@ def _generate_report_path(query: str) -> str:
# Generate a unique filename that does not contain
# non-alphanumeric characters.
query_hash = hashlib.md5(query.encode("utf-8")).hexdigest()[:10]
- return os.path.join(
- OUTPUT_DIR,
- f"research_report_{query_hash}_{datetime.now().isoformat()}.md",
+ return OUTPUT_DIR / (
+ f"research_report_{query_hash}_{int(datetime.now().timestamp())}.md"
)
@@ -139,8 +138,8 @@ def run_research_process(
)
# Set up the AI Context Manager
- output_dir = os.path.join(OUTPUT_DIR, f"research_{research_id}")
- os.makedirs(output_dir, exist_ok=True)
+ output_dir = OUTPUT_DIR / f"research_{research_id}"
+ output_dir.mkdir(parents=True, exist_ok=True)
# Set up progress callback
def progress_callback(message, progress_percent, metadata):
@@ -532,9 +531,7 @@ def run_research_process(
)
# Save as markdown file
- if not os.path.exists(OUTPUT_DIR):
- os.makedirs(OUTPUT_DIR)
-
+ OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
report_path = _generate_report_path(query)
# Send progress update for writing to file
@@ -545,7 +542,7 @@ def run_research_process(
)
logger.info("Writing report to: %s", report_path)
- with open(report_path, "w", encoding="utf-8") as f:
+ with report_path.open("w", encoding="utf-8") as f:
f.write("# Quick Research Summary\n\n")
f.write(f"Query: {query}\n\n")
f.write(clean_markdown)
@@ -583,7 +580,7 @@ def run_research_process(
"completed",
completed_at,
duration_seconds,
- report_path,
+ str(report_path),
json.dumps(metadata),
research_id,
),
@@ -598,7 +595,7 @@ def run_research_process(
progress_callback(
"Research completed successfully",
100,
- {"phase": "complete", "report_path": report_path},
+ {"phase": "complete", "report_path": str(report_path)},
)
# Clean up resources
@@ -635,12 +632,10 @@ def run_research_process(
)
# Save as markdown file
- if not os.path.exists(OUTPUT_DIR):
- os.makedirs(OUTPUT_DIR)
-
+ OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
report_path = _generate_report_path(query)
- with open(report_path, "w", encoding="utf-8") as f:
+ with report_path.open("w", encoding="utf-8") as f:
f.write(final_report["content"])
# Update database
@@ -668,7 +663,7 @@ def run_research_process(
"completed",
completed_at,
duration_seconds,
- report_path,
+ str(report_path),
json.dumps(metadata),
research_id,
),
@@ -679,7 +674,7 @@ def run_research_process(
progress_callback(
"Research completed successfully",
100,
- {"phase": "complete", "report_path": report_path},
+ {"phase": "complete", "report_path": str(report_path)},
)
# Clean up resources