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: ollama server url parsing

Samf84a66a78908
diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.py
index e00fb38541..ca5befd046 100644
--- a/src/local_deep_research/config/llm_config.py
+++ b/src/local_deep_research/config/llm_config.py
@@ -1,5 +1,6 @@
import logging
import os
+from urllib.parse import urlparse # urlunparse removed if not used elsewhere
from langchain_anthropic import ChatAnthropic
from langchain_community.llms import VLLM
@@ -141,7 +142,27 @@ def get_llm(model_name=None, temperature=None, provider=None, openai_endpoint_ur
elif provider == "ollama":
try:
# Use the configurable Ollama base URL
- base_url = get_db_setting("llm.ollama.url", "http://localhost:11434")
+ raw_base_url = get_db_setting("llm.ollama.url", "http://localhost:11434")
+ parsed_url = urlparse(raw_base_url)
+ if parsed_url.scheme and not parsed_url.netloc and parsed_url.path:
+ # Corrects "scheme:hostname" to "scheme://hostname"
+ scheme_to_use = parsed_url.scheme if parsed_url.scheme in ("http", "https") else "https"
+ base_url = f"{scheme_to_use}://{parsed_url.path}"
+ elif not parsed_url.scheme:
+ # Handles "hostname" or "//hostname"
+ temp_host_path = raw_base_url
+ if raw_base_url.startswith("//"):
+ temp_host_path = raw_base_url[2:]
+
+ is_localhost = temp_host_path.startswith("localhost") or temp_host_path.startswith("127.0.0.1")
+
+ if is_localhost:
+ base_url = "http://" + temp_host_path
+ else:
+ base_url = "https://" + temp_host_path
+ else:
+ # Assumed to be well-formed (e.g., "http://hostname", "https://hostname") or other scheme.
+ base_url = raw_base_url
# Check if Ollama is available before trying to use it
if not is_ollama_available():
@@ -371,7 +392,27 @@ def is_ollama_available():
try:
import requests
- base_url = get_db_setting("llm.ollama.url", "http://localhost:11434")
+ raw_base_url = get_db_setting("llm.ollama.url", "http://localhost:11434")
+ parsed_url = urlparse(raw_base_url)
+ if parsed_url.scheme and not parsed_url.netloc and parsed_url.path:
+ # Corrects "scheme:hostname" to "scheme://hostname"
+ scheme_to_use = parsed_url.scheme if parsed_url.scheme in ("http", "https") else "https"
+ base_url = f"{scheme_to_use}://{parsed_url.path}"
+ elif not parsed_url.scheme:
+ # Handles "hostname" or "//hostname"
+ temp_host_path = raw_base_url
+ if raw_base_url.startswith("//"):
+ temp_host_path = raw_base_url[2:]
+
+ is_localhost = temp_host_path.startswith("localhost") or temp_host_path.startswith("127.0.0.1")
+
+ if is_localhost:
+ base_url = "http://" + temp_host_path
+ else:
+ base_url = "https://" + temp_host_path
+ else:
+ # Assumed to be well-formed (e.g., "http://hostname", "https://hostname") or other scheme.
+ base_url = raw_base_url
logger.info(f"Checking Ollama availability at {base_url}/api/tags")
try:
diff --git a/src/local_deep_research/web/routes/api_routes.py b/src/local_deep_research/web/routes/api_routes.py
index b253ecd00c..98660f9026 100644
--- a/src/local_deep_research/web/routes/api_routes.py
+++ b/src/local_deep_research/web/routes/api_routes.py
@@ -1,6 +1,7 @@
import json
import logging
import os
+from urllib.parse import urlparse # urlunparse removed if not used elsewhere
import requests
from flask import Blueprint, current_app, jsonify, request
@@ -256,11 +257,32 @@ def check_ollama_status():
)
# Get Ollama API URL
- ollama_base_url = os.getenv(
+ raw_ollama_base_url = os.getenv(
"OLLAMA_BASE_URL",
llm_config.get("ollama_base_url", "http://localhost:11434"),
)
+ parsed_url = urlparse(raw_ollama_base_url)
+ if parsed_url.scheme and not parsed_url.netloc and parsed_url.path:
+ # Corrects "scheme:hostname" to "scheme://hostname"
+ scheme_to_use = parsed_url.scheme if parsed_url.scheme in ("http", "https") else "https"
+ ollama_base_url = f"{scheme_to_use}://{parsed_url.path}"
+ elif not parsed_url.scheme:
+ # Handles "hostname" or "//hostname"
+ temp_host_path = raw_ollama_base_url
+ if raw_ollama_base_url.startswith("//"):
+ temp_host_path = raw_ollama_base_url[2:]
+
+ is_localhost = temp_host_path.startswith("localhost") or temp_host_path.startswith("127.0.0.1")
+
+ if is_localhost:
+ ollama_base_url = "http://" + temp_host_path
+ else:
+ ollama_base_url = "https://" + temp_host_path
+ else:
+ # Assumed to be well-formed (e.g., "http://hostname", "https://hostname") or other scheme.
+ ollama_base_url = raw_ollama_base_url
+
logger.info(f"Checking Ollama status at: {ollama_base_url}")
# Check if Ollama is running
@@ -380,10 +402,30 @@ def check_ollama_model():
# Log which model we're checking for debugging
logger.info(f"Checking availability of Ollama model: {model_name}")
- ollama_base_url = os.getenv(
+ raw_ollama_base_url = os.getenv(
"OLLAMA_BASE_URL",
llm_config.get("ollama_base_url", "http://localhost:11434"),
)
+ parsed_url = urlparse(raw_ollama_base_url)
+ if parsed_url.scheme and not parsed_url.netloc and parsed_url.path:
+ # Corrects "scheme:hostname" to "scheme://hostname"
+ scheme_to_use = parsed_url.scheme if parsed_url.scheme in ("http", "https") else "https"
+ ollama_base_url = f"{scheme_to_use}://{parsed_url.path}"
+ elif not parsed_url.scheme:
+ # Handles "hostname" or "//hostname"
+ temp_host_path = raw_ollama_base_url
+ if raw_ollama_base_url.startswith("//"):
+ temp_host_path = raw_ollama_base_url[2:]
+
+ is_localhost = temp_host_path.startswith("localhost") or temp_host_path.startswith("127.0.0.1")
+
+ if is_localhost:
+ ollama_base_url = "http://" + temp_host_path
+ else:
+ ollama_base_url = "https://" + temp_host_path
+ else:
+ # Assumed to be well-formed (e.g., "http://hostname", "https://hostname") or other scheme.
+ ollama_base_url = raw_ollama_base_url
# Check if the model is available
try:
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.py
index f697b67b24..5bea9c3ad8 100644
--- a/src/local_deep_research/web/routes/settings_routes.py
+++ b/src/local_deep_research/web/routes/settings_routes.py
@@ -4,6 +4,7 @@ import os
import platform
import subprocess
from typing import Any, Optional, Tuple
+from urllib.parse import urlparse # urlunparse removed if not used elsewhere
import requests
from flask import (
@@ -667,7 +668,28 @@ def api_get_available_models():
try:
current_app.logger.info("Attempting to connect to Ollama API")
- base_url = get_db_setting("llm.ollama.url", "http://localhost:11434")
+ raw_base_url = get_db_setting("llm.ollama.url", "http://localhost:11434")
+ parsed_url = urlparse(raw_base_url)
+ if parsed_url.scheme and not parsed_url.netloc and parsed_url.path:
+ # Corrects "scheme:hostname" to "scheme://hostname"
+ scheme_to_use = parsed_url.scheme if parsed_url.scheme in ("http", "https") else "https"
+ base_url = f"{scheme_to_use}://{parsed_url.path}"
+ elif not parsed_url.scheme:
+ # Handles "hostname" or "//hostname"
+ temp_host_path = raw_base_url
+ if raw_base_url.startswith("//"):
+ temp_host_path = raw_base_url[2:]
+
+ is_localhost = temp_host_path.startswith("localhost") or temp_host_path.startswith("127.0.0.1")
+
+ if is_localhost:
+ base_url = "http://" + temp_host_path
+ else:
+ base_url = "https://" + temp_host_path
+ else:
+ # Assumed to be well-formed (e.g., "http://hostname", "https://hostname") or other scheme.
+ base_url = raw_base_url
+
ollama_response = requests.get(f"{base_url}/api/tags", timeout=5)
current_app.logger.debug(
@@ -1270,10 +1292,31 @@ def check_ollama_status():
"""Check if Ollama is running and available"""
try:
# Set a shorter timeout for the request
- base_url = os.getenv(
+ raw_base_url = os.getenv(
"OLLAMA_BASE_URL",
- "http://localhost:11434",
+ get_db_setting("llm.ollama.url", "http://localhost:11434"), # Use db setting as fallback
)
+ parsed_url = urlparse(raw_base_url)
+ if parsed_url.scheme and not parsed_url.netloc and parsed_url.path:
+ # Corrects "scheme:hostname" to "scheme://hostname"
+ scheme_to_use = parsed_url.scheme if parsed_url.scheme in ("http", "https") else "https"
+ base_url = f"{scheme_to_use}://{parsed_url.path}"
+ elif not parsed_url.scheme:
+ # Handles "hostname" or "//hostname"
+ temp_host_path = raw_base_url
+ if raw_base_url.startswith("//"):
+ temp_host_path = raw_base_url[2:]
+
+ is_localhost = temp_host_path.startswith("localhost") or temp_host_path.startswith("127.0.0.1")
+
+ if is_localhost:
+ base_url = "http://" + temp_host_path
+ else:
+ base_url = "https://" + temp_host_path
+ else:
+ # Assumed to be well-formed (e.g., "http://hostname", "https://hostname") or other scheme.
+ base_url = raw_base_url
+
response = requests.get(f"{base_url}/api/version", timeout=2.0)
if response.status_code == 200:
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_local.py b/src/local_deep_research/web_search_engines/engines/search_engine_local.py
index f6fb013d15..54f345f986 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_local.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_local.py
@@ -1,4 +1,5 @@
import hashlib
+import hashlib
import json
import logging
import os
@@ -8,6 +9,7 @@ from concurrent.futures import ProcessPoolExecutor
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional
+from urllib.parse import urlparse
from faiss import IndexFlatL2
from langchain_community.docstore.in_memory import InMemoryDocstore
@@ -169,12 +171,23 @@ class LocalEmbeddingManager:
if self.embedding_model_type == "ollama":
# Use Ollama for embeddings
if not self.ollama_base_url:
- self.ollama_base_url = get_db_setting(
+ raw_ollama_base_url = get_db_setting(
"llm.ollama.url", "http://localhost:11434"
)
+ parsed_url = urlparse(raw_ollama_base_url)
+ if not parsed_url.scheme:
+ self.ollama_base_url = urlunparse(parsed_url._replace(scheme="https"))
+ else:
+ self.ollama_base_url = raw_ollama_base_url
+ else:
+ # Ensure scheme is present if ollama_base_url was passed in constructor
+ parsed_url = urlparse(self.ollama_base_url)
+ if not parsed_url.scheme:
+ self.ollama_base_url = urlunparse(parsed_url._replace(scheme="https"))
+
logger.info(
- f"Initializing Ollama embeddings with model {self.embedding_model}"
+ f"Initializing Ollama embeddings with model {self.embedding_model} and base_url {self.ollama_base_url}"
)
return OllamaEmbeddings(
model=self.embedding_model, base_url=self.ollama_base_url