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 constants for hardcoded default URLs (#2934)

LearningCircuit12e3e1fe12b3
diff --git a/src/local_deep_research/config/constants.py b/src/local_deep_research/config/constants.py
new file mode 100644
index 0000000000..92c316b79b
--- /dev/null
+++ b/src/local_deep_research/config/constants.py
@@ -0,0 +1,4 @@
+"""Shared constants used across the codebase."""
+
+DEFAULT_OLLAMA_URL = "http://localhost:11434"
+DEFAULT_LMSTUDIO_URL = "http://localhost:1234/v1"
diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.py
index b2d3f31cc7..327dee87fa 100644
--- a/src/local_deep_research/config/llm_config.py
+++ b/src/local_deep_research/config/llm_config.py
@@ -10,6 +10,7 @@ from ..llm import get_llm_from_registry, is_llm_registered
from ..utilities.search_utilities import remove_think_tags
from ..utilities.url_utils import normalize_url
from ..security import safe_get
+from .constants import DEFAULT_OLLAMA_URL, DEFAULT_LMSTUDIO_URL
# Import providers module to trigger auto-discovery
try:
@@ -529,13 +530,13 @@ def get_llm(
# Use the configurable Ollama base URL
raw_base_url = get_setting_from_snapshot(
"llm.ollama.url",
- "http://localhost:11434",
+ DEFAULT_OLLAMA_URL,
settings_snapshot=settings_snapshot,
)
base_url = (
normalize_url(raw_base_url)
if raw_base_url
- else "http://localhost:11434"
+ else DEFAULT_OLLAMA_URL
)
# Check if Ollama is available before trying to use it
@@ -661,7 +662,7 @@ def get_llm(
# LM Studio supports OpenAI API format, so we can use ChatOpenAI directly
lmstudio_url = get_setting_from_snapshot(
"llm.lmstudio.url",
- "http://localhost:1234/v1",
+ DEFAULT_LMSTUDIO_URL,
settings_snapshot=settings_snapshot,
)
# Use URL as-is (default already includes /v1)
diff --git a/src/local_deep_research/llm/providers/implementations/lmstudio.py b/src/local_deep_research/llm/providers/implementations/lmstudio.py
index 1820a5a6c5..309a21d9b1 100644
--- a/src/local_deep_research/llm/providers/implementations/lmstudio.py
+++ b/src/local_deep_research/llm/providers/implementations/lmstudio.py
@@ -2,6 +2,7 @@
from loguru import logger
+from ....config.constants import DEFAULT_LMSTUDIO_URL
from ....utilities.url_utils import normalize_url
from ...llm_registry import register_llm
from ..openai_base import OpenAICompatibleProvider
@@ -16,7 +17,7 @@ class LMStudioProvider(OpenAICompatibleProvider):
provider_name = "LM Studio"
api_key_setting = None # LM Studio doesn't need a real API key
url_setting = "llm.lmstudio.url" # Settings key for URL
- default_base_url = "http://localhost:1234/v1"
+ default_base_url = DEFAULT_LMSTUDIO_URL
default_model = "local-model" # User should specify their loaded model
# Metadata for auto-discovery
diff --git a/src/local_deep_research/utilities/llm_utils.py b/src/local_deep_research/utilities/llm_utils.py
index c31ab9e72f..524143ddba 100644
--- a/src/local_deep_research/utilities/llm_utils.py
+++ b/src/local_deep_research/utilities/llm_utils.py
@@ -9,6 +9,7 @@ when the user's llm_config.py is missing or incomplete.
from loguru import logger
from typing import Any, Optional, Dict
+from ..config.constants import DEFAULT_OLLAMA_URL
from ..config.thread_settings import get_setting_from_snapshot
@@ -55,7 +56,7 @@ def get_ollama_base_url(
"embeddings.ollama.url",
default=get_setting_from_snapshot(
"llm.ollama.url", # Fall back to LLM setting
- default="http://localhost:11434",
+ default=DEFAULT_OLLAMA_URL,
settings_snapshot=settings_snapshot,
),
settings_snapshot=settings_snapshot,
@@ -63,7 +64,7 @@ def get_ollama_base_url(
return (
normalize_url(raw_base_url)
if raw_base_url
- else "http://localhost:11434"
+ else DEFAULT_OLLAMA_URL
)
diff --git a/src/local_deep_research/web/routes/api_routes.py b/src/local_deep_research/web/routes/api_routes.py
index 7e9feb96b0..c53b8b3486 100644
--- a/src/local_deep_research/web/routes/api_routes.py
+++ b/src/local_deep_research/web/routes/api_routes.py
@@ -9,6 +9,7 @@ from loguru import logger
from ...database.models import ResearchHistory
from ...database.session_context import get_user_db_session
+from ...config.constants import DEFAULT_OLLAMA_URL
from ...utilities.url_utils import normalize_url
from ...security.decorators import require_json_body
from ..auth.decorators import login_required
@@ -302,12 +303,12 @@ def check_ollama_status():
# Get Ollama API URL from LLM config
raw_ollama_base_url = llm_config.get(
- "ollama_base_url", "http://localhost:11434"
+ "ollama_base_url", DEFAULT_OLLAMA_URL
)
ollama_base_url = (
normalize_url(raw_ollama_base_url)
if raw_ollama_base_url
- else "http://localhost:11434"
+ else DEFAULT_OLLAMA_URL
)
logger.info(f"Checking Ollama status at: {ollama_base_url}")
@@ -436,12 +437,12 @@ def check_ollama_model():
# Get Ollama API URL from LLM config
raw_ollama_base_url = llm_config.get(
- "ollama_base_url", "http://localhost:11434"
+ "ollama_base_url", DEFAULT_OLLAMA_URL
)
ollama_base_url = (
normalize_url(raw_ollama_base_url)
if raw_ollama_base_url
- else "http://localhost:11434"
+ else DEFAULT_OLLAMA_URL
)
# Check if the model is available
diff --git a/src/local_deep_research/web/routes/research_routes.py b/src/local_deep_research/web/routes/research_routes.py
index 6fa5bb79be..b82fab39bc 100644
--- a/src/local_deep_research/web/routes/research_routes.py
+++ b/src/local_deep_research/web/routes/research_routes.py
@@ -18,6 +18,7 @@ from ...settings.logger import log_settings
from sqlalchemy import func
# Security imports
+from ...config.constants import DEFAULT_OLLAMA_URL
from ...constants import ResearchStatus
from ...security import (
FileUploadValidator,
@@ -190,7 +191,7 @@ def start_research():
ollama_url = data.get("ollama_url")
if not ollama_url and model_provider == "OLLAMA":
ollama_url = settings_manager.get_setting(
- "llm.ollama.url", "http://localhost:11434"
+ "llm.ollama.url", DEFAULT_OLLAMA_URL
)
logger.debug(
f"No ollama_url in request, using database setting: {ollama_url}"
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.py
index f96bac8aeb..1257ccd3b2 100644
--- a/src/local_deep_research/web/routes/settings_routes.py
+++ b/src/local_deep_research/web/routes/settings_routes.py
@@ -55,6 +55,7 @@ from flask import (
from flask_wtf.csrf import generate_csrf
from loguru import logger
+from ...config.constants import DEFAULT_OLLAMA_URL
from ...config.paths import get_data_directory, get_encrypted_database_path
from ...database.models import Setting, SettingType
from ...database.session_context import get_user_db_session
@@ -1083,12 +1084,12 @@ def api_get_available_models():
logger.info("Attempting to connect to Ollama API")
raw_base_url = _get_setting_from_session(
- "llm.ollama.url", "http://localhost:11434"
+ "llm.ollama.url", DEFAULT_OLLAMA_URL
)
base_url = (
normalize_url(raw_base_url)
if raw_base_url
- else "http://localhost:11434"
+ else DEFAULT_OLLAMA_URL
)
ollama_response = safe_get(
@@ -1971,12 +1972,12 @@ def check_ollama_status():
try:
# Get Ollama URL from settings
raw_base_url = _get_setting_from_session(
- "llm.ollama.url", "http://localhost:11434"
+ "llm.ollama.url", DEFAULT_OLLAMA_URL
)
base_url = (
normalize_url(raw_base_url)
if raw_base_url
- else "http://localhost:11434"
+ else DEFAULT_OLLAMA_URL
)
response = safe_get(