-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Expand file tree
/
Copy pathloader_options.go
More file actions
120 lines (98 loc) · 2.31 KB
/
Copy pathloader_options.go
File metadata and controls
120 lines (98 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package model
import (
"context"
pb "github.com/mudler/LocalAI/pkg/grpc/proto"
)
type Options struct {
backendString string
model string
modelID string
context context.Context
gRPCOptions *pb.ModelOptions
externalBackends map[string]string
grpcAttempts int
grpcAttemptsDelay int
parallelRequests bool
// modelSizeBytes is the estimated total weight size in bytes, pre-computed
// by the caller using the vram estimation scaffolding. When non-zero it is
// registered with the watchdog so size-aware eviction can rank models.
modelSizeBytes int64
// envVars contains model-specific environment variables to pass to the backend process
envVars map[string]string
}
type Option func(*Options)
var EnableParallelRequests = func(o *Options) {
o.parallelRequests = true
}
func WithExternalBackend(name string, uri string) Option {
return func(o *Options) {
if o.externalBackends == nil {
o.externalBackends = make(map[string]string)
}
o.externalBackends[name] = uri
}
}
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 {
return func(o *Options) {
o.backendString = backend
}
}
func WithDefaultBackendString(backend string) Option {
return func(o *Options) {
if o.backendString == "" {
o.backendString = backend
}
}
}
func WithModel(modelFile string) Option {
return func(o *Options) {
o.model = modelFile
}
}
func WithLoadGRPCLoadModelOpts(opts *pb.ModelOptions) Option {
return func(o *Options) {
o.gRPCOptions = opts
}
}
func WithContext(ctx context.Context) Option {
return func(o *Options) {
o.context = ctx
}
}
func WithModelID(id string) Option {
return func(o *Options) {
o.modelID = id
}
}
func WithModelSizeBytes(bytes int64) Option {
return func(o *Options) {
o.modelSizeBytes = bytes
}
}
func WithEnvVars(envVars map[string]string) Option {
return func(o *Options) {
o.envVars = envVars
}
}
func NewOptions(opts ...Option) *Options {
o := &Options{
gRPCOptions: &pb.ModelOptions{},
context: context.Background(),
grpcAttempts: 20,
grpcAttemptsDelay: 2,
}
for _, opt := range opts {
opt(o)
}
return o
}