mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-20 13:13:11 +00:00
255748bcba
This PR specifically introduces a `core` folder and moves the following packages over, without any other changes: - `api/backend` - `api/config` - `api/options` - `api/schema` Once this is merged and we confirm there's no regressions, I can migrate over the remaining changes piece by piece to split up application startup, backend services, http, and mqtt as was the goal of the earlier PRs!
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package localai
|
|
|
|
import (
|
|
fiberContext "github.com/go-skynet/LocalAI/api/ctx"
|
|
"github.com/go-skynet/LocalAI/core/backend"
|
|
config "github.com/go-skynet/LocalAI/core/config"
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/go-skynet/LocalAI/core/options"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type TTSRequest struct {
|
|
Model string `json:"model" yaml:"model"`
|
|
Input string `json:"input" yaml:"input"`
|
|
Backend string `json:"backend" yaml:"backend"`
|
|
}
|
|
|
|
func TTSEndpoint(cm *config.ConfigLoader, o *options.Option) func(c *fiber.Ctx) error {
|
|
return func(c *fiber.Ctx) error {
|
|
|
|
input := new(TTSRequest)
|
|
|
|
// Get input data from the request body
|
|
if err := c.BodyParser(input); err != nil {
|
|
return err
|
|
}
|
|
|
|
modelFile, err := fiberContext.ModelFromContext(c, o.Loader, input.Model, false)
|
|
if err != nil {
|
|
modelFile = input.Model
|
|
log.Warn().Msgf("Model not found in context: %s", input.Model)
|
|
}
|
|
cfg, err := config.Load(modelFile, o.Loader.ModelPath, cm, false, 0, 0, false)
|
|
if err != nil {
|
|
modelFile = input.Model
|
|
log.Warn().Msgf("Model not found in context: %s", input.Model)
|
|
} else {
|
|
modelFile = cfg.Model
|
|
}
|
|
log.Debug().Msgf("Request for model: %s", modelFile)
|
|
|
|
if input.Backend != "" {
|
|
cfg.Backend = input.Backend
|
|
}
|
|
|
|
filePath, _, err := backend.ModelTTS(cfg.Backend, input.Input, modelFile, o.Loader, o, *cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return c.Download(filePath)
|
|
}
|
|
}
|