2024-08-25 12:36:09 +00:00
|
|
|
package model
|
|
|
|
|
2024-09-26 10:44:55 +00:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
grpc "github.com/mudler/LocalAI/pkg/grpc"
|
|
|
|
process "github.com/mudler/go-processmanager"
|
|
|
|
)
|
2024-08-25 12:36:09 +00:00
|
|
|
|
|
|
|
type Model struct {
|
2024-09-25 16:00:23 +00:00
|
|
|
ID string `json:"id"`
|
2024-08-25 12:36:09 +00:00
|
|
|
address string
|
|
|
|
client grpc.Backend
|
2024-09-26 10:44:55 +00:00
|
|
|
process *process.Process
|
|
|
|
sync.Mutex
|
2024-08-25 12:36:09 +00:00
|
|
|
}
|
|
|
|
|
2024-09-26 10:44:55 +00:00
|
|
|
func NewModel(ID, address string, process *process.Process) *Model {
|
2024-08-25 12:36:09 +00:00
|
|
|
return &Model{
|
2024-09-25 16:00:23 +00:00
|
|
|
ID: ID,
|
2024-08-25 12:36:09 +00:00
|
|
|
address: address,
|
2024-09-26 10:44:55 +00:00
|
|
|
process: process,
|
2024-08-25 12:36:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-26 10:44:55 +00:00
|
|
|
func (m *Model) Process() *process.Process {
|
|
|
|
return m.process
|
|
|
|
}
|
|
|
|
|
2024-08-25 12:36:09 +00:00
|
|
|
func (m *Model) GRPC(parallel bool, wd *WatchDog) grpc.Backend {
|
|
|
|
if m.client != nil {
|
|
|
|
return m.client
|
|
|
|
}
|
|
|
|
|
|
|
|
enableWD := false
|
|
|
|
if wd != nil {
|
|
|
|
enableWD = true
|
|
|
|
}
|
|
|
|
|
2024-09-26 10:44:55 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2024-08-30 13:20:39 +00:00
|
|
|
m.client = grpc.NewClient(m.address, parallel, wd, enableWD)
|
|
|
|
return m.client
|
2024-08-25 12:36:09 +00:00
|
|
|
}
|