mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 18:45:00 +00:00
Use the first available model if not specified (#55)
Signed-off-by: mudler <mudler@mocaccino.org>
This commit is contained in:
parent
bf20cc34f6
commit
79791438fe
1 changed files with 14 additions and 2 deletions
16
api/api.go
16
api/api.go
|
@ -94,16 +94,28 @@ func openAIEndpoint(chat, debug bool, loader *model.ModelLoader, threads, ctx in
|
||||||
// Set model from bearer token, if available
|
// Set model from bearer token, if available
|
||||||
bearer := strings.TrimLeft(c.Get("authorization"), "Bearer ")
|
bearer := strings.TrimLeft(c.Get("authorization"), "Bearer ")
|
||||||
bearerExists := bearer != "" && loader.ExistsInModelPath(bearer)
|
bearerExists := bearer != "" && loader.ExistsInModelPath(bearer)
|
||||||
|
|
||||||
|
// If no model was specified, take the first available
|
||||||
|
if modelFile == "" {
|
||||||
|
models, _ := loader.ListModels()
|
||||||
|
if len(models) > 0 {
|
||||||
|
modelFile = models[0]
|
||||||
|
log.Debug().Msgf("No model specified, using: %s", modelFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no model is found or specified, we bail out
|
||||||
if modelFile == "" && !bearerExists {
|
if modelFile == "" && !bearerExists {
|
||||||
return fmt.Errorf("no model specified")
|
return fmt.Errorf("no model specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
if bearerExists { // model specified in bearer token takes precedence
|
// If a model is found in bearer token takes precedence
|
||||||
|
if bearerExists {
|
||||||
log.Debug().Msgf("Using model from bearer token: %s", bearer)
|
log.Debug().Msgf("Using model from bearer token: %s", bearer)
|
||||||
modelFile = bearer
|
modelFile = bearer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to load the model with both
|
// Try to load the model
|
||||||
var llamaerr, gpt2err, gptjerr, stableerr error
|
var llamaerr, gpt2err, gptjerr, stableerr error
|
||||||
llamaOpts := []llama.ModelOption{}
|
llamaOpts := []llama.ModelOption{}
|
||||||
if ctx != 0 {
|
if ctx != 0 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue