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
|
|
|
|
modelFile string
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(*Options)
|
|
|
|
|
|
|
|
func WithBackendString(backend string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.backendString = backend
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithModelFile(modelFile string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.modelFile = modelFile
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|