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.

chore: delete unused convert_debug_to_markdown helper (#4149)

LearningCircuitc44c9faced95
diff --git a/src/local_deep_research/web/utils/formatters.py b/src/local_deep_research/web/utils/formatters.py
deleted file mode 100644
index f79c62870e..0000000000
--- a/src/local_deep_research/web/utils/formatters.py
+++ /dev/null
@@ -1,53 +0,0 @@
-from loguru import logger
-
-
-def convert_debug_to_markdown(raw_text, query):
- """
- Convert the debug-formatted text to clean markdown.
-
- Args:
- raw_text: The raw formatted findings with debug symbols
- query: Original research query
-
- Returns:
- Clean markdown formatted text
- """
- try:
- logger.info(f"Starting markdown conversion for query: {query}")
- logger.info(f"Raw text type: {type(raw_text)}")
-
- # Handle None or empty input
- if not raw_text:
- logger.warning("WARNING: raw_text is empty or None")
- return f"No detailed findings available for '{query}'."
-
- # If there's a "DETAILED FINDINGS:" section, extract everything after it
- if "DETAILED FINDINGS:" in raw_text:
- logger.info("Found DETAILED FINDINGS section")
- detailed_index = raw_text.index("DETAILED FINDINGS:")
- content = raw_text[
- detailed_index + len("DETAILED FINDINGS:") :
- ].strip()
- else:
- logger.info("No DETAILED FINDINGS section found, using full text")
- content = raw_text
-
- # Remove divider lines with === symbols
- lines_before = len(content.split("\n"))
- content = "\n".join(
- [
- line
- for line in content.split("\n")
- if not line.strip().startswith("===")
- and not line.strip() == "=" * 80
- ]
- )
- lines_after = len(content.split("\n"))
- logger.info(f"Removed {lines_before - lines_after} divider lines")
-
- logger.info(f"Final markdown length: {len(content.strip())}")
- return content.strip()
- except Exception:
- logger.exception("Error in convert_debug_to_markdown")
- # Return a basic message with the original query as fallback
- return f"# Research on {query}\n\nThere was an error formatting the research results."
diff --git a/tests/web/test_formatters.py b/tests/web/test_formatters.py
deleted file mode 100644
index 9cdcb7b3fd..0000000000
--- a/tests/web/test_formatters.py
+++ /dev/null
@@ -1,151 +0,0 @@
-"""
-Tests for web/utils/formatters.py
-
-Tests cover:
-- convert_debug_to_markdown function
-- Edge cases: None, empty, no findings section
-- Standard conversion with divider removal
-"""
-
-
-class TestConvertDebugToMarkdown:
- """Tests for the convert_debug_to_markdown function."""
-
- def test_empty_input_returns_message(self):
- """Test that empty input returns informative message."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- result = convert_debug_to_markdown("", "test query")
- assert "No detailed findings available" in result
- assert "test query" in result
-
- def test_none_input_returns_message(self):
- """Test that None input returns informative message."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- result = convert_debug_to_markdown(None, "my research")
- assert "No detailed findings available" in result
- assert "my research" in result
-
- def test_extracts_detailed_findings_section(self):
- """Test extraction of content after DETAILED FINDINGS marker."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = """Some header content
-DETAILED FINDINGS:
-This is the actual content
-that should be extracted."""
-
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert "This is the actual content" in result
- assert "that should be extracted" in result
- assert "Some header content" not in result
-
- def test_removes_divider_lines_with_equals(self):
- """Test that === divider lines are removed."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = """DETAILED FINDINGS:
-=== Section 1 ===
-Actual content here
-================================================================================
-More content"""
-
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert "===" not in result
- assert "Actual content here" in result
- assert "More content" in result
-
- def test_no_detailed_findings_uses_full_text(self):
- """Test that full text is used when no DETAILED FINDINGS marker."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = """This is research content
-with multiple lines
-and no special markers."""
-
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert "This is research content" in result
- assert "with multiple lines" in result
-
- def test_returns_stripped_result(self):
- """Test that result is properly stripped of whitespace."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = """DETAILED FINDINGS:
-
- Content with whitespace
-
-"""
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert not result.startswith(" ")
- assert not result.endswith(" ")
- assert "Content with whitespace" in result
-
- def test_handles_only_divider_lines(self):
- """Test handling of text that contains only dividers."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = """DETAILED FINDINGS:
-================================================================================
-=== Only Dividers ===
-================================================================================"""
-
- result = convert_debug_to_markdown(raw_text, "query")
-
- # Should return empty or minimal content after removing dividers
- assert "===" not in result
-
- def test_preserves_markdown_formatting(self):
- """Test that markdown formatting is preserved."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = """DETAILED FINDINGS:
-# Header
-
-- Bullet point
-- Another bullet
-
-**Bold text** and *italic*"""
-
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert "# Header" in result
- assert "- Bullet point" in result
- assert "**Bold text**" in result
- assert "*italic*" in result
-
- def test_handles_unicode_content(self):
- """Test proper handling of unicode characters."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = """DETAILED FINDINGS:
-Émojis 🌍 and spëcial çharacters
-日本語テキスト"""
-
- result = convert_debug_to_markdown(raw_text, "日本語クエリ")
-
- assert "🌍" in result
- assert "日本語テキスト" in result
diff --git a/tests/web/test_formatters_behavior.py b/tests/web/test_formatters_behavior.py
deleted file mode 100644
index 5ef7e2963d..0000000000
--- a/tests/web/test_formatters_behavior.py
+++ /dev/null
@@ -1,145 +0,0 @@
-"""
-Behavioral tests for web/utils/formatters module.
-
-Tests convert_debug_to_markdown function with various input formats.
-"""
-
-
-class TestConvertDebugToMarkdown:
- """Tests for convert_debug_to_markdown function."""
-
- def test_returns_string(self):
- """Returns a string."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- result = convert_debug_to_markdown("some text", "test query")
- assert isinstance(result, str)
-
- def test_none_input_returns_message(self):
- """None input returns informative message."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- result = convert_debug_to_markdown(None, "test query")
- assert "test query" in result
-
- def test_empty_string_returns_message(self):
- """Empty string returns informative message."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- result = convert_debug_to_markdown("", "test query")
- assert "test query" in result
-
- def test_plain_text_returned_as_is(self):
- """Plain text without special markers is returned stripped."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- result = convert_debug_to_markdown("Hello World", "query")
- assert result == "Hello World"
-
- def test_extracts_content_after_detailed_findings(self):
- """Extracts content after DETAILED FINDINGS: marker."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw = "SOME HEADER\nDETAILED FINDINGS:\nActual content here"
- result = convert_debug_to_markdown(raw, "query")
- assert "Actual content here" in result
- assert "SOME HEADER" not in result
-
- def test_removes_divider_lines(self):
- """Removes lines starting with ===."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw = "Line 1\n=== Divider ===\nLine 2"
- result = convert_debug_to_markdown(raw, "query")
- assert "===" not in result
- assert "Line 1" in result
- assert "Line 2" in result
-
- def test_removes_80_char_divider(self):
- """Removes 80-character = divider lines."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw = "Line 1\n" + "=" * 80 + "\nLine 2"
- result = convert_debug_to_markdown(raw, "query")
- assert "=" * 80 not in result
- assert "Line 1" in result
- assert "Line 2" in result
-
- def test_strips_whitespace(self):
- """Result is stripped of leading/trailing whitespace."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw = " \n content \n "
- result = convert_debug_to_markdown(raw, "query")
- assert result == "content"
-
- def test_preserves_markdown_headers(self):
- """Preserves markdown headers in content."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw = "# Header\n## Subheader\nParagraph text"
- result = convert_debug_to_markdown(raw, "query")
- assert "# Header" in result
- assert "## Subheader" in result
-
- def test_preserves_bullet_points(self):
- """Preserves bullet points in content."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw = "- Item 1\n- Item 2\n- Item 3"
- result = convert_debug_to_markdown(raw, "query")
- assert "- Item 1" in result
- assert "- Item 2" in result
- assert "- Item 3" in result
-
- def test_detailed_findings_with_dividers(self):
- """Handles DETAILED FINDINGS with divider lines."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw = "SUMMARY\nDETAILED FINDINGS:\n=== Section ===\nContent"
- result = convert_debug_to_markdown(raw, "query")
- assert "===" not in result
- assert "Content" in result
- assert "SUMMARY" not in result
-
- def test_multiline_content_preserved(self):
- """Multiple lines of content are preserved."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw = "Line 1\nLine 2\nLine 3\nLine 4"
- result = convert_debug_to_markdown(raw, "query")
- assert "Line 1" in result
- assert "Line 4" in result
-
- def test_query_in_none_fallback(self):
- """Query appears in fallback message for None input."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- result = convert_debug_to_markdown(None, "quantum computing")
- assert "quantum computing" in result
diff --git a/tests/web/utils/test_formatters.py b/tests/web/utils/test_formatters.py
deleted file mode 100644
index a3a6785d20..0000000000
--- a/tests/web/utils/test_formatters.py
+++ /dev/null
@@ -1,152 +0,0 @@
-"""Tests for web/utils/formatters.py."""
-
-
-class TestConvertDebugToMarkdown:
- """Tests for convert_debug_to_markdown function."""
-
- def test_empty_input_returns_no_findings_message(self):
- """Test that empty input returns appropriate message."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- result = convert_debug_to_markdown(None, "test query")
- assert "No detailed findings available" in result
- assert "test query" in result
-
- def test_empty_string_returns_no_findings_message(self):
- """Test that empty string returns appropriate message."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- result = convert_debug_to_markdown("", "my query")
- assert "No detailed findings available" in result
- assert "my query" in result
-
- def test_extracts_content_after_detailed_findings_header(self):
- """Test that content after DETAILED FINDINGS: is extracted."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = "Some preamble\nDETAILED FINDINGS:\nThis is the actual content\nMore content"
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert "This is the actual content" in result
- assert "More content" in result
- assert "Some preamble" not in result
- assert "DETAILED FINDINGS:" not in result
-
- def test_returns_full_text_if_no_detailed_findings_header(self):
- """Test that full text is returned when no DETAILED FINDINGS header."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = "Just some regular content\nWith multiple lines"
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert "Just some regular content" in result
- assert "With multiple lines" in result
-
- def test_removes_divider_lines_starting_with_equals(self):
- """Test that lines starting with === are removed."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = (
- "Content line\n=== DIVIDER ===\nMore content\n================"
- )
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert "Content line" in result
- assert "More content" in result
- assert "===" not in result
- assert "DIVIDER" not in result
-
- def test_removes_80_char_equals_divider(self):
- """Test that 80-char equals dividers are removed."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- divider = "=" * 80
- raw_text = f"Content\n{divider}\nMore content"
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert "Content" in result
- assert "More content" in result
- assert divider not in result
-
- def test_preserves_equals_in_regular_content(self):
- """Test that equals signs in regular content are preserved."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = "a = b + c\nx == y"
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert "a = b + c" in result
- assert "x == y" in result
-
- def test_strips_whitespace_from_result(self):
- """Test that result is stripped of leading/trailing whitespace."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = " \n Content \n "
- result = convert_debug_to_markdown(raw_text, "query")
-
- assert result == "Content"
-
- def test_handles_exception_gracefully(self):
- """Test that exceptions are handled and fallback message returned."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- # Create an object that will raise when converted
- class BadInput:
- def __bool__(self):
- return True
-
- def __contains__(self, item):
- raise RuntimeError("Test error")
-
- result = convert_debug_to_markdown(BadInput(), "my query")
- assert "Research on my query" in result
- assert "error formatting" in result
-
- def test_complex_input_with_multiple_sections(self):
- """Test complex input with headers, dividers, and content."""
- from local_deep_research.web.utils.formatters import (
- convert_debug_to_markdown,
- )
-
- raw_text = """
-SUMMARY:
-Some summary text
-
-================================================================================
-DETAILED FINDINGS:
-=== Section 1 ===
-First finding details
-More details here
-
-=== Section 2 ===
-Second finding details
-"""
- result = convert_debug_to_markdown(raw_text, "complex query")
-
- # Should extract after DETAILED FINDINGS
- assert "First finding details" in result
- assert "Second finding details" in result
- # Should not include content before DETAILED FINDINGS
- assert "Some summary text" not in result
- # Should remove divider lines
- assert "===" not in result
- assert "=" * 80 not in result