-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
79 lines (71 loc) · 2.54 KB
/
config.go
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
package main
import (
"eternal/pkg/llm"
"eternal/pkg/sd"
"time"
"github.com/spf13/afero"
"gopkg.in/yaml.v3"
"gorm.io/gorm"
)
type AppConfig struct {
ServerID string `yaml:"server_id"`
CurrentUser string `yaml:"current_user"`
AssistantName string `yaml:"assistant_name"`
ControlHost string `yaml:"control_host"`
ControlPort string `yaml:"control_port"`
DataPath string `yaml:"data_path"`
ServiceHosts map[string]map[string]BackendHost `yaml:"service_hosts"`
ChromedpKey string `yaml:"chromedp_key"`
OAIKey string `yaml:"oai_key"`
AnthropicKey string `yaml:"anthropic_key"`
GoogleKey string `yaml:"google_key"`
LanguageModels []llm.Model `yaml:"language_models"`
ImageModels []sd.ImageModel `yaml:"image_models"`
AssistantRoles []struct {
Name string `yaml:"name"`
Instructions string `yaml:"instructions"`
} `yaml:"assistant_roles"`
Tools struct {
Memory struct {
Enabled bool `yaml:"enabled"`
TopN int `yaml:"top_n"`
} `yaml:"memory"`
WebGet struct {
Enabled bool `yaml:"enabled"`
} `yaml:"webget"`
WebSearch struct {
Enabled bool `yaml:"enabled"`
Name string `yaml:"name"`
Endpoint string `yaml:"endpoint"`
TopN int `yaml:"top_n"`
} `yaml:"websearch"`
ImgGen struct {
Enabled bool `yaml:"enabled"`
} `yaml:"img_gen"`
} `yaml:"tools"`
}
// BackendHost represents a local or remote backend host.
type BackendHost struct {
ID uint `gorm:"primaryKey" yaml:"-"`
Host string `yaml:"host" gorm:"column:host"`
Port string `yaml:"port" gorm:"column:port"`
GgufGPULayers int `yaml:"gpu_layers" gorm:"column:gguf_gpu_layers"`
ModelType string `yaml:"model_type" gorm:"column:model_type"`
CreatedAt time.Time `yaml:"-"`
UpdatedAt time.Time `yaml:"-"`
DeletedAt gorm.DeletedAt `gorm:"index" yaml:"-"`
}
// LoadConfig loads configuration from a YAML file.
func LoadConfig(fs afero.Fs, path string) (*AppConfig, error) {
config := &AppConfig{}
// Use Afero to read the file
file, err := afero.ReadFile(fs, path)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(file, config)
if err != nil {
return nil, err
}
return config, nil
}