mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 09:45:24 -04:00
refactor(tests): replace local function copies in test_endpoint_resolver with real imports (#3359)
* refactor(tests): replace local function copies in test_endpoint_resolver with real imports The test file carried 9 verbatim copies of src/endpoint_resolver.py functions to avoid import-pollution concerns, but these copies are a drift hazard — PR #3343 had to update both in parallel. Replace them with direct imports so future changes to endpoint_resolver are automatically exercised by the test suite. Also fixes _ollama_api_root in endpoint_resolver.py: the bare-URL Ollama case (e.g. http://nas:11434 with empty path) was already handled correctly in the test copy but was missing from the real function, which would return /chat instead of /api/chat for native Ollama endpoints without an explicit /api prefix. Closes #3351 * refactor: import _ollama_api_root from llm_core instead of duplicating it endpoint_resolver already imports _detect_provider and _host_match from llm_core. Add _ollama_api_root to that import and remove the local copy, collapsing two implementations to one source of truth. llm_core's version is a superset (also strips /api/chat|tags|generate paths), and since normalize_base already removes those suffixes upstream the result is identical for every input used here.
This commit is contained in:
@@ -12,7 +12,7 @@ from typing import Optional, Tuple, Dict
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
||||
from core.database import SessionLocal, ModelEndpoint
|
||||
from src.llm_core import _detect_provider, _host_match
|
||||
from src.llm_core import _detect_provider, _host_match, _ollama_api_root
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -150,19 +150,6 @@ def _anthropic_api_root(base: str) -> str:
|
||||
return base
|
||||
|
||||
|
||||
def _ollama_api_root(base: str) -> str:
|
||||
"""Return the native Ollama API root, adding /api for ollama.com hosts."""
|
||||
base = (base or "").strip().rstrip("/")
|
||||
parsed = urlparse(base)
|
||||
path = (parsed.path or "").rstrip("/")
|
||||
if path.endswith("/api"):
|
||||
return base
|
||||
if _host_match(base, "ollama.com"):
|
||||
root = f"{parsed.scheme}://{parsed.netloc}" if parsed.scheme and parsed.netloc else "https://ollama.com"
|
||||
return root.rstrip("/") + "/api"
|
||||
return base
|
||||
|
||||
|
||||
def build_chat_url(base: str) -> str:
|
||||
"""Return the correct chat endpoint URL for a given base."""
|
||||
base = resolve_url(base)
|
||||
|
||||
Reference in New Issue
Block a user