~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
Centralize boolean conversion logic in utilities/type_utils.py
LearningCircuita6fc0fc14ec2
diff --git a/src/local_deep_research/api/settings_utils.py b/src/local_deep_research/api/settings_utils.pyindex 47719e2218..01bd2ea7bc 100644--- a/src/local_deep_research/api/settings_utils.py+++ b/src/local_deep_research/api/settings_utils.py@@ -13,6 +13,7 @@ from loguru import loggerfrom ..settings import SettingsManagerfrom ..settings.base import ISettingsManager+from ..utilities.type_utils import to_bool # noqa: F401class InMemorySettingsManager(ISettingsManager):@@ -332,51 +333,6 @@ def extract_setting_value(return default-def to_bool(value: Any, default: bool = False) -> bool:- """- Convert a value to boolean, handling string representations.-- This is a standalone utility for converting any value to boolean,- centralizing the string-to-boolean conversion logic that was- previously scattered throughout the codebase.-- Handles truthy string representations that may come from:- - API requests- - Configuration files- - SQLite (which lacks native boolean type)- - Environment variables-- Args:- value: The value to convert- default: Default boolean if value is None-- Returns:- Boolean value-- Examples:- >>> to_bool("true")- True- >>> to_bool("yes")- True- >>> to_bool("1")- True- >>> to_bool("false")- False- >>> to_bool(1)- True- >>> to_bool(None, default=True)- True- """- if isinstance(value, bool):- return value- if isinstance(value, str):- return value.lower() in ("true", "1", "yes", "on", "enabled")- if value is None:- return default- # For other types (int, etc.), use Python's bool conversion- return bool(value)--def extract_bool_setting(settings_snapshot: Dict[str, Any], key: str, default: bool = False) -> bool:diff --git a/src/local_deep_research/config/thread_settings.py b/src/local_deep_research/config/thread_settings.pyindex 7f990fa186..d6f8878537 100644--- a/src/local_deep_research/config/thread_settings.py+++ b/src/local_deep_research/config/thread_settings.py@@ -8,6 +8,7 @@ import osimport threadingfrom ..settings.manager import get_typed_setting_value+from ..utilities.type_utils import to_boolclass NoSettingsContextError(Exception):@@ -157,11 +158,4 @@ def get_bool_setting_from_snapshot(check_fallback_llm=check_fallback_llm,)- if isinstance(value, bool):- return value- if isinstance(value, str):- return value.lower() in ("true", "1", "yes", "on", "enabled")- if value is None:- return default- # For other types (int, etc.), use Python's bool conversion- return bool(value)+ return to_bool(value, default)diff --git a/src/local_deep_research/research_library/services/library_rag_service.py b/src/local_deep_research/research_library/services/library_rag_service.pyindex 0923875a1a..a15925ff12 100644--- a/src/local_deep_research/research_library/services/library_rag_service.py+++ b/src/local_deep_research/research_library/services/library_rag_service.py@@ -26,6 +26,7 @@ from ...database.models.library import (EmbeddingProvider,)from ...database.session_context import get_user_db_session+from ...utilities.type_utils import to_boolfrom ...embeddings.splitters import get_text_splitterfrom ...web_search_engines.engines.search_engine_local import (LocalEmbeddingManager,@@ -90,8 +91,6 @@ class LibraryRAGService:)self.distance_metric = distance_metric# Ensure normalize_vectors is always a proper boolean- from local_deep_research.api.settings_utils import to_bool-self.normalize_vectors = to_bool(normalize_vectors, default=True)self.index_type = index_typediff --git a/src/local_deep_research/utilities/type_utils.py b/src/local_deep_research/utilities/type_utils.pynew file mode 100644index 0000000000..b9fee88f2e--- /dev/null+++ b/src/local_deep_research/utilities/type_utils.py@@ -0,0 +1,54 @@+"""+Type conversion utilities.++This module provides type conversion functions that are used throughout+the codebase. It is intentionally kept free of internal dependencies to+avoid circular import issues.+"""++from typing import Any+++def to_bool(value: Any, default: bool = False) -> bool:+ """+ Convert a value to boolean, handling string representations.++ This is a standalone utility for converting any value to boolean,+ centralizing the string-to-boolean conversion logic that was+ previously scattered throughout the codebase.++ Handles truthy string representations that may come from:+ - API requests+ - Configuration files+ - SQLite (which lacks native boolean type)+ - Environment variables++ Args:+ value: The value to convert+ default: Default boolean if value is None++ Returns:+ Boolean value++ Examples:+ >>> to_bool("true")+ True+ >>> to_bool("yes")+ True+ >>> to_bool("1")+ True+ >>> to_bool("false")+ False+ >>> to_bool(1)+ True+ >>> to_bool(None, default=True)+ True+ """+ if isinstance(value, bool):+ return value+ if isinstance(value, str):+ return value.lower() in ("true", "1", "yes", "on", "enabled")+ if value is None:+ return default+ # For other types (int, etc.), use Python's bool conversion+ return bool(value)diff --git a/src/local_deep_research/web/services/settings_manager.py b/src/local_deep_research/web/services/settings_manager.pyindex 0146381cb3..f6d3e5555d 100644--- a/src/local_deep_research/web/services/settings_manager.py+++ b/src/local_deep_research/web/services/settings_manager.py@@ -10,6 +10,7 @@ from sqlalchemy.exc import SQLAlchemyErrorfrom sqlalchemy.orm import Sessionfrom ... import defaults+from ...utilities.type_utils import to_boolfrom ...__version__ import __version__ as package_versionfrom ...database.models import Setting, SettingTypefrom ..models.settings import (@@ -313,14 +314,7 @@ class SettingsManager:"""value = self.get_setting(key, default, check_env)- if isinstance(value, bool):- return value- if isinstance(value, str):- return value.lower() in ("true", "1", "yes", "on", "enabled")- if value is None:- return default- # For other types (int, etc.), use Python's bool conversion- return bool(value)+ return to_bool(value, default)def set_setting(self, key: str, value: Any, commit: bool = True) -> bool:"""