LocalAI/pkg/model/model.go
Ettore Di Giacinto 7f06954425
fix(model-loading): keep track of open GRPC Clients (#3377)
Due to a previous refactor we moved the client constructor tight to the
model address, however that was just a string which we would use to
build the client each time.

With this change we make the loader to return a *Model which carries a
constructor for the client and stores the client on the first
connection.

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2024-08-25 14:36:09 +02:00

30 lines
470 B
Go

package model
import grpc "github.com/mudler/LocalAI/pkg/grpc"
type Model struct {
address string
client grpc.Backend
}
func NewModel(address string) *Model {
return &Model{
address: address,
}
}
func (m *Model) GRPC(parallel bool, wd *WatchDog) grpc.Backend {
if m.client != nil {
return m.client
}
enableWD := false
if wd != nil {
enableWD = true
}
client := grpc.NewClient(m.address, parallel, wd, enableWD)
m.client = client
return client
}