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.

refactor: extract shared exporter logic into BaseExporter (#2896)

LearningCircuite1b0411bde7e
diff --git a/src/local_deep_research/exporters/base.py b/src/local_deep_research/exporters/base.py
index 4c4ba82dec..8156a2cc3e 100644
--- a/src/local_deep_research/exporters/base.py
+++ b/src/local_deep_research/exporters/base.py
@@ -59,6 +59,9 @@ class BaseExporter(ABC):
...
"""
+ # Maximum content size (50 MB) to prevent OOM errors
+ MAX_CONTENT_SIZE = 50 * 1024 * 1024
+
@property
@abstractmethod
def format_name(self) -> str:
@@ -80,6 +83,21 @@ class BaseExporter(ABC):
"""Return the MIME type for the exported file."""
pass
+ def _validate_content_size(self, content: str) -> None:
+ """Validate that content does not exceed the maximum size limit.
+
+ Args:
+ content: The content string to validate
+
+ Raises:
+ ValueError: If content exceeds MAX_CONTENT_SIZE
+ """
+ if len(content) > self.MAX_CONTENT_SIZE:
+ raise ValueError(
+ f"Content exceeds maximum size of "
+ f"{self.MAX_CONTENT_SIZE // (1024 * 1024)} MB"
+ )
+
@abstractmethod
def export(
self,
diff --git a/src/local_deep_research/exporters/latex_exporter.py b/src/local_deep_research/exporters/latex_exporter.py
index 1617ca0011..001ce5aba9 100644
--- a/src/local_deep_research/exporters/latex_exporter.py
+++ b/src/local_deep_research/exporters/latex_exporter.py
@@ -11,9 +11,6 @@ from loguru import logger
from .base import BaseExporter, ExportOptions, ExportResult
from .registry import ExporterRegistry
-# Maximum content size (50 MB) to prevent OOM errors
-MAX_CONTENT_SIZE = 50 * 1024 * 1024
-
@ExporterRegistry.register
class LaTeXExporter(BaseExporter):
@@ -63,11 +60,7 @@ class LaTeXExporter(BaseExporter):
"""
try:
# Check content size limit to prevent OOM errors
- if len(markdown_content) > MAX_CONTENT_SIZE:
- raise ValueError(
- f"Content exceeds maximum size of "
- f"{MAX_CONTENT_SIZE // (1024 * 1024)} MB"
- )
+ self._validate_content_size(markdown_content)
options = options or ExportOptions()
diff --git a/src/local_deep_research/exporters/odt_exporter.py b/src/local_deep_research/exporters/odt_exporter.py
index 3967abce37..d7225c090b 100644
--- a/src/local_deep_research/exporters/odt_exporter.py
+++ b/src/local_deep_research/exporters/odt_exporter.py
@@ -25,9 +25,6 @@ except ImportError:
from .base import BaseExporter, ExportOptions, ExportResult
from .registry import ExporterRegistry
-# Maximum content size (50 MB) to prevent OOM errors
-MAX_CONTENT_SIZE = 50 * 1024 * 1024
-
@ExporterRegistry.register
class ODTExporter(BaseExporter):
@@ -86,11 +83,7 @@ class ODTExporter(BaseExporter):
)
# Check content size limit to prevent OOM errors
- if len(markdown_content) > MAX_CONTENT_SIZE:
- raise ValueError(
- f"Content exceeds maximum size of "
- f"{MAX_CONTENT_SIZE // (1024 * 1024)} MB"
- )
+ self._validate_content_size(markdown_content)
options = options or ExportOptions()
diff --git a/src/local_deep_research/exporters/pdf_exporter.py b/src/local_deep_research/exporters/pdf_exporter.py
index 5e20eab9e2..1cdbcfe04d 100644
--- a/src/local_deep_research/exporters/pdf_exporter.py
+++ b/src/local_deep_research/exporters/pdf_exporter.py
@@ -14,9 +14,6 @@ from loguru import logger
from .base import BaseExporter, ExportOptions, ExportResult
from .registry import ExporterRegistry
-# Maximum content size (50 MB) to prevent OOM errors
-MAX_CONTENT_SIZE = 50 * 1024 * 1024
-
@ExporterRegistry.register
class PDFExporter(BaseExporter):
@@ -65,11 +62,7 @@ class PDFExporter(BaseExporter):
"""
try:
# Check content size limit to prevent OOM errors
- if len(markdown_content) > MAX_CONTENT_SIZE:
- raise ValueError(
- f"Content exceeds maximum size of "
- f"{MAX_CONTENT_SIZE // (1024 * 1024)} MB"
- )
+ self._validate_content_size(markdown_content)
options = options or ExportOptions()
diff --git a/src/local_deep_research/exporters/quarto_exporter.py b/src/local_deep_research/exporters/quarto_exporter.py
index 400f0c2218..5f3e116f33 100644
--- a/src/local_deep_research/exporters/quarto_exporter.py
+++ b/src/local_deep_research/exporters/quarto_exporter.py
@@ -14,9 +14,6 @@ from loguru import logger
from .base import BaseExporter, ExportOptions, ExportResult
from .registry import ExporterRegistry
-# Maximum content size (50 MB) to prevent OOM errors
-MAX_CONTENT_SIZE = 50 * 1024 * 1024
-
@ExporterRegistry.register
class QuartoExporter(BaseExporter):
@@ -71,11 +68,7 @@ class QuartoExporter(BaseExporter):
"""
try:
# Check content size limit to prevent OOM errors
- if len(markdown_content) > MAX_CONTENT_SIZE:
- raise ValueError(
- f"Content exceeds maximum size of "
- f"{MAX_CONTENT_SIZE // (1024 * 1024)} MB"
- )
+ self._validate_content_size(markdown_content)
options = options or ExportOptions()
diff --git a/src/local_deep_research/exporters/ris_exporter.py b/src/local_deep_research/exporters/ris_exporter.py
index 25e5fd6ca2..d66799bbb2 100644
--- a/src/local_deep_research/exporters/ris_exporter.py
+++ b/src/local_deep_research/exporters/ris_exporter.py
@@ -11,9 +11,6 @@ from loguru import logger
from .base import BaseExporter, ExportOptions, ExportResult
from .registry import ExporterRegistry
-# Maximum content size (50 MB) to prevent OOM errors
-MAX_CONTENT_SIZE = 50 * 1024 * 1024
-
@ExporterRegistry.register
class RISExporter(BaseExporter):
@@ -64,11 +61,7 @@ class RISExporter(BaseExporter):
"""
try:
# Check content size limit to prevent OOM errors
- if len(markdown_content) > MAX_CONTENT_SIZE:
- raise ValueError(
- f"Content exceeds maximum size of "
- f"{MAX_CONTENT_SIZE // (1024 * 1024)} MB"
- )
+ self._validate_content_size(markdown_content)
options = options or ExportOptions()
diff --git a/tests/exporters/test_latex_exporter.py b/tests/exporters/test_latex_exporter.py
index e469c9cd11..dd58f929ba 100644
--- a/tests/exporters/test_latex_exporter.py
+++ b/tests/exporters/test_latex_exporter.py
@@ -148,9 +148,9 @@ class TestLaTeXExporterContentSizeLimit:
def test_raises_error_for_oversized_content(self, exporter):
"""Test that ValueError is raised for content exceeding size limit."""
- from local_deep_research.exporters.latex_exporter import (
- MAX_CONTENT_SIZE,
- )
+ from local_deep_research.exporters.base import BaseExporter
+
+ MAX_CONTENT_SIZE = BaseExporter.MAX_CONTENT_SIZE
# Create content that exceeds the limit
oversized_content = "x" * (MAX_CONTENT_SIZE + 1)
@@ -162,9 +162,9 @@ class TestLaTeXExporterContentSizeLimit:
def test_accepts_content_at_limit(self, exporter):
"""Test that content at exactly the limit is accepted."""
- from local_deep_research.exporters.latex_exporter import (
- MAX_CONTENT_SIZE,
- )
+ from local_deep_research.exporters.base import BaseExporter
+
+ MAX_CONTENT_SIZE = BaseExporter.MAX_CONTENT_SIZE
# Create content at exactly the limit
content_at_limit = "x" * MAX_CONTENT_SIZE
diff --git a/tests/exporters/test_odt_exporter.py b/tests/exporters/test_odt_exporter.py
index 5cc2fd95bf..12c9d1901d 100644
--- a/tests/exporters/test_odt_exporter.py
+++ b/tests/exporters/test_odt_exporter.py
@@ -372,7 +372,9 @@ class TestODTExporterContentSizeLimit:
def test_raises_error_for_oversized_content(self, exporter):
"""Test that ValueError is raised for content exceeding size limit."""
- from local_deep_research.exporters.odt_exporter import MAX_CONTENT_SIZE
+ from local_deep_research.exporters.base import BaseExporter
+
+ MAX_CONTENT_SIZE = BaseExporter.MAX_CONTENT_SIZE
# Create content that exceeds the limit
oversized_content = "x" * (MAX_CONTENT_SIZE + 1)
@@ -384,7 +386,9 @@ class TestODTExporterContentSizeLimit:
def test_accepts_content_at_limit(self, exporter):
"""Test that content at exactly the limit is accepted (doesn't raise)."""
- from local_deep_research.exporters.odt_exporter import MAX_CONTENT_SIZE
+ from local_deep_research.exporters.base import BaseExporter
+
+ MAX_CONTENT_SIZE = BaseExporter.MAX_CONTENT_SIZE
import zipfile
import io
diff --git a/tests/exporters/test_pdf_exporter.py b/tests/exporters/test_pdf_exporter.py
index 29594df43a..1357234232 100644
--- a/tests/exporters/test_pdf_exporter.py
+++ b/tests/exporters/test_pdf_exporter.py
@@ -191,7 +191,9 @@ class TestPDFExporterContentSizeLimit:
def test_raises_error_for_oversized_content(self, exporter):
"""Test that ValueError is raised for content exceeding size limit."""
- from local_deep_research.exporters.pdf_exporter import MAX_CONTENT_SIZE
+ from local_deep_research.exporters.base import BaseExporter
+
+ MAX_CONTENT_SIZE = BaseExporter.MAX_CONTENT_SIZE
# Create content that exceeds the limit
oversized_content = "x" * (MAX_CONTENT_SIZE + 1)
@@ -203,7 +205,9 @@ class TestPDFExporterContentSizeLimit:
def test_accepts_content_at_limit(self, exporter):
"""Test that content at exactly the limit is accepted."""
- from local_deep_research.exporters.pdf_exporter import MAX_CONTENT_SIZE
+ from local_deep_research.exporters.base import BaseExporter
+
+ MAX_CONTENT_SIZE = BaseExporter.MAX_CONTENT_SIZE
# Create content at exactly the limit
content_at_limit = "x" * MAX_CONTENT_SIZE
diff --git a/tests/exporters/test_quarto_exporter.py b/tests/exporters/test_quarto_exporter.py
index 5758177a84..2d4d3d4bfc 100644
--- a/tests/exporters/test_quarto_exporter.py
+++ b/tests/exporters/test_quarto_exporter.py
@@ -209,9 +209,9 @@ class TestQuartoExporterContentSizeLimit:
def test_raises_error_for_oversized_content(self, exporter):
"""Test that ValueError is raised for content exceeding size limit."""
- from local_deep_research.exporters.quarto_exporter import (
- MAX_CONTENT_SIZE,
- )
+ from local_deep_research.exporters.base import BaseExporter
+
+ MAX_CONTENT_SIZE = BaseExporter.MAX_CONTENT_SIZE
# Create content that exceeds the limit
oversized_content = "x" * (MAX_CONTENT_SIZE + 1)
@@ -223,9 +223,9 @@ class TestQuartoExporterContentSizeLimit:
def test_accepts_content_at_limit(self, exporter):
"""Test that content at exactly the limit is accepted."""
- from local_deep_research.exporters.quarto_exporter import (
- MAX_CONTENT_SIZE,
- )
+ from local_deep_research.exporters.base import BaseExporter
+
+ MAX_CONTENT_SIZE = BaseExporter.MAX_CONTENT_SIZE
# Create content at exactly the limit
content_at_limit = "x" * MAX_CONTENT_SIZE
diff --git a/tests/exporters/test_ris_exporter.py b/tests/exporters/test_ris_exporter.py
index e8c322d77e..97c0b22cd6 100644
--- a/tests/exporters/test_ris_exporter.py
+++ b/tests/exporters/test_ris_exporter.py
@@ -196,7 +196,9 @@ class TestRISExporterContentSizeLimit:
def test_raises_error_for_oversized_content(self, exporter):
"""Test that ValueError is raised for content exceeding size limit."""
- from local_deep_research.exporters.ris_exporter import MAX_CONTENT_SIZE
+ from local_deep_research.exporters.base import BaseExporter
+
+ MAX_CONTENT_SIZE = BaseExporter.MAX_CONTENT_SIZE
# Create content that exceeds the limit
oversized_content = "x" * (MAX_CONTENT_SIZE + 1)
@@ -208,7 +210,9 @@ class TestRISExporterContentSizeLimit:
def test_accepts_content_at_limit(self, exporter):
"""Test that content at exactly the limit is accepted."""
- from local_deep_research.exporters.ris_exporter import MAX_CONTENT_SIZE
+ from local_deep_research.exporters.base import BaseExporter
+
+ MAX_CONTENT_SIZE = BaseExporter.MAX_CONTENT_SIZE
# Create content at exactly the limit
content_at_limit = "x" * MAX_CONTENT_SIZE