mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-23 21:25:33 -04:00
e0ccf250a4
* feat(discovery): detect llama.cpp servers and label local providers Scan port 8080 (llama-server) and 11435 (APFEL) during discovery, fingerprint llama.cpp via its native /props endpoint, and label well-known local serving ports (8080 llama.cpp, 8000 vLLM, 1234 LM Studio, 11434 Ollama) consistently in both the Python provider helper and the JS endpoint UI. Adds a llama.cpp hint to the /setup slash command. * fix(discovery): don't infer the serving tool from the port alone Per review: vLLM, SGLang, llama.cpp and plain OpenAI-compatible servers all share 8000/8080, so labeling by port mislabels real setups (a vLLM box on 8080 shown as llama.cpp). Drop the port->tool assertions from _provider_label and providerLabel; the authoritative signal is the /props fingerprint done during discovery, which is unchanged. Loopback now reads a neutral 'local endpoint' / 'Local'. Tests updated to assert the neutral labels.
55 lines
2.3 KiB
Python
55 lines
2.3 KiB
Python
"""providerLabel() in providers.js must NOT name the serving tool from the port,
|
|
mirroring the Python _provider_label() in src/llm_core.py.
|
|
|
|
A port is not authoritative: vLLM, SGLang, llama.cpp and plain OpenAI-compatible
|
|
servers all routinely share 8000/8080, so a port-only label would mislabel real
|
|
setups (e.g. a vLLM box on :8080 shown as "llama.cpp"). The actual tool is
|
|
identified by probing /props during discovery and stored as the endpoint's name.
|
|
The rule here: loopback → "Local"; private-LAN IPs → "Local"; known remote
|
|
provider hosts → their provider name.
|
|
"""
|
|
import json
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
_REPO = Path(__file__).resolve().parent.parent
|
|
_SRC = _REPO / "static" / "js" / "providers.js"
|
|
_HAS_NODE = shutil.which("node") is not None
|
|
|
|
|
|
def _provider_label(url: str) -> str | None:
|
|
src = _SRC.read_text(encoding="utf-8")
|
|
# Strip the `export` keyword so the module runs standalone.
|
|
src_runnable = src.replace("export function providerLabel", "function providerLabel")
|
|
src_runnable = src_runnable.replace("export default {", "const _default = {")
|
|
js = src_runnable + f"\nconsole.log(JSON.stringify(providerLabel({json.dumps(url)})));"
|
|
proc = subprocess.run(
|
|
["node", "--input-type=module"],
|
|
input=js, capture_output=True, text=True, encoding="utf-8",
|
|
cwd=str(_REPO), timeout=30,
|
|
)
|
|
assert proc.returncode == 0, proc.stderr
|
|
return json.loads(proc.stdout.strip())
|
|
|
|
|
|
@pytest.mark.skipif(not _HAS_NODE, reason="node binary not on PATH")
|
|
@pytest.mark.parametrize("url,expected", [
|
|
# Loopback never names the tool from the port — it isn't authoritative.
|
|
("http://localhost:8080/v1", "Local"),
|
|
("http://127.0.0.1:8080/v1", "Local"),
|
|
("http://localhost:8000/v1", "Local"),
|
|
("http://localhost:1234/v1", "Local"),
|
|
("http://localhost:11434/api", "Local"),
|
|
("http://localhost:9999/v1", "Local"),
|
|
# Known remote provider hosts are still labeled by host suffix.
|
|
("https://api.openai.com/v1", "OpenAI"),
|
|
("https://api.groq.com/openai/v1","Groq"),
|
|
("http://192.168.1.50:8080", "Local"), # private LAN: no port branding
|
|
])
|
|
def test_provider_label_neutral_for_loopback(url, expected):
|
|
assert _provider_label(url) == expected
|