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: use centralized URL normalization in api_routes.py

LearningCircuit8df11a6f2f1e
diff --git a/src/local_deep_research/web/routes/api_routes.py b/src/local_deep_research/web/routes/api_routes.py
index 98660f9026..b1af17cfe0 100644
--- a/src/local_deep_research/web/routes/api_routes.py
+++ b/src/local_deep_research/web/routes/api_routes.py
@@ -1,11 +1,11 @@
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
+from ...utilities.url_utils import normalize_ollama_url
from ..models.database import get_db_connection
from ..routes.research_routes import active_research, termination_flags
from ..services.research_service import (
@@ -261,27 +261,7 @@ def check_ollama_status():
"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
+ ollama_base_url = normalize_ollama_url(raw_ollama_base_url)
logger.info(f"Checking Ollama status at: {ollama_base_url}")
@@ -406,26 +386,7 @@ def check_ollama_model():
"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
+ ollama_base_url = normalize_ollama_url(raw_ollama_base_url)
# Check if the model is available
try: