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 another API test.

Daniel Pettie7ca93ac790c
diff --git a/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py b/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py
index 382492028f..2f5706150d 100644
--- a/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py
@@ -65,6 +65,7 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
max_results=cross_engine_max_results,
default_reorder=filter_reorder,
default_reindex=filter_reindex,
+ settings_snapshot=settings_snapshot,
)
# Set include_full_content on the search engine if it supports it
diff --git a/src/local_deep_research/api/research_functions.py b/src/local_deep_research/api/research_functions.py
index 8e47dc82e5..718ccdd066 100644
--- a/src/local_deep_research/api/research_functions.py
+++ b/src/local_deep_research/api/research_functions.py
@@ -115,6 +115,7 @@ def _init_search_system(
username=username,
research_id=research_id,
research_context=research_context,
+ settings_snapshot=settings_snapshot,
)
# Override default settings with user-provided values
diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.py
index d27eed667c..a080b19f89 100644
--- a/src/local_deep_research/config/llm_config.py
+++ b/src/local_deep_research/config/llm_config.py
@@ -513,7 +513,9 @@ def get_llm(
try:
# Use the configurable Ollama base URL
raw_base_url = get_setting_from_snapshot(
- "llm.ollama.url", "http://localhost:11434"
+ "llm.ollama.url",
+ "http://localhost:11434",
+ settings_snapshot=settings_snapshot,
)
base_url = (
normalize_url(raw_base_url)
@@ -522,7 +524,7 @@ def get_llm(
)
# Check if Ollama is available before trying to use it
- if not is_ollama_available():
+ if not is_ollama_available(settings_snapshot=settings_snapshot):
logger.error(
f"Ollama not available at {base_url}. Falling back to dummy model."
)
@@ -604,6 +606,7 @@ def get_llm(
research_id=research_id,
provider=provider,
research_context=research_context,
+ settings_snapshot=settings_snapshot,
)
except Exception:
logger.exception("Error creating or testing ChatOllama")
diff --git a/src/local_deep_research/metrics/token_counter.py b/src/local_deep_research/metrics/token_counter.py
index 4d38b1ec31..45e02d3b7c 100644
--- a/src/local_deep_research/metrics/token_counter.py
+++ b/src/local_deep_research/metrics/token_counter.py
@@ -429,7 +429,8 @@ class TokenCountingCallback(BaseCallbackHandler):
token_usage = TokenUsage(
research_id=self.research_id,
model_name=self.current_model,
- provider=self.current_provider, # Added provider for accurate cost tracking
+ model_provider=self.current_provider, # Added provider
+ # for accurate cost tracking
prompt_tokens=prompt_tokens,
completion_tokens=completion_tokens,
total_tokens=prompt_tokens + completion_tokens,
@@ -456,28 +457,22 @@ class TokenCountingCallback(BaseCallbackHandler):
model_usage = (
session.query(ModelUsage)
.filter_by(
- research_id=self.research_id,
model_name=self.current_model,
)
.first()
)
if model_usage:
- model_usage.prompt_tokens += prompt_tokens
- model_usage.completion_tokens += completion_tokens
model_usage.total_tokens += (
prompt_tokens + completion_tokens
)
- model_usage.calls += 1
+ model_usage.total_calls += 1
else:
model_usage = ModelUsage(
- research_id=self.research_id,
model_name=self.current_model,
- provider=self.current_provider,
- prompt_tokens=prompt_tokens,
- completion_tokens=completion_tokens,
+ model_provider=self.current_provider,
total_tokens=prompt_tokens + completion_tokens,
- calls=1,
+ total_calls=1,
)
session.add(model_usage)
diff --git a/src/local_deep_research/web/api.py b/src/local_deep_research/web/api.py
index 2c669dc036..2ef041f92b 100644
--- a/src/local_deep_research/web/api.py
+++ b/src/local_deep_research/web/api.py
@@ -6,8 +6,9 @@ Provides HTTP access to programmatic search and research capabilities.
import logging
import time
from functools import wraps
+from typing import Dict, Any
-from flask import Blueprint, jsonify, request
+from flask import Blueprint, jsonify, request, Response
from ..api.research_functions import analyze_documents
from ..utilities.db_utils import get_setting_from_db_main_thread
@@ -170,6 +171,29 @@ def api_quick_summary_test():
)
+def _serialize_results(results: Dict[str, Any]) -> Response:
+ """
+ Converts the results dictionary into a JSON string.
+
+ Args:
+ results: The results dictionary.
+
+ Returns:
+ The JSON string.
+
+ """
+ # The main thing that needs to be handled here is the `Document` instances.
+ converted_results = results.copy()
+ for finding in converted_results.get("findings", []):
+ for i, document in enumerate(finding.get("documents", [])):
+ finding["documents"][i] = {
+ "metadata": document.metadata,
+ "content": document.page_content,
+ }
+
+ return jsonify(converted_results)
+
+
@api_blueprint.route("/quick_summary", methods=["POST"])
@api_access_control
def api_quick_summary():
@@ -301,7 +325,7 @@ def api_quick_summary():
# Call the actual research function
result = quick_summary(query, **params)
- return jsonify(result)
+ return _serialize_results(result)
except TimeoutError:
logger.error("Request timed out")
return (
@@ -312,8 +336,8 @@ def api_quick_summary():
),
504,
)
- except Exception as e:
- logger.error(f"Error in quick_summary API: {e!s}", exc_info=True)
+ except Exception:
+ logger.exception("Error in quick_summary API")
return (
jsonify(
{
diff --git a/tests/conftest.py b/tests/conftest.py
index 0e1817c1a2..109d368645 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -9,7 +9,7 @@ from unittest.mock import Mock
import pytest
from sqlalchemy import create_engine
from sqlalchemy.exc import SQLAlchemyError
-from sqlalchemy.orm import sessionmaker
+from sqlalchemy.orm import sessionmaker, Session
import src.local_deep_research.utilities.db_utils as db_utils_module
from src.local_deep_research.database.models import Base
@@ -192,9 +192,16 @@ def setup_database_for_all_tests(
mock_get_settings_manager = session_mocker.patch(
"src.local_deep_research.utilities.db_utils.get_settings_manager"
)
- mock_get_settings_manager.side_effect = lambda: SettingsManager(
- db_session=mock_get_db_session()
- )
+
+ def _settings_with_maybe_fake_db(
+ db_session: Session | None = None, *_, **__
+ ) -> SettingsManager:
+ if db_session is None:
+ # Use the mock.
+ db_session = mock_get_db_session()
+ return SettingsManager(db_session=db_session)
+
+ mock_get_settings_manager.side_effect = _settings_with_maybe_fake_db
yield SessionLocal # Yield the SessionLocal class for individual tests to create sessions
diff --git a/tests/run_all_tests.py b/tests/run_all_tests.py
index 417e0cb15e..b72f53b5c2 100755
--- a/tests/run_all_tests.py
+++ b/tests/run_all_tests.py
@@ -326,8 +326,6 @@ class TestRunner:
"tests/test_wikipedia_url_security.py",
"tests/test_search_engines_enhanced.py",
"tests/test_utils.py",
- "tests/test_research_strategy_orm.py",
- "tests/test_database_location_migration.py", # Database location migration tests
"tests/rate_limiting/", # Rate limiting test suite
"tests/retriever_integration/", # LangChain retriever integration tests
"tests/feature_tests/",