mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-15 00:11:15 +03:00
decouple list_models from provider init
switching providers in the UI left an invalid model in the config, then _init_provider would fail and list_models would return an empty list, making it impossible to select a valid model
This commit is contained in:
parent
f7f73e0de4
commit
3fcd5a90b3
@ -238,10 +238,15 @@ class LlamaCppClient(GenAIClient):
|
||||
|
||||
def list_models(self) -> list[str]:
|
||||
"""Return available model IDs from the llama.cpp server."""
|
||||
if self.provider is None:
|
||||
base_url = self.provider or (
|
||||
self.genai_config.base_url.rstrip("/")
|
||||
if self.genai_config.base_url
|
||||
else None
|
||||
)
|
||||
if base_url is None:
|
||||
return []
|
||||
try:
|
||||
response = requests.get(f"{self.provider}/v1/models", timeout=10)
|
||||
response = requests.get(f"{base_url}/v1/models", timeout=10)
|
||||
response.raise_for_status()
|
||||
models = []
|
||||
for m in response.json().get("data", []):
|
||||
|
||||
@ -134,10 +134,20 @@ class OllamaClient(GenAIClient):
|
||||
|
||||
def list_models(self) -> list[str]:
|
||||
"""Return available model names from the Ollama server."""
|
||||
if self.provider is None:
|
||||
return []
|
||||
client = self.provider
|
||||
if client is None:
|
||||
# Provider init may have failed due to invalid model, but we can
|
||||
# still list available models with a fresh client.
|
||||
if not self.genai_config.base_url:
|
||||
return []
|
||||
try:
|
||||
client = ApiClient(
|
||||
host=self.genai_config.base_url, timeout=self.timeout
|
||||
)
|
||||
except Exception:
|
||||
return []
|
||||
try:
|
||||
response = self.provider.list()
|
||||
response = client.list()
|
||||
return sorted(
|
||||
m.get("name", m.get("model", "")) for m in response.get("models", [])
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user