mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
feat: make initializer accept gRPC delay times (#900)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
7ffd21dbc8
commit
0ec695f9e4
7 changed files with 60 additions and 4 deletions
|
@ -30,6 +30,14 @@ func ModelEmbedding(s string, tokens []int, loader *model.ModelLoader, c config.
|
||||||
model.WithContext(o.Context),
|
model.WithContext(o.Context),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.GRPC.Attempts != 0 {
|
||||||
|
opts = append(opts, model.WithGRPCAttempts(c.GRPC.Attempts))
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.GRPC.AttemptsSleepTime != 0 {
|
||||||
|
opts = append(opts, model.WithGRPCAttemptsDelay(c.GRPC.AttemptsSleepTime))
|
||||||
|
}
|
||||||
|
|
||||||
for k, v := range o.ExternalGRPCBackends {
|
for k, v := range o.ExternalGRPCBackends {
|
||||||
opts = append(opts, model.WithExternalBackend(k, v))
|
opts = append(opts, model.WithExternalBackend(k, v))
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,14 @@ func ImageGeneration(height, width, mode, step, seed int, positive_prompt, negat
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.GRPC.Attempts != 0 {
|
||||||
|
opts = append(opts, model.WithGRPCAttempts(c.GRPC.Attempts))
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.GRPC.AttemptsSleepTime != 0 {
|
||||||
|
opts = append(opts, model.WithGRPCAttemptsDelay(c.GRPC.AttemptsSleepTime))
|
||||||
|
}
|
||||||
|
|
||||||
for k, v := range o.ExternalGRPCBackends {
|
for k, v := range o.ExternalGRPCBackends {
|
||||||
opts = append(opts, model.WithExternalBackend(k, v))
|
opts = append(opts, model.WithExternalBackend(k, v))
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,14 @@ func ModelInference(ctx context.Context, s string, loader *model.ModelLoader, c
|
||||||
model.WithContext(o.Context),
|
model.WithContext(o.Context),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.GRPC.Attempts != 0 {
|
||||||
|
opts = append(opts, model.WithGRPCAttempts(c.GRPC.Attempts))
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.GRPC.AttemptsSleepTime != 0 {
|
||||||
|
opts = append(opts, model.WithGRPCAttemptsDelay(c.GRPC.AttemptsSleepTime))
|
||||||
|
}
|
||||||
|
|
||||||
for k, v := range o.ExternalGRPCBackends {
|
for k, v := range o.ExternalGRPCBackends {
|
||||||
opts = append(opts, model.WithExternalBackend(k, v))
|
opts = append(opts, model.WithExternalBackend(k, v))
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,13 @@ func ModelTranscription(audio, language string, loader *model.ModelLoader, c con
|
||||||
model.WithAssetDir(o.AssetsDestination),
|
model.WithAssetDir(o.AssetsDestination),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.GRPC.Attempts != 0 {
|
||||||
|
opts = append(opts, model.WithGRPCAttempts(c.GRPC.Attempts))
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.GRPC.AttemptsSleepTime != 0 {
|
||||||
|
opts = append(opts, model.WithGRPCAttemptsDelay(c.GRPC.AttemptsSleepTime))
|
||||||
|
}
|
||||||
for k, v := range o.ExternalGRPCBackends {
|
for k, v := range o.ExternalGRPCBackends {
|
||||||
opts = append(opts, model.WithExternalBackend(k, v))
|
opts = append(opts, model.WithExternalBackend(k, v))
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,14 @@ type Config struct {
|
||||||
Diffusers Diffusers `yaml:"diffusers"`
|
Diffusers Diffusers `yaml:"diffusers"`
|
||||||
|
|
||||||
Step int `yaml:"step"`
|
Step int `yaml:"step"`
|
||||||
|
|
||||||
|
// GRPC Options
|
||||||
|
GRPC GRPC `yaml:"grpc"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GRPC struct {
|
||||||
|
Attempts int `yaml:"attempts"`
|
||||||
|
AttemptsSleepTime int `yaml:"attempts_sleep_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Diffusers struct {
|
type Diffusers struct {
|
||||||
|
|
|
@ -185,13 +185,13 @@ func (ml *ModelLoader) grpcModel(backend string, o *Options) func(string, string
|
||||||
|
|
||||||
// Wait for the service to start up
|
// Wait for the service to start up
|
||||||
ready := false
|
ready := false
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < o.grpcAttempts; i++ {
|
||||||
if client.HealthCheck(context.Background()) {
|
if client.HealthCheck(context.Background()) {
|
||||||
log.Debug().Msgf("GRPC Service Ready")
|
log.Debug().Msgf("GRPC Service Ready")
|
||||||
ready = true
|
ready = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(time.Duration(o.grpcAttemptsDelay) * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ready {
|
if !ready {
|
||||||
|
|
|
@ -16,6 +16,9 @@ type Options struct {
|
||||||
gRPCOptions *pb.ModelOptions
|
gRPCOptions *pb.ModelOptions
|
||||||
|
|
||||||
externalBackends map[string]string
|
externalBackends map[string]string
|
||||||
|
|
||||||
|
grpcAttempts int
|
||||||
|
grpcAttemptsDelay int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Option func(*Options)
|
type Option func(*Options)
|
||||||
|
@ -29,6 +32,18 @@ func WithExternalBackend(name string, uri string) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithGRPCAttempts(attempts int) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.grpcAttempts = attempts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithGRPCAttemptsDelay(delay int) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.grpcAttemptsDelay = delay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WithBackendString(backend string) Option {
|
func WithBackendString(backend string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.backendString = backend
|
o.backendString = backend
|
||||||
|
@ -67,8 +82,10 @@ func WithContext(ctx context.Context) Option {
|
||||||
|
|
||||||
func NewOptions(opts ...Option) *Options {
|
func NewOptions(opts ...Option) *Options {
|
||||||
o := &Options{
|
o := &Options{
|
||||||
gRPCOptions: &pb.ModelOptions{},
|
gRPCOptions: &pb.ModelOptions{},
|
||||||
context: context.Background(),
|
context: context.Background(),
|
||||||
|
grpcAttempts: 20,
|
||||||
|
grpcAttemptsDelay: 2,
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(o)
|
opt(o)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue