Skip to content

Commit 55509d3

Browse files
committed
Load wrapper clients
Testing with: ```yaml name: gpt-4o pipeline: tts: voice-it-riccardo_fasol-x-low transcription: whisper-base-q5_1 llm: llama-3.2-1b-instruct:q4_k_m ``` Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent c824422 commit 55509d3

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

core/config/backend_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type BackendConfig struct {
7979
type Pipeline struct {
8080
TTS string `yaml:"tts"`
8181
LLM string `yaml:"llm"`
82-
Transcription string `yaml:"sst"`
82+
Transcription string `yaml:"transcription"`
8383
}
8484

8585
type File struct {

core/http/endpoints/openai/realtime.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"github.com/gofiber/websocket/v2"
1111
"github.com/mudler/LocalAI/core/backend"
1212
"github.com/mudler/LocalAI/core/config"
13+
grpc "github.com/mudler/LocalAI/pkg/grpc"
1314
model "github.com/mudler/LocalAI/pkg/model"
15+
1416
"github.com/rs/zerolog/log"
1517
)
1618

@@ -111,13 +113,17 @@ type Model interface {
111113
}
112114

113115
type wrappedModel struct {
114-
TTS *config.BackendConfig
115-
SST *config.BackendConfig
116-
LLM *config.BackendConfig
116+
TTSConfig *config.BackendConfig
117+
TranscriptionConfig *config.BackendConfig
118+
LLMConfig *config.BackendConfig
119+
TTSClient grpc.Backend
120+
TranscriptionClient grpc.Backend
121+
LLMClient grpc.Backend
117122
}
118123

119124
// returns and loads either a wrapped model or a model that support audio-to-audio
120125
func newModel(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig, modelName string) (Model, error) {
126+
121127
cfg, err := cl.LoadBackendConfigFileByName(modelName, ml.ModelPath)
122128
if err != nil {
123129
return nil, fmt.Errorf("failed to load backend config: %w", err)
@@ -134,6 +140,8 @@ func newModel(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *
134140
return ml.BackendLoader(opts...)
135141
}
136142

143+
log.Debug().Msg("Loading a wrapped model")
144+
137145
// Otherwise we want to return a wrapped model, which is a "virtual" model that re-uses other models to perform operations
138146
cfgLLM, err := cl.LoadBackendConfigFileByName(cfg.Pipeline.LLM, ml.ModelPath)
139147
if err != nil {
@@ -165,10 +173,31 @@ func newModel(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *
165173
return nil, fmt.Errorf("failed to validate config: %w", err)
166174
}
167175

176+
opts := backend.ModelOptions(*cfgTTS, appConfig)
177+
ttsClient, err := ml.BackendLoader(opts...)
178+
if err != nil {
179+
return nil, fmt.Errorf("failed to load tts model: %w", err)
180+
}
181+
182+
opts = backend.ModelOptions(*cfgSST, appConfig)
183+
transcriptionClient, err := ml.BackendLoader(opts...)
184+
if err != nil {
185+
return nil, fmt.Errorf("failed to load SST model: %w", err)
186+
}
187+
188+
opts = backend.ModelOptions(*cfgLLM, appConfig)
189+
llmClient, err := ml.BackendLoader(opts...)
190+
if err != nil {
191+
return nil, fmt.Errorf("failed to load LLM model: %w", err)
192+
}
193+
168194
return &wrappedModel{
169-
TTS: cfgTTS,
170-
SST: cfgSST,
171-
LLM: cfgLLM,
195+
TTSConfig: cfgTTS,
196+
TranscriptionConfig: cfgSST,
197+
LLMConfig: cfgLLM,
198+
TTSClient: ttsClient,
199+
TranscriptionClient: transcriptionClient,
200+
LLMClient: llmClient,
172201
}, nil
173202
}
174203

0 commit comments

Comments
 (0)