mirror of
https://github.com/mudler/LocalAI.git
synced 2026-01-06 02:29:54 -06:00
- Add a system backend path - Refactor and consolidate system information in system state - Use system state in all the components to figure out the system paths to used whenever needed - Refactor BackendConfig -> ModelConfig. This was otherway misleading as now we do have a backend configuration which is not the model config. Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
gguf "github.com/gpustack/gguf-parser-go"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func guessDefaultsFromFile(cfg *ModelConfig, modelPath string, defaultCtx int) {
|
|
if os.Getenv("LOCALAI_DISABLE_GUESSING") == "true" {
|
|
log.Debug().Msgf("guessDefaultsFromFile: %s", "guessing disabled with LOCALAI_DISABLE_GUESSING")
|
|
return
|
|
}
|
|
|
|
if modelPath == "" {
|
|
log.Debug().Msgf("guessDefaultsFromFile: %s", "modelPath is empty")
|
|
return
|
|
}
|
|
|
|
// We try to guess only if we don't have a template defined already
|
|
guessPath := filepath.Join(modelPath, cfg.ModelFileName())
|
|
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
log.Error().Msgf("guessDefaultsFromFile: %s", "panic while parsing gguf file")
|
|
}
|
|
}()
|
|
|
|
defer func() {
|
|
if cfg.ContextSize == nil {
|
|
if defaultCtx == 0 {
|
|
defaultCtx = defaultContextSize
|
|
}
|
|
cfg.ContextSize = &defaultCtx
|
|
}
|
|
}()
|
|
|
|
// try to parse the gguf file
|
|
f, err := gguf.ParseGGUFFile(guessPath)
|
|
if err == nil {
|
|
guessGGUFFromFile(cfg, f, defaultCtx)
|
|
return
|
|
}
|
|
}
|