implement dropdown when hf inference provider is selected.#14
Conversation
|
@askserge could you review the PR? |
There was a problem hiding this comment.
🤗 Serge says:
The PR adds a dropdown of HF Inference Provider tool-capable models when the "hf" provider is selected, falling back to a free-text input for other providers or when the router is unreachable. The implementation is mostly solid, but there's a correctness bug in the Python caching logic that prevents empty (but valid) fetch results from being cached, causing repeated network requests.
Correctness
_fetch_hf_router_modelsinreviewbot/webapp.pyusesif cached and ...to decide whether to return the cached list. Because an empty list is falsy in Python, a successful fetch that returns no tool-capable models (or an empty list seeded in tests) will never be cached and will trigger a fresh HTTP request on every call. The check should usefetched_at > 0(orcached is not Nonewith a sentinel) to distinguish "never fetched" from "fetched and empty".
Security / Trust boundaries
- The new
/llm-options/hf-modelsendpoint correctly gates behind_require_user, so unauthenticated callers cannot enumerate models. - No secrets are logged or exposed in the new fetch path.
Client-side
- The JS correctly guards against provider-switch races by re-checking
providerEl.value === "hf"after the async fetch. - The text input remains the
named form control and stays in sync with the hidden<select>viachangelisteners, so submitted values are correct.
Tests
- Tests cover the payload parser, garbage tolerance, and the endpoint with a seeded cache. They do not exercise the TTL expiry or the "empty list should be cached" path.
8 LLM turns · 9 tool calls · 416.4s · 92348 in / 22161 out tokens
| now = time.monotonic() | ||
| with _hf_models_lock: | ||
| cached = _hf_models_cache["models"] | ||
| if cached and now - _hf_models_cache["fetched_at"] < _HF_MODELS_TTL_SECONDS: |
There was a problem hiding this comment.
The cache check if cached and ... treats an empty list as a cache miss. This means a successful fetch that returns [] (or an empty cache seeded in tests) will never be served from cache and will trigger a fresh HTTP request every time.
Use the timestamp to determine whether the cache has been populated instead:
| if cached and now - _hf_models_cache["fetched_at"] < _HF_MODELS_TTL_SECONDS: | |
| with _hf_models_lock: | |
| cached = _hf_models_cache["models"] | |
| if _hf_models_cache["fetched_at"] > 0 and now - _hf_models_cache["fetched_at"] < _HF_MODELS_TTL_SECONDS: | |
| return cached |
|
What Serge says :) |
|
@askserge could you review the PR? |
There was a problem hiding this comment.
🤗 Serge says:
The PR cleanly implements a dropdown of tool-capable HF Inference Provider models when the "hf" provider is selected, falling back to a free-text input for other providers or when the router is unreachable. The server-side parsing, caching, and endpoint are well-tested, and the client-side sync between the hidden text input and the visible select keeps form submission straightforward. No correctness or security issues were found.
6 LLM turns · 9 tool calls · 79.5s · 62779 in / 3908 out tokens
Fixes #3