mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-15 00:11:15 +03:00
Correctly query specific model props
This commit is contained in:
parent
0729af7246
commit
fc8851b8da
@ -62,7 +62,9 @@ class LlamaCppClient(GenAIClient):
|
|||||||
if base_url is None:
|
if base_url is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Query /v1/models to validate the model and extract capabilities
|
configured_model = self.genai_config.model
|
||||||
|
|
||||||
|
# Query /v1/models to validate the configured model exists
|
||||||
try:
|
try:
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
f"{base_url}/v1/models",
|
f"{base_url}/v1/models",
|
||||||
@ -71,17 +73,16 @@ class LlamaCppClient(GenAIClient):
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
models_data = response.json()
|
models_data = response.json()
|
||||||
|
|
||||||
matched_model = None
|
model_found = False
|
||||||
configured_model = self.genai_config.model
|
|
||||||
for model in models_data.get("data", []):
|
for model in models_data.get("data", []):
|
||||||
model_ids = {model.get("id")}
|
model_ids = {model.get("id")}
|
||||||
for alias in model.get("aliases", []):
|
for alias in model.get("aliases", []):
|
||||||
model_ids.add(alias)
|
model_ids.add(alias)
|
||||||
if configured_model in model_ids:
|
if configured_model in model_ids:
|
||||||
matched_model = model
|
model_found = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if matched_model is None:
|
if not model_found:
|
||||||
available = []
|
available = []
|
||||||
for m in models_data.get("data", []):
|
for m in models_data.get("data", []):
|
||||||
available.append(m.get("id", "unknown"))
|
available.append(m.get("id", "unknown"))
|
||||||
@ -93,10 +94,37 @@ class LlamaCppClient(GenAIClient):
|
|||||||
available,
|
available,
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(
|
||||||
|
"Failed to query llama.cpp /v1/models endpoint: %s. "
|
||||||
|
"Model validation skipped.",
|
||||||
|
e,
|
||||||
|
)
|
||||||
|
|
||||||
# Parse capabilities from the model's server launch args
|
# Query /props for context size, modalities, and tool support
|
||||||
args = matched_model.get("status", {}).get("args", [])
|
try:
|
||||||
self._parse_model_args(args)
|
response = requests.get(
|
||||||
|
f"{base_url}/props",
|
||||||
|
params={"model": configured_model},
|
||||||
|
timeout=10,
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
props = response.json()
|
||||||
|
|
||||||
|
# Context size from server runtime config
|
||||||
|
default_settings = props.get("default_generation_settings", {})
|
||||||
|
n_ctx = default_settings.get("n_ctx")
|
||||||
|
if n_ctx:
|
||||||
|
self._context_size = int(n_ctx)
|
||||||
|
|
||||||
|
# Modalities (vision, audio)
|
||||||
|
modalities = props.get("modalities", {})
|
||||||
|
self._supports_vision = modalities.get("vision", False)
|
||||||
|
self._supports_audio = modalities.get("audio", False)
|
||||||
|
|
||||||
|
# Tool support from chat template capabilities
|
||||||
|
chat_caps = props.get("chat_template_caps", {})
|
||||||
|
self._supports_tools = chat_caps.get("supports_tools", False)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"llama.cpp model '%s' initialized — context: %s, vision: %s, audio: %s, tools: %s",
|
"llama.cpp model '%s' initialized — context: %s, vision: %s, audio: %s, tools: %s",
|
||||||
@ -108,26 +136,13 @@ class LlamaCppClient(GenAIClient):
|
|||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Failed to query llama.cpp /v1/models endpoint: %s. "
|
"Failed to query llama.cpp /props endpoint: %s. "
|
||||||
"Model validation skipped.",
|
"Using defaults for context size and capabilities.",
|
||||||
e,
|
e,
|
||||||
)
|
)
|
||||||
|
|
||||||
return base_url
|
return base_url
|
||||||
|
|
||||||
def _parse_model_args(self, args: list[str]) -> None:
|
|
||||||
"""Extract context size and capabilities from llama-server launch args."""
|
|
||||||
for i, arg in enumerate(args):
|
|
||||||
if arg == "--ctx-size" and i + 1 < len(args):
|
|
||||||
try:
|
|
||||||
self._context_size = int(args[i + 1])
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
elif arg == "--mmproj":
|
|
||||||
self._supports_vision = True
|
|
||||||
elif arg == "--jinja":
|
|
||||||
self._supports_tools = True
|
|
||||||
|
|
||||||
def _send(
|
def _send(
|
||||||
self,
|
self,
|
||||||
prompt: str,
|
prompt: str,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user