Skip to content

Commit

Permalink
chore: simplify passing options to ModelOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler committed Nov 7, 2024
1 parent 650134d commit 4034562
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion core/backend/embeddings.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func ModelEmbedding(s string, tokens []int, loader *model.ModelLoader, backendCo
var inferenceModel interface{}
var err error

opts := ModelOptions(backendConfig, appConfig, []model.Option{})
opts := ModelOptions(backendConfig, appConfig)

if backendConfig.Backend == "" {
inferenceModel, err = loader.GreedyLoader(opts...)
Expand Down
2 changes: 1 addition & 1 deletion core/backend/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func ImageGeneration(height, width, mode, step, seed int, positive_prompt, negative_prompt, src, dst string, loader *model.ModelLoader, backendConfig config.BackendConfig, appConfig *config.ApplicationConfig) (func() error, error) {

opts := ModelOptions(backendConfig, appConfig, []model.Option{})
opts := ModelOptions(backendConfig, appConfig)

inferenceModel, err := loader.BackendLoader(
opts...,
Expand Down
2 changes: 1 addition & 1 deletion core/backend/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func ModelInference(ctx context.Context, s string, messages []schema.Message, im
var inferenceModel grpc.Backend
var err error

opts := ModelOptions(c, o, []model.Option{})
opts := ModelOptions(c, o)

if c.Backend != "" {
opts = append(opts, model.WithBackendString(c.Backend))
Expand Down
2 changes: 1 addition & 1 deletion core/backend/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/rs/zerolog/log"
)

func ModelOptions(c config.BackendConfig, so *config.ApplicationConfig, opts []model.Option) []model.Option {
func ModelOptions(c config.BackendConfig, so *config.ApplicationConfig, opts ...model.Option) []model.Option {
name := c.Name
if name == "" {
name = c.Model
Expand Down
2 changes: 1 addition & 1 deletion core/backend/rerank.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func Rerank(modelFile string, request *proto.RerankRequest, loader *model.ModelLoader, appConfig *config.ApplicationConfig, backendConfig config.BackendConfig) (*proto.RerankResult, error) {

opts := ModelOptions(backendConfig, appConfig, []model.Option{model.WithModel(modelFile)})
opts := ModelOptions(backendConfig, appConfig, model.WithModel(modelFile))
rerankModel, err := loader.BackendLoader(opts...)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion core/backend/soundgeneration.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func SoundGeneration(
backendConfig config.BackendConfig,
) (string, *proto.Result, error) {

opts := ModelOptions(backendConfig, appConfig, []model.Option{model.WithModel(modelFile)})
opts := ModelOptions(backendConfig, appConfig, model.WithModel(modelFile))

soundGenModel, err := loader.BackendLoader(opts...)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions core/backend/token_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ func TokenMetrics(
appConfig *config.ApplicationConfig,
backendConfig config.BackendConfig) (*proto.MetricsResponse, error) {

opts := ModelOptions(backendConfig, appConfig, []model.Option{
model.WithModel(modelFile),
})
opts := ModelOptions(backendConfig, appConfig, model.WithModel(modelFile))
model, err := loader.BackendLoader(opts...)
if err != nil {
return nil, err
Expand Down
4 changes: 1 addition & 3 deletions core/backend/tokenize.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ func ModelTokenize(s string, loader *model.ModelLoader, backendConfig config.Bac
var inferenceModel grpc.Backend
var err error

opts := ModelOptions(backendConfig, appConfig, []model.Option{
model.WithModel(modelFile),
})
opts := ModelOptions(backendConfig, appConfig, model.WithModel(modelFile))

if backendConfig.Backend == "" {
inferenceModel, err = loader.GreedyLoader(opts...)
Expand Down
2 changes: 1 addition & 1 deletion core/backend/transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ModelTranscription(audio, language string, translate bool, ml *model.ModelL
backendConfig.Backend = model.WhisperBackend
}

opts := ModelOptions(backendConfig, appConfig, []model.Option{})
opts := ModelOptions(backendConfig, appConfig)

transcriptionModel, err := ml.BackendLoader(opts...)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions core/backend/tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ func ModelTTS(
bb = model.PiperBackend
}

opts := ModelOptions(backendConfig, appConfig, []model.Option{
model.WithBackendString(bb),
model.WithModel(modelFile),
})

opts := ModelOptions(backendConfig, appConfig, model.WithBackendString(bb), model.WithModel(modelFile))
ttsModel, err := loader.BackendLoader(opts...)
if err != nil {
return "", nil, err
Expand Down
6 changes: 2 additions & 4 deletions core/http/endpoints/openai/realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,8 @@ func newModel(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *

if cfg.Pipeline.LLM == "" || cfg.Pipeline.TTS == "" || cfg.Pipeline.Transcription == "" {
// If we don't have Wrapped model definitions, just return a standard model
opts := backend.ModelOptions(*cfg, appConfig, []model.Option{
model.WithBackendString(cfg.Backend),
model.WithModel(cfg.Model),
})
opts := backend.ModelOptions(*cfg, appConfig, model.WithBackendString(cfg.Backend),
model.WithModel(cfg.Model))
return ml.BackendLoader(opts...)
}

Expand Down
2 changes: 1 addition & 1 deletion core/startup/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func Startup(opts ...config.AppOption) (*config.BackendConfigLoader, *model.Mode

log.Debug().Msgf("Auto loading model %s into memory from file: %s", m, cfg.Model)

o := backend.ModelOptions(*cfg, options, []model.Option{})
o := backend.ModelOptions(*cfg, options)

var backendErr error
if cfg.Backend != "" {
Expand Down

0 comments on commit 4034562

Please sign in to comment.