mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-23 20:14:59 +00:00
chore(refactor): track grpcProcess in the model structure (#3663)
* chore(refactor): track grpcProcess in the model structure This avoids to have to handle in two parts the data relative to the same model. It makes it easier to track and use mutex with. This also fixes races conditions while accessing to the model. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(tests): run protogen-go before starting aio tests Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(tests): install protoc in aio tests Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
3d12d2037c
commit
fa5c98549a
7 changed files with 71 additions and 44 deletions
|
@ -1,20 +1,32 @@
|
|||
package model
|
||||
|
||||
import grpc "github.com/mudler/LocalAI/pkg/grpc"
|
||||
import (
|
||||
"sync"
|
||||
|
||||
grpc "github.com/mudler/LocalAI/pkg/grpc"
|
||||
process "github.com/mudler/go-processmanager"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
ID string `json:"id"`
|
||||
address string
|
||||
client grpc.Backend
|
||||
process *process.Process
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func NewModel(ID, address string) *Model {
|
||||
func NewModel(ID, address string, process *process.Process) *Model {
|
||||
return &Model{
|
||||
ID: ID,
|
||||
address: address,
|
||||
process: process,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) Process() *process.Process {
|
||||
return m.process
|
||||
}
|
||||
|
||||
func (m *Model) GRPC(parallel bool, wd *WatchDog) grpc.Backend {
|
||||
if m.client != nil {
|
||||
return m.client
|
||||
|
@ -25,6 +37,8 @@ func (m *Model) GRPC(parallel bool, wd *WatchDog) grpc.Backend {
|
|||
enableWD = true
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
m.client = grpc.NewClient(m.address, parallel, wd, enableWD)
|
||||
return m.client
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue