mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
feat(model-list): be consistent, skip known files from listing (#2760)
fix(model-list): be consistent, skip known files from listing This changeset does two things: - Removes the dependency of listing models from the OpenAI schema. - Tries to reduce confusion between ListModels() in model loader and in the service - now there is only one ListModels which is in services and does not depend anymore on the OpenAI schema - The OpenAI-schema functions were moved nearby the OpenAI specific endpoints that needs the schema - Drops the ListModel Service structure as there was no real need for it. Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
28c6daf916
commit
59ef426fbf
22 changed files with 97 additions and 70 deletions
|
@ -30,7 +30,6 @@ type PromptTemplateData struct {
|
|||
MessageIndex int
|
||||
}
|
||||
|
||||
// TODO: Ask mudler about FunctionCall stuff being useful at the message level?
|
||||
type ChatMessageTemplateData struct {
|
||||
SystemPrompt string
|
||||
Role string
|
||||
|
@ -87,22 +86,47 @@ func (ml *ModelLoader) ExistsInModelPath(s string) bool {
|
|||
return utils.ExistsInPath(ml.ModelPath, s)
|
||||
}
|
||||
|
||||
func (ml *ModelLoader) ListModels() ([]string, error) {
|
||||
var knownFilesToSkip []string = []string{
|
||||
"MODEL_CARD",
|
||||
"README",
|
||||
"README.md",
|
||||
}
|
||||
|
||||
var knownModelsNameSuffixToSkip []string = []string{
|
||||
".tmpl",
|
||||
".keep",
|
||||
".yaml",
|
||||
".yml",
|
||||
".json",
|
||||
".DS_Store",
|
||||
".",
|
||||
}
|
||||
|
||||
func (ml *ModelLoader) ListFilesInModelPath() ([]string, error) {
|
||||
files, err := os.ReadDir(ml.ModelPath)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
|
||||
models := []string{}
|
||||
FILE:
|
||||
for _, file := range files {
|
||||
// Skip templates, YAML, .keep, .json, and .DS_Store files - TODO: as this list grows, is there a more efficient method?
|
||||
if strings.HasSuffix(file.Name(), ".tmpl") ||
|
||||
strings.HasSuffix(file.Name(), ".keep") ||
|
||||
strings.HasSuffix(file.Name(), ".yaml") ||
|
||||
strings.HasSuffix(file.Name(), ".yml") ||
|
||||
strings.HasSuffix(file.Name(), ".json") ||
|
||||
strings.HasSuffix(file.Name(), ".DS_Store") ||
|
||||
strings.HasPrefix(file.Name(), ".") {
|
||||
|
||||
for _, skip := range knownFilesToSkip {
|
||||
if strings.EqualFold(file.Name(), skip) {
|
||||
continue FILE
|
||||
}
|
||||
}
|
||||
|
||||
// Skip templates, YAML, .keep, .json, and .DS_Store files
|
||||
for _, skip := range knownModelsNameSuffixToSkip {
|
||||
if strings.HasSuffix(file.Name(), skip) {
|
||||
continue FILE
|
||||
}
|
||||
}
|
||||
|
||||
// Skip directories
|
||||
if file.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue