MCPcopy
hub / github.com/mudler/LocalAI / _resolve_model_path

Function _resolve_model_path

backend/python/insightface/engines.py:534–563  ·  view source on GitHub ↗

Resolve an ONNX file path across the paths LocalAI might deliver it from. Search order: 1. The path itself if it already resolves (absolute, or relative to CWD). 2. `model_dir` (typically `os.path.dirname(ModelOptions.ModelFile)`) — this is how LocalAI surfaces gallery-mana

(path: str, model_dir: str | None = None)

Source from the content-addressed store, hash-verified

532
533
534def _resolve_model_path(path: str, model_dir: str | None = None) -> str:
535 """Resolve an ONNX file path across the paths LocalAI might deliver it from.
536
537 Search order:
538 1. The path itself if it already resolves (absolute, or relative to CWD).
539 2. `model_dir` (typically `os.path.dirname(ModelOptions.ModelFile)`) —
540 this is how LocalAI surfaces gallery-managed files. When the gallery
541 entry lists `files:`, each one lands under the models directory and
542 backends load them via filename anchored by ModelFile.
543 3. `<script_dir>/<path-without-leading-slash>` — covers dev layouts
544 where someone manually dropped weights inside the backend dir.
545
546 If none hit, return the literal input so cv2/insightface surfaces a
547 clearer error naming the actually-attempted path.
548 """
549 import os
550
551 if os.path.isfile(path):
552 return path
553 stripped = path.lstrip("/")
554 candidates: list[str] = []
555 if model_dir:
556 candidates.append(os.path.join(model_dir, os.path.basename(path)))
557 candidates.append(os.path.join(model_dir, stripped))
558 script_dir = os.path.dirname(os.path.abspath(__file__))
559 candidates.append(os.path.join(script_dir, stripped))
560 for c in candidates:
561 if os.path.isfile(c):
562 return c
563 return path
564
565
566def build_engine(name: str) -> FaceEngine:

Callers 2

_build_antispooferFunction · 0.85
prepareMethod · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected