()
| 249 | const retryTimeout = time.Duration(2 * time.Minute) |
| 250 | |
| 251 | func (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{} |
| 258 | FILE: |
| 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 | |
| 291 | func (ml *ModelLoader) ListLoadedModels() []*Model { |
| 292 | ml.mu.Lock() |
no test coverage detected