mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-21 19:15:00 +00:00
Revert "[Refactor]: Core/API Split" (#1550)
Revert "[Refactor]: Core/API Split (#1506)"
This reverts commit ab7b4d5ee9
.
This commit is contained in:
parent
ab7b4d5ee9
commit
db926896bd
77 changed files with 3132 additions and 3456 deletions
|
@ -6,7 +6,7 @@ import (
|
|||
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
|
||||
)
|
||||
|
||||
type ModelOptions struct {
|
||||
type Options struct {
|
||||
backendString string
|
||||
model string
|
||||
threads uint32
|
||||
|
@ -23,14 +23,14 @@ type ModelOptions struct {
|
|||
parallelRequests bool
|
||||
}
|
||||
|
||||
type Option func(*ModelOptions)
|
||||
type Option func(*Options)
|
||||
|
||||
var EnableParallelRequests = func(o *ModelOptions) {
|
||||
var EnableParallelRequests = func(o *Options) {
|
||||
o.parallelRequests = true
|
||||
}
|
||||
|
||||
func WithExternalBackend(name string, uri string) Option {
|
||||
return func(o *ModelOptions) {
|
||||
return func(o *Options) {
|
||||
if o.externalBackends == nil {
|
||||
o.externalBackends = make(map[string]string)
|
||||
}
|
||||
|
@ -38,81 +38,62 @@ func WithExternalBackend(name string, uri string) Option {
|
|||
}
|
||||
}
|
||||
|
||||
// Currently, LocalAI isn't ready for backends to be yanked out from under it - so this is a little overcomplicated to allow non-overwriting updates
|
||||
func WithExternalBackends(backends map[string]string, overwrite bool) Option {
|
||||
return func(o *ModelOptions) {
|
||||
if backends == nil {
|
||||
return
|
||||
}
|
||||
if o.externalBackends == nil {
|
||||
o.externalBackends = backends
|
||||
return
|
||||
}
|
||||
for name, url := range backends {
|
||||
_, exists := o.externalBackends[name]
|
||||
if !exists || overwrite {
|
||||
o.externalBackends[name] = url
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func WithGRPCAttempts(attempts int) Option {
|
||||
return func(o *ModelOptions) {
|
||||
return func(o *Options) {
|
||||
o.grpcAttempts = attempts
|
||||
}
|
||||
}
|
||||
|
||||
func WithGRPCAttemptsDelay(delay int) Option {
|
||||
return func(o *ModelOptions) {
|
||||
return func(o *Options) {
|
||||
o.grpcAttemptsDelay = delay
|
||||
}
|
||||
}
|
||||
|
||||
func WithBackendString(backend string) Option {
|
||||
return func(o *ModelOptions) {
|
||||
return func(o *Options) {
|
||||
o.backendString = backend
|
||||
}
|
||||
}
|
||||
|
||||
func WithModel(modelFile string) Option {
|
||||
return func(o *ModelOptions) {
|
||||
return func(o *Options) {
|
||||
o.model = modelFile
|
||||
}
|
||||
}
|
||||
|
||||
func WithLoadGRPCLoadModelOpts(opts *pb.ModelOptions) Option {
|
||||
return func(o *ModelOptions) {
|
||||
return func(o *Options) {
|
||||
o.gRPCOptions = opts
|
||||
}
|
||||
}
|
||||
|
||||
func WithThreads(threads uint32) Option {
|
||||
return func(o *ModelOptions) {
|
||||
return func(o *Options) {
|
||||
o.threads = threads
|
||||
}
|
||||
}
|
||||
|
||||
func WithAssetDir(assetDir string) Option {
|
||||
return func(o *ModelOptions) {
|
||||
return func(o *Options) {
|
||||
o.assetDir = assetDir
|
||||
}
|
||||
}
|
||||
|
||||
func WithContext(ctx context.Context) Option {
|
||||
return func(o *ModelOptions) {
|
||||
return func(o *Options) {
|
||||
o.context = ctx
|
||||
}
|
||||
}
|
||||
|
||||
func WithSingleActiveBackend() Option {
|
||||
return func(o *ModelOptions) {
|
||||
return func(o *Options) {
|
||||
o.singleActiveBackend = true
|
||||
}
|
||||
}
|
||||
|
||||
func NewOptions(opts ...Option) *ModelOptions {
|
||||
o := &ModelOptions{
|
||||
func NewOptions(opts ...Option) *Options {
|
||||
o := &Options{
|
||||
gRPCOptions: &pb.ModelOptions{},
|
||||
context: context.Background(),
|
||||
grpcAttempts: 20,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue