Skip to content

Commit

Permalink
collapse default settings for future reuse
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Lee <dave@gray101.com>
  • Loading branch information
dave-gray101 committed Oct 16, 2024
1 parent 8b29d7c commit d9abc20
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
8 changes: 8 additions & 0 deletions core/config/backend_config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ func (bcl *BackendConfigLoader) LoadBackendConfigFileByName(modelName, modelPath
return cfg, nil
}

func (bcl *BackendConfigLoader) LoadBackendConfigFileByNameDefaultOptions(modelName string, appConfig *ApplicationConfig) (*BackendConfig, error) {
return bcl.LoadBackendConfigFileByName(modelName, appConfig.ModelPath,
LoadOptionDebug(appConfig.Debug),
LoadOptionThreads(appConfig.Threads),
LoadOptionContextSize(appConfig.ContextSize),
LoadOptionF16(appConfig.F16))
}

// This format is currently only used when reading a single file at startup, passed in via ApplicationConfig.ConfigFile
func (bcl *BackendConfigLoader) LoadMultipleBackendConfigsSingleFile(file string, opts ...ConfigLoaderOption) error {
bcl.Lock()
Expand Down
9 changes: 3 additions & 6 deletions core/http/endpoints/localai/get_token_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/mudler/LocalAI/pkg/model"
)

// TODO: This is not yet in use. Needs middleware rework, since it is not referenced.

// TokenMetricsEndpoint is an endpoint to get TokensProcessed Per Second for Active SlotID
//
// @Summary Get TokenMetrics for Active Slot.
Expand All @@ -35,12 +37,7 @@ func TokenMetricsEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader,
log.Warn().Msgf("Model not found in context: %s", input.Model)
}

cfg, err := cl.LoadBackendConfigFileByName(modelFile, appConfig.ModelPath,
config.LoadOptionDebug(appConfig.Debug),
config.LoadOptionThreads(appConfig.Threads),
config.LoadOptionContextSize(appConfig.ContextSize),
config.LoadOptionF16(appConfig.F16),
)
cfg, err := cl.LoadBackendConfigFileByNameDefaultOptions(modelFile, appConfig)

if err != nil {
log.Err(err)
Expand Down
8 changes: 1 addition & 7 deletions core/http/middleware/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,7 @@ func (re *RequestExtractor) SetModelAndConfig(initializer func() schema.LocalAIR
}
}

cfg, err := re.backendConfigLoader.LoadBackendConfigFileByName(input.ModelName(nil), re.applicationConfig.ModelPath,
config.LoadOptionDebug(re.applicationConfig.Debug),
config.LoadOptionThreads(re.applicationConfig.Threads),
config.LoadOptionContextSize(re.applicationConfig.ContextSize),
config.LoadOptionF16(re.applicationConfig.F16),
config.ModelPath(re.modelLoader.ModelPath),
)
cfg, err := re.backendConfigLoader.LoadBackendConfigFileByNameDefaultOptions(input.ModelName(nil), re.applicationConfig)

if err != nil {
log.Err(err)
Expand Down
8 changes: 1 addition & 7 deletions core/startup/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,7 @@ func Startup(opts ...config.AppOption) (*config.BackendConfigLoader, *model.Mode

if options.LoadToMemory != nil {
for _, m := range options.LoadToMemory {
cfg, err := cl.LoadBackendConfigFileByName(m, options.ModelPath,
config.LoadOptionDebug(options.Debug),
config.LoadOptionThreads(options.Threads),
config.LoadOptionContextSize(options.ContextSize),
config.LoadOptionF16(options.F16),
config.ModelPath(options.ModelPath),
)
cfg, err := cl.LoadBackendConfigFileByNameDefaultOptions(m, options)
if err != nil {
return nil, nil, nil, err
}
Expand Down

0 comments on commit d9abc20

Please sign in to comment.