mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-18 20:27:57 +00:00
Fix: listmodelservice / welcome endpoint use LOOSE_ONLY (#3791)
* fix list model service and welcome Signed-off-by: Dave Lee <dave@gray101.com> * comment Signed-off-by: Dave Lee <dave@gray101.com> --------- Signed-off-by: Dave Lee <dave@gray101.com>
This commit is contained in:
parent
a0f0505f0d
commit
65ca754166
@ -13,15 +13,10 @@ import (
|
|||||||
func WelcomeEndpoint(appConfig *config.ApplicationConfig,
|
func WelcomeEndpoint(appConfig *config.ApplicationConfig,
|
||||||
cl *config.BackendConfigLoader, ml *model.ModelLoader, modelStatus func() (map[string]string, map[string]string)) func(*fiber.Ctx) error {
|
cl *config.BackendConfigLoader, ml *model.ModelLoader, modelStatus func() (map[string]string, map[string]string)) func(*fiber.Ctx) error {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
models, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED)
|
|
||||||
backendConfigs := cl.GetAllBackendConfigs()
|
backendConfigs := cl.GetAllBackendConfigs()
|
||||||
|
|
||||||
galleryConfigs := map[string]*gallery.Config{}
|
galleryConfigs := map[string]*gallery.Config{}
|
||||||
modelsWithBackendConfig := map[string]interface{}{}
|
|
||||||
|
|
||||||
for _, m := range backendConfigs {
|
for _, m := range backendConfigs {
|
||||||
modelsWithBackendConfig[m.Name] = nil
|
|
||||||
|
|
||||||
cfg, err := gallery.GetLocalModelConfiguration(ml.ModelPath, m.Name)
|
cfg, err := gallery.GetLocalModelConfiguration(ml.ModelPath, m.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
@ -29,12 +24,7 @@ func WelcomeEndpoint(appConfig *config.ApplicationConfig,
|
|||||||
galleryConfigs[m.Name] = cfg
|
galleryConfigs[m.Name] = cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
modelsWithoutConfig := []string{}
|
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
|
||||||
for _, m := range models {
|
|
||||||
if _, ok := modelsWithBackendConfig[m]; !ok {
|
|
||||||
modelsWithoutConfig = append(modelsWithoutConfig, m)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get model statuses to display in the UI the operation in progress
|
// Get model statuses to display in the UI the operation in progress
|
||||||
processingModels, taskTypes := modelStatus()
|
processingModels, taskTypes := modelStatus()
|
||||||
|
@ -8,10 +8,10 @@ import (
|
|||||||
type LooseFilePolicy int
|
type LooseFilePolicy int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SKIP_IF_CONFIGURED LooseFilePolicy = iota
|
LOOSE_ONLY LooseFilePolicy = iota
|
||||||
|
SKIP_IF_CONFIGURED
|
||||||
SKIP_ALWAYS
|
SKIP_ALWAYS
|
||||||
ALWAYS_INCLUDE
|
ALWAYS_INCLUDE
|
||||||
LOOSE_ONLY
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ListModels(bcl *config.BackendConfigLoader, ml *model.ModelLoader, filter config.BackendConfigFilterFn, looseFilePolicy LooseFilePolicy) ([]string, error) {
|
func ListModels(bcl *config.BackendConfigLoader, ml *model.ModelLoader, filter config.BackendConfigFilterFn, looseFilePolicy LooseFilePolicy) ([]string, error) {
|
||||||
@ -21,11 +21,13 @@ func ListModels(bcl *config.BackendConfigLoader, ml *model.ModelLoader, filter c
|
|||||||
dataModels := []string{}
|
dataModels := []string{}
|
||||||
|
|
||||||
// Start with known configurations
|
// Start with known configurations
|
||||||
if looseFilePolicy != LOOSE_ONLY {
|
|
||||||
for _, c := range bcl.GetBackendConfigsByFilter(filter) {
|
for _, c := range bcl.GetBackendConfigsByFilter(filter) {
|
||||||
if looseFilePolicy == SKIP_IF_CONFIGURED {
|
// Is this better than looseFilePolicy <= SKIP_IF_CONFIGURED ? less performant but more readable?
|
||||||
skipMap[c.Model] = nil
|
if (looseFilePolicy == SKIP_IF_CONFIGURED) || (looseFilePolicy == LOOSE_ONLY) {
|
||||||
}
|
skipMap[c.Model] = nil
|
||||||
|
}
|
||||||
|
if looseFilePolicy != LOOSE_ONLY {
|
||||||
dataModels = append(dataModels, c.Name)
|
dataModels = append(dataModels, c.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user