Expose all profiles through llama.cpp discovery

This commit is contained in:
Mikei386
2026-09-15 11:28:34 +02:00
parent 23f4970072
commit 80917e72b4
3 changed files with 52 additions and 0 deletions
+32
View File
@@ -1859,6 +1859,13 @@ class Handler(BaseHTTPRequestHandler):
self._send_auth_required()
elif path == "/v1/models" and self.command == "GET":
self._send_json(200, self._models_payload())
elif path == "/models" and self.command == "GET":
# llama.cpp clients (notably OpenClaw's existing-server
# provider) probe the native catalog before /v1/models. Do
# not proxy this request to the one currently active profile,
# otherwise the remaining switchable profiles disappear from
# discovery.
self._send_json(200, self._llamacpp_models_payload())
elif path == "/status" and self.command == "GET":
self._send_json(200, self._status_payload())
elif path == "/mode" and self.command == "GET":
@@ -2076,6 +2083,31 @@ class Handler(BaseHTTPRequestHandler):
"data": models,
}
@staticmethod
def _llamacpp_models_payload() -> dict:
"""Return every switchable profile in llama.cpp's native catalog."""
active = current_profile()
models = []
for name, ctx in PROFILES.items():
model_id = EXPECTED_MODELS.get(name) or f"qwen-{name}"
models.append({
"id": model_id,
"object": "model",
"created": 0,
"owned_by": "ai-profile-router",
"context_length": ctx,
"context_window": ctx,
"meta": {"n_ctx_train": ctx},
"status": {
"value": "loaded" if name == active else "unloaded",
},
"architecture": {
"input_modalities": ["text", "image"],
"output_modalities": ["text"],
},
})
return {"data": models}
def _status_payload(self) -> dict:
up = upstream_status()
img = STATE.image