Refresh AITURK model discovery automatically in desktop beta 4

This commit is contained in:
2026-09-06 01:37:27 +03:00
parent aa498f4cbb
commit 237d1e2060
8 changed files with 111 additions and 10 deletions
+17 -4
View File
@@ -8,6 +8,7 @@ Add, remove, or reorder entries here — both `hermes setup` and
from __future__ import annotations
import copy
import contextvars
import json
import http.client
import logging
@@ -4809,10 +4810,11 @@ def _spawn_swr_refresh(cache_key: str, refresh_fn=None) -> None:
``PROVIDER_REGISTRY`` slug and refreshed via :func:`provider_model_ids`
(the original behavior).
"""
refresh_identity = (str(_provider_models_cache_path()), cache_key)
with _swr_refresh_lock:
if cache_key in _swr_refresh_inflight:
if refresh_identity in _swr_refresh_inflight:
return
_swr_refresh_inflight.add(cache_key)
_swr_refresh_inflight.add(refresh_identity)
def _default_refresh():
live = provider_model_ids(cache_key, force_refresh=True)
@@ -4847,10 +4849,10 @@ def _spawn_swr_refresh(cache_key: str, refresh_fn=None) -> None:
logger.debug("SWR refresh failed for %s", cache_key, exc_info=True)
finally:
with _swr_refresh_lock:
_swr_refresh_inflight.discard(cache_key)
_swr_refresh_inflight.discard(refresh_identity)
threading.Thread(
target=_refresh, daemon=True, name=f"model-cache-swr-{cache_key}"
target=contextvars.copy_context().run, args=(_refresh,), daemon=True, name=f"model-cache-swr-{cache_key}"
).start()
@@ -6855,6 +6857,17 @@ def cached_fetch_api_models(
entry = cache.get(cache_key)
now = time.time()
if normalized_url == "https://ai.turkservis.online/v1":
ttl_seconds = min(ttl_seconds, 30)
if cache_only and (not _cache_entry_valid(entry, fp) or now - entry["at"] >= ttl_seconds):
def _refresh_aiturk():
live = fetch_api_models(api_key, base_url, timeout=timeout,
api_mode=api_mode, headers=headers)
if live is None:
return None
return {"fp": fp, "at": time.time(), "models": list(live)}
_spawn_swr_refresh(cache_key, _refresh_aiturk)
if cache_only:
# Same trust window as the stale-while-revalidate tier below, minus
# the revalidation: an entry this side of the bound is good enough to