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: modernize type hints in API module (#2009)

LearningCircuit6920db80a29e
diff --git a/src/local_deep_research/api/benchmark_functions.py b/src/local_deep_research/api/benchmark_functions.py
index a200395461..f3dac40598 100644
--- a/src/local_deep_research/api/benchmark_functions.py
+++ b/src/local_deep_research/api/benchmark_functions.py
@@ -6,7 +6,7 @@ This module provides functions for running benchmarks programmatically.
from loguru import logger
from pathlib import Path
-from typing import Any, Dict, List, Optional
+from typing import Any
from ..benchmarks import (
calculate_metrics,
@@ -24,10 +24,10 @@ def evaluate_simpleqa(
questions_per_iteration: int = 3,
search_tool: str = "searxng",
human_evaluation: bool = False,
- evaluation_model: Optional[str] = None,
- evaluation_provider: Optional[str] = None,
+ evaluation_model: str | None = None,
+ evaluation_provider: str | None = None,
output_dir: str = "benchmark_results",
-) -> Dict[str, Any]:
+) -> dict[str, Any]:
"""
Run SimpleQA benchmark evaluation.
@@ -80,10 +80,10 @@ def evaluate_browsecomp(
questions_per_iteration: int = 3,
search_tool: str = "searxng",
human_evaluation: bool = False,
- evaluation_model: Optional[str] = None,
- evaluation_provider: Optional[str] = None,
+ evaluation_model: str | None = None,
+ evaluation_provider: str | None = None,
output_dir: str = "benchmark_results",
-) -> Dict[str, Any]:
+) -> dict[str, Any]:
"""
Run BrowseComp benchmark evaluation.
@@ -136,10 +136,10 @@ def evaluate_xbench_deepsearch(
questions_per_iteration: int = 3,
search_tool: str = "searxng",
human_evaluation: bool = False,
- evaluation_model: Optional[str] = None,
- evaluation_provider: Optional[str] = None,
+ evaluation_model: str | None = None,
+ evaluation_provider: str | None = None,
output_dir: str = "benchmark_results",
-) -> Dict[str, Any]:
+) -> dict[str, Any]:
"""
Run xbench-DeepSearch benchmark evaluation.
@@ -188,7 +188,7 @@ def evaluate_xbench_deepsearch(
return results
-def get_available_benchmarks() -> List[Dict[str, str]]:
+def get_available_benchmarks() -> list[dict[str, str]]:
"""
Get information about available benchmarks.
@@ -220,9 +220,9 @@ def get_available_benchmarks() -> List[Dict[str, str]]:
def compare_configurations(
dataset_type: str = "simpleqa",
num_examples: int = 20,
- configurations: List[Dict[str, Any]] = None,
+ configurations: list[dict[str, Any]] = None,
output_dir: str = "benchmark_comparisons",
-) -> Dict[str, Any]:
+) -> dict[str, Any]:
"""
Compare multiple search configurations on the same benchmark.
diff --git a/src/local_deep_research/api/client.py b/src/local_deep_research/api/client.py
index ea23aede9f..279f2e606a 100644
--- a/src/local_deep_research/api/client.py
+++ b/src/local_deep_research/api/client.py
@@ -56,7 +56,7 @@ Example usage:
"""
import time
-from typing import Optional, Dict, Any, List
+from typing import Any
from loguru import logger
from local_deep_research.benchmarks.comparison.results import Benchmark_results
from local_deep_research.security import SafeSession
@@ -161,7 +161,7 @@ class LDRClient:
logger.exception("Login error")
return False
- def _api_headers(self) -> Dict[str, str]:
+ def _api_headers(self) -> dict[str, str]:
"""Get headers with CSRF token for API requests."""
if self.csrf_token:
return {"X-CSRF-Token": self.csrf_token}
@@ -170,12 +170,12 @@ class LDRClient:
def quick_research(
self,
query: str,
- model: Optional[str] = None,
- search_engines: Optional[List[str]] = None,
+ model: str | None = None,
+ search_engines: list[str] | None = None,
iterations: int = 2,
wait_for_result: bool = True,
timeout: int = 300,
- ) -> Dict[str, Any]:
+ ) -> dict[str, Any]:
"""
Research a topic using LLMs and search engines.
@@ -248,7 +248,7 @@ class LDRClient:
def wait_for_research(
self, research_id: str, timeout: int = 300
- ) -> Dict[str, Any]:
+ ) -> dict[str, Any]:
"""
Wait for research to complete and get results.
@@ -299,7 +299,7 @@ class LDRClient:
raise RuntimeError(f"Research timed out after {timeout} seconds")
- def get_settings(self) -> Dict[str, Any]:
+ def get_settings(self) -> dict[str, Any]:
"""Get current user settings."""
if not self.logged_in:
raise RuntimeError("Not logged in. Call login() first.")
@@ -333,7 +333,7 @@ class LDRClient:
)
return response.status_code == 200
- def get_history(self) -> List[Dict[str, Any]]:
+ def get_history(self) -> list[dict[str, Any]]:
"""
Get your past research queries.
diff --git a/src/local_deep_research/api/research_functions.py b/src/local_deep_research/api/research_functions.py
index 819e3aa072..406c195ab4 100644
--- a/src/local_deep_research/api/research_functions.py
+++ b/src/local_deep_research/api/research_functions.py
@@ -4,7 +4,7 @@ Provides programmatic access to search and research capabilities.
"""
from datetime import datetime, UTC
-from typing import Any, Callable, Dict, Optional, Union
+from typing import Any, Callable
from loguru import logger
from local_deep_research.settings.logger import log_settings
@@ -26,18 +26,18 @@ def _init_search_system(
provider: str | None = None,
openai_endpoint_url: str | None = None,
progress_callback: Callable[[str, int, dict], None] | None = None,
- search_tool: Optional[str] = None,
+ search_tool: str | None = None,
search_strategy: str = "source_based",
iterations: int = 1,
questions_per_iteration: int = 1,
- retrievers: Optional[Dict[str, Any]] = None,
- llms: Optional[Dict[str, Any]] = None,
- username: Optional[str] = None,
- research_id: Optional[Union[int, str]] = None,
- research_context: Optional[Dict[str, Any]] = None,
+ retrievers: dict[str, Any] | None = None,
+ llms: dict[str, Any] | None = None,
+ username: str | None = None,
+ research_id: str | None = None,
+ research_context: dict[str, Any] | None = None,
programmatic_mode: bool = True,
search_original_query: bool = True,
- settings_snapshot: Optional[Dict[str, Any]] = None,
+ settings_snapshot: dict[str, Any] | None = None,
**kwargs: Any,
) -> AdvancedSearchSystem:
"""
@@ -149,19 +149,19 @@ def _init_search_system(
@no_db_settings
def quick_summary(
query: str,
- research_id: Optional[Union[int, str]] = None,
- retrievers: Optional[Dict[str, Any]] = None,
- llms: Optional[Dict[str, Any]] = None,
- username: Optional[str] = None,
- provider: Optional[str] = None,
- api_key: Optional[str] = None,
- temperature: Optional[float] = None,
- max_search_results: Optional[int] = None,
- settings: Optional[Dict[str, Any]] = None,
- settings_override: Optional[Dict[str, Any]] = None,
+ research_id: str | None = None,
+ retrievers: dict[str, Any] | None = None,
+ llms: dict[str, Any] | None = None,
+ username: str | None = None,
+ provider: str | None = None,
+ api_key: str | None = None,
+ temperature: float | None = None,
+ max_search_results: int | None = None,
+ settings: dict[str, Any] | None = None,
+ settings_override: dict[str, Any] | None = None,
search_original_query: bool = True,
**kwargs: Any,
-) -> Dict[str, Any]:
+) -> dict[str, Any]:
"""
Generate a quick research summary for a given query.
@@ -308,19 +308,19 @@ def quick_summary(
@no_db_settings
def generate_report(
query: str,
- output_file: Optional[str] = None,
- progress_callback: Optional[Callable] = None,
+ output_file: str | None = None,
+ progress_callback: Callable | None = None,
searches_per_section: int = 2,
- retrievers: Optional[Dict[str, Any]] = None,
- llms: Optional[Dict[str, Any]] = None,
- provider: Optional[str] = None,
- api_key: Optional[str] = None,
- temperature: Optional[float] = None,
- max_search_results: Optional[int] = None,
- settings: Optional[Dict[str, Any]] = None,
- settings_override: Optional[Dict[str, Any]] = None,
+ retrievers: dict[str, Any] | None = None,
+ llms: dict[str, Any] | None = None,
+ provider: str | None = None,
+ api_key: str | None = None,
+ temperature: float | None = None,
+ max_search_results: int | None = None,
+ settings: dict[str, Any] | None = None,
+ settings_override: dict[str, Any] | None = None,
**kwargs: Any,
-) -> Dict[str, Any]:
+) -> dict[str, Any]:
"""
Generate a comprehensive, structured research report for a given query.
@@ -445,11 +445,11 @@ def generate_report(
@no_db_settings
def detailed_research(
query: str,
- research_id: Optional[Union[int, str]] = None,
- retrievers: Optional[Dict[str, Any]] = None,
- llms: Optional[Dict[str, Any]] = None,
+ research_id: str | None = None,
+ retrievers: dict[str, Any] | None = None,
+ llms: dict[str, Any] | None = None,
**kwargs: Any,
-) -> Dict[str, Any]:
+) -> dict[str, Any]:
"""
Perform detailed research with comprehensive analysis.
@@ -533,8 +533,8 @@ def analyze_documents(
max_results: int = 10,
temperature: float = 0.7,
force_reindex: bool = False,
- output_file: Optional[str] = None,
-) -> Dict[str, Any]:
+ output_file: str | None = None,
+) -> dict[str, Any]:
"""
Search and analyze documents in a specific local collection.
diff --git a/src/local_deep_research/api/settings_utils.py b/src/local_deep_research/api/settings_utils.py
index 01bd2ea7bc..84402d1d14 100644
--- a/src/local_deep_research/api/settings_utils.py
+++ b/src/local_deep_research/api/settings_utils.py
@@ -8,7 +8,7 @@ web interface.
import os
import copy
-from typing import Any, Dict, Optional, Union
+from typing import Any
from loguru import logger
from ..settings import SettingsManager
@@ -43,7 +43,7 @@ class InMemorySettingsManager(ISettingsManager):
self._settings = {}
self._load_defaults()
- def _get_typed_value(self, setting_data: Dict[str, Any], value: Any) -> Any:
+ def _get_typed_value(self, setting_data: dict[str, Any], value: Any) -> Any:
"""
Convert a value to the appropriate type based on the setting's ui_element.
@@ -137,7 +137,7 @@ class InMemorySettingsManager(ISettingsManager):
return True
return False
- def get_all_settings(self) -> Dict[str, Any]:
+ def get_all_settings(self) -> dict[str, Any]:
"""Get all settings with metadata."""
return copy.deepcopy(self._settings)
@@ -148,8 +148,8 @@ class InMemorySettingsManager(ISettingsManager):
self._load_defaults()
def create_or_update_setting(
- self, setting: Union[Dict[str, Any], Any], commit: bool = True
- ) -> Optional[Any]:
+ self, setting: dict[str, Any] | Any, commit: bool = True
+ ) -> Any | None:
"""Create or update a setting (in memory only)."""
if isinstance(setting, dict) and "key" in setting:
key = setting["key"]
@@ -171,7 +171,7 @@ class InMemorySettingsManager(ISettingsManager):
def import_settings(
self,
- settings_data: Dict[str, Any],
+ settings_data: dict[str, Any],
commit: bool = True,
overwrite: bool = True,
delete_extra: bool = False,
@@ -190,7 +190,7 @@ class InMemorySettingsManager(ISettingsManager):
self._settings[key] = value
-def get_default_settings_snapshot() -> Dict[str, Any]:
+def get_default_settings_snapshot() -> dict[str, Any]:
"""
Get a complete settings snapshot with default values.
@@ -206,10 +206,10 @@ def get_default_settings_snapshot() -> Dict[str, Any]:
def create_settings_snapshot(
- overrides: Optional[Dict[str, Any]] = None,
- base_settings: Optional[Dict[str, Any]] = None,
+ overrides: dict[str, Any] | None = None,
+ base_settings: dict[str, Any] | None = None,
**kwargs,
-) -> Dict[str, Any]:
+) -> dict[str, Any]:
"""
Create a settings snapshot for the programmatic API.
@@ -310,7 +310,7 @@ def create_settings_snapshot(
def extract_setting_value(
- settings_snapshot: Dict[str, Any], key: str, default: Any = None
+ settings_snapshot: dict[str, Any], key: str, default: Any = None
) -> Any:
"""
Extract a setting value from a settings snapshot.
@@ -334,7 +334,7 @@ def extract_setting_value(
def extract_bool_setting(
- settings_snapshot: Dict[str, Any], key: str, default: bool = False
+ settings_snapshot: dict[str, Any], key: str, default: bool = False
) -> bool:
"""
Extract a boolean setting value from a settings snapshot.