MCPcopy Index your code
hub / github.com/mudler/LocalAI / ListFilesInModelPath

Method ListFilesInModelPath

pkg/model/loader.go:251–289  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

249const retryTimeout = time.Duration(2 * time.Minute)
250
251func (ml *ModelLoader) ListFilesInModelPath() ([]string, error) {
252 files, err := os.ReadDir(ml.ModelPath)
253 if err != nil {
254 return []string{}, err
255 }
256
257 models := []string{}
258FILE:
259 for _, file := range files {
260
261 for _, skip := range knownFilesToSkip {
262 if strings.EqualFold(file.Name(), skip) {
263 continue FILE
264 }
265 }
266
267 // Skip templates, YAML, .keep, .json, .DS_Store, and other non-model files.
268 // Use case-insensitive matching so e.g. CACHEDIR.TAG is caught by ".tag".
269 lowerName := strings.ToLower(file.Name())
270 for _, skip := range knownModelsNameSuffixToSkip {
271 if strings.HasSuffix(lowerName, skip) {
272 continue FILE
273 }
274 }
275 // Skip backup files created by LocalAI or huggingface_hub (e.g. model.yaml.bak-pre-gpumem072).
276 if strings.Contains(lowerName, ".bak") {
277 continue FILE
278 }
279
280 // Skip directories
281 if file.IsDir() {
282 continue
283 }
284
285 models = append(models, file.Name())
286 }
287
288 return models, nil
289}
290
291func (ml *ModelLoader) ListLoadedModels() []*Model {
292 ml.mu.Lock()

Callers 2

ListModelsFunction · 0.80
loader_test.goFile · 0.80

Calls 2

ContainsMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected