2023-07-14 23:19:43 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2023-07-14 23:19:43 +00:00
|
|
|
"context"
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
backendString string
|
2023-08-07 20:39:10 +00:00
|
|
|
model string
|
2023-07-14 23:19:43 +00:00
|
|
|
threads uint32
|
|
|
|
assetDir string
|
2023-07-14 23:19:43 +00:00
|
|
|
context context.Context
|
2023-07-14 23:19:43 +00:00
|
|
|
|
|
|
|
gRPCOptions *pb.ModelOptions
|
2023-07-20 20:10:12 +00:00
|
|
|
|
|
|
|
externalBackends map[string]string
|
2023-07-14 23:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(*Options)
|
|
|
|
|
2023-07-20 20:10:12 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
func WithBackendString(backend string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.backendString = backend
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-07 20:39:10 +00:00
|
|
|
func WithModel(modelFile string) Option {
|
2023-07-14 23:19:43 +00:00
|
|
|
return func(o *Options) {
|
2023-08-07 20:39:10 +00:00
|
|
|
o.model = modelFile
|
2023-07-14 23:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
func WithLoadGRPCLLMModelOpts(opts *pb.ModelOptions) Option {
|
2023-07-14 23:19:43 +00:00
|
|
|
return func(o *Options) {
|
|
|
|
o.gRPCOptions = opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithThreads(threads uint32) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.threads = threads
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAssetDir(assetDir string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.assetDir = assetDir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
func WithContext(ctx context.Context) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.context = ctx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
func NewOptions(opts ...Option) *Options {
|
2023-07-14 23:19:43 +00:00
|
|
|
o := &Options{
|
|
|
|
gRPCOptions: &pb.ModelOptions{},
|
|
|
|
context: context.Background(),
|
|
|
|
}
|
2023-07-14 23:19:43 +00:00
|
|
|
for _, opt := range opts {
|
|
|
|
opt(o)
|
|
|
|
}
|
|
|
|
return o
|
|
|
|
}
|