@@ -10,7 +10,9 @@ import (
10
10
"github.com/gofiber/websocket/v2"
11
11
"github.com/mudler/LocalAI/core/backend"
12
12
"github.com/mudler/LocalAI/core/config"
13
+ grpc "github.com/mudler/LocalAI/pkg/grpc"
13
14
model "github.com/mudler/LocalAI/pkg/model"
15
+
14
16
"github.com/rs/zerolog/log"
15
17
)
16
18
@@ -111,13 +113,17 @@ type Model interface {
111
113
}
112
114
113
115
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
117
122
}
118
123
119
124
// returns and loads either a wrapped model or a model that support audio-to-audio
120
125
func newModel (cl * config.BackendConfigLoader , ml * model.ModelLoader , appConfig * config.ApplicationConfig , modelName string ) (Model , error ) {
126
+
121
127
cfg , err := cl .LoadBackendConfigFileByName (modelName , ml .ModelPath )
122
128
if err != nil {
123
129
return nil , fmt .Errorf ("failed to load backend config: %w" , err )
@@ -134,6 +140,8 @@ func newModel(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *
134
140
return ml .BackendLoader (opts ... )
135
141
}
136
142
143
+ log .Debug ().Msg ("Loading a wrapped model" )
144
+
137
145
// Otherwise we want to return a wrapped model, which is a "virtual" model that re-uses other models to perform operations
138
146
cfgLLM , err := cl .LoadBackendConfigFileByName (cfg .Pipeline .LLM , ml .ModelPath )
139
147
if err != nil {
@@ -165,10 +173,31 @@ func newModel(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *
165
173
return nil , fmt .Errorf ("failed to validate config: %w" , err )
166
174
}
167
175
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
+
168
194
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 ,
172
201
}, nil
173
202
}
174
203
0 commit comments