You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
3.4 KiB
170 lines
3.4 KiB
1 year ago
|
package options
|
||
2 years ago
|
|
||
|
import (
|
||
|
"context"
|
||
2 years ago
|
"embed"
|
||
2 years ago
|
"encoding/json"
|
||
2 years ago
|
|
||
2 years ago
|
"github.com/go-skynet/LocalAI/pkg/gallery"
|
||
2 years ago
|
model "github.com/go-skynet/LocalAI/pkg/model"
|
||
2 years ago
|
"github.com/rs/zerolog/log"
|
||
2 years ago
|
)
|
||
|
|
||
|
type Option struct {
|
||
1 year ago
|
Context context.Context
|
||
|
ConfigFile string
|
||
|
Loader *model.ModelLoader
|
||
|
UploadLimitMB, Threads, ContextSize int
|
||
|
F16 bool
|
||
|
Debug, DisableMessage bool
|
||
|
ImageDir string
|
||
|
AudioDir string
|
||
|
CORS bool
|
||
|
PreloadJSONModels string
|
||
|
PreloadModelsFromPath string
|
||
|
CORSAllowOrigins string
|
||
2 years ago
|
|
||
1 year ago
|
Galleries []gallery.Gallery
|
||
2 years ago
|
|
||
1 year ago
|
BackendAssets embed.FS
|
||
|
AssetsDestination string
|
||
2 years ago
|
}
|
||
|
|
||
|
type AppOption func(*Option)
|
||
|
|
||
1 year ago
|
func NewOptions(o ...AppOption) *Option {
|
||
2 years ago
|
opt := &Option{
|
||
1 year ago
|
Context: context.Background(),
|
||
|
UploadLimitMB: 15,
|
||
|
Threads: 1,
|
||
|
ContextSize: 512,
|
||
|
Debug: true,
|
||
|
DisableMessage: true,
|
||
2 years ago
|
}
|
||
|
for _, oo := range o {
|
||
|
oo(opt)
|
||
|
}
|
||
|
return opt
|
||
|
}
|
||
|
|
||
|
func WithCors(b bool) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.CORS = b
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func WithCorsAllowOrigins(b string) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.CORSAllowOrigins = b
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
func WithBackendAssetsOutput(out string) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.AssetsDestination = out
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func WithBackendAssets(f embed.FS) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.BackendAssets = f
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
func WithStringGalleries(galls string) AppOption {
|
||
|
return func(o *Option) {
|
||
|
if galls == "" {
|
||
|
log.Debug().Msgf("no galleries to load")
|
||
|
return
|
||
|
}
|
||
|
var galleries []gallery.Gallery
|
||
|
if err := json.Unmarshal([]byte(galls), &galleries); err != nil {
|
||
|
log.Error().Msgf("failed loading galleries: %s", err.Error())
|
||
|
}
|
||
1 year ago
|
o.Galleries = append(o.Galleries, galleries...)
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
func WithGalleries(galleries []gallery.Gallery) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.Galleries = append(o.Galleries, galleries...)
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
func WithContext(ctx context.Context) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.Context = ctx
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
func WithYAMLConfigPreload(configFile string) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.PreloadModelsFromPath = configFile
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func WithJSONStringPreload(configFile string) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.PreloadJSONModels = configFile
|
||
2 years ago
|
}
|
||
|
}
|
||
2 years ago
|
func WithConfigFile(configFile string) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.ConfigFile = configFile
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func WithModelLoader(loader *model.ModelLoader) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.Loader = loader
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func WithUploadLimitMB(limit int) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.UploadLimitMB = limit
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func WithThreads(threads int) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.Threads = threads
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func WithContextSize(ctxSize int) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.ContextSize = ctxSize
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func WithF16(f16 bool) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.F16 = f16
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func WithDebug(debug bool) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.Debug = debug
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func WithDisableMessage(disableMessage bool) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.DisableMessage = disableMessage
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
func WithAudioDir(audioDir string) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.AudioDir = audioDir
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
func WithImageDir(imageDir string) AppOption {
|
||
|
return func(o *Option) {
|
||
1 year ago
|
o.ImageDir = imageDir
|
||
2 years ago
|
}
|
||
|
}
|