Feat: add toml config
This commit is contained in:
37
config/config.go
Normal file
37
config/config.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
APIURL string `toml:"APIURL"`
|
||||
ShowSys bool `toml:"ShowSys"`
|
||||
LogFile string `toml:"LogFile"`
|
||||
UserRole string `toml:"UserRole"`
|
||||
ToolRole string `toml:"ToolRole"`
|
||||
AssistantRole string `toml:"AssistantRole"`
|
||||
AssistantIcon string `toml:"AssistantIcon"`
|
||||
UserIcon string `toml:"UserIcon"`
|
||||
ToolIcon string `toml:"ToolIcon"`
|
||||
}
|
||||
|
||||
func LoadConfigOrDefault(fn string) *Config {
|
||||
if fn == "" {
|
||||
fn = "config.toml"
|
||||
}
|
||||
config := &Config{}
|
||||
_, err := toml.DecodeFile(fn, &config)
|
||||
if err != nil {
|
||||
fmt.Println("failed to read config from file, loading default")
|
||||
config.APIURL = "http://localhost:8080/v1/chat/completions"
|
||||
config.ShowSys = true
|
||||
config.LogFile = "log.txt"
|
||||
config.UserRole = "user"
|
||||
config.ToolRole = "tool"
|
||||
config.AssistantRole = "assistant"
|
||||
}
|
||||
return config
|
||||
}
|
||||
Reference in New Issue
Block a user