Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: listmodelservice / welcome endpoint use LOOSE_ONLY #3791

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions core/http/endpoints/localai/welcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,18 @@ import (
func WelcomeEndpoint(appConfig *config.ApplicationConfig,
cl *config.BackendConfigLoader, ml *model.ModelLoader, modelStatus func() (map[string]string, map[string]string)) func(*fiber.Ctx) error {
return func(c *fiber.Ctx) error {
models, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED)
backendConfigs := cl.GetAllBackendConfigs()

galleryConfigs := map[string]*gallery.Config{}
modelsWithBackendConfig := map[string]interface{}{}

for _, m := range backendConfigs {
modelsWithBackendConfig[m.Name] = nil

cfg, err := gallery.GetLocalModelConfiguration(ml.ModelPath, m.Name)
if err != nil {
continue
}
galleryConfigs[m.Name] = cfg
}

modelsWithoutConfig := []string{}
for _, m := range models {
if _, ok := modelsWithBackendConfig[m]; !ok {
modelsWithoutConfig = append(modelsWithoutConfig, m)
}
}
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)

// Get model statuses to display in the UI the operation in progress
processingModels, taskTypes := modelStatus()
Expand Down
16 changes: 9 additions & 7 deletions core/services/list_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
type LooseFilePolicy int

const (
SKIP_IF_CONFIGURED LooseFilePolicy = iota
LOOSE_ONLY LooseFilePolicy = iota
SKIP_IF_CONFIGURED
SKIP_ALWAYS
ALWAYS_INCLUDE
LOOSE_ONLY
)

func ListModels(bcl *config.BackendConfigLoader, ml *model.ModelLoader, filter config.BackendConfigFilterFn, looseFilePolicy LooseFilePolicy) ([]string, error) {
Expand All @@ -21,11 +21,13 @@ func ListModels(bcl *config.BackendConfigLoader, ml *model.ModelLoader, filter c
dataModels := []string{}

// Start with known configurations
if looseFilePolicy != LOOSE_ONLY {
for _, c := range bcl.GetBackendConfigsByFilter(filter) {
if looseFilePolicy == SKIP_IF_CONFIGURED {
skipMap[c.Model] = nil
}

for _, c := range bcl.GetBackendConfigsByFilter(filter) {
// Is this better than looseFilePolicy <= SKIP_IF_CONFIGURED ? less performant but more readable?
if (looseFilePolicy == SKIP_IF_CONFIGURED) || (looseFilePolicy == LOOSE_ONLY) {
skipMap[c.Model] = nil
}
if looseFilePolicy != LOOSE_ONLY {
dataModels = append(dataModels, c.Name)
}
}
Expand Down
Loading