Allow remote detect in production until local Ollama is connected.
Keep KANSHO_ENV=production and require an explicit operator flag instead of treating Prod as Development. Promote to Prod only via merge commit on main. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
dd7858347c
commit
af6fe55577
23 files changed
+236
-27
No files matched your search
@@ -110,7 +110,7 @@ def _parse_model_row(row: dict) -> ModelWindow | None:
|
||||
)
|
||||
|
||||
|
||||
def _fetch_catalog(url: str, key: str) -> dict[str, dict]:
|
||||
def _request_models_payload(url: str, key: str) -> list:
|
||||
headers = {"Content-Type": "application/json"}
|
||||
if key:
|
||||
headers["Authorization"] = f"Bearer {key}"
|
||||
@@ -143,6 +143,11 @@ def _fetch_catalog(url: str, key: str) -> dict[str, dict]:
|
||||
status_code=503,
|
||||
diagnostics={"models_url": url, "reason": "unexpected_shape"},
|
||||
)
|
||||
return rows
|
||||
|
||||
|
||||
def _fetch_catalog(url: str, key: str) -> dict[str, dict]:
|
||||
rows = _request_models_payload(url, key)
|
||||
parsed: dict[str, dict] = {}
|
||||
for row in rows:
|
||||
if not isinstance(row, dict):
|
||||
@@ -249,3 +254,30 @@ def resolve_generate_metadata(config, *, now: float | None = None) -> ModelWindo
|
||||
diagnostics={"model": model, "reason": "model_not_in_catalog"},
|
||||
)
|
||||
return _window_from_cache(fetched[model], model=model)
|
||||
|
||||
|
||||
def list_provider_models(config) -> list[dict]:
|
||||
"""Model ids for the admin picker. Soft-fail; free-text remains valid."""
|
||||
if not config or getattr(config, "mode", None) == "fake":
|
||||
return []
|
||||
url = getattr(config, "url", "") or ""
|
||||
if not url:
|
||||
return []
|
||||
catalog_key = models_url(url)
|
||||
try:
|
||||
rows = _request_models_payload(catalog_key, getattr(config, "key", "") or "")
|
||||
except JournalBudgetError:
|
||||
return []
|
||||
seen: set[str] = set()
|
||||
items: list[dict] = []
|
||||
for row in rows:
|
||||
if not isinstance(row, dict):
|
||||
continue
|
||||
model_id = str(row.get("id") or "").strip()
|
||||
if not model_id or model_id in seen:
|
||||
continue
|
||||
seen.add(model_id)
|
||||
name = str(row.get("name") or model_id).strip() or model_id
|
||||
items.append({"id": model_id, "name": name})
|
||||
items.sort(key=lambda item: item["id"])
|
||||
return items
|
||||
Reference in new issue
Block a user