summaryrefslogtreecommitdiff
path: root/config/config.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2024-11-27 20:16:58 +0300
committerGrail Finder <wohilas@gmail.com>2024-11-27 20:16:58 +0300
commit14d706f94a45ab43c51f9c03abea7b3588c571c7 (patch)
treead74004c0b3fa95d1e8408797683d548eee807f2 /config/config.go
parent55007d27f808426128a7b2d86169e86c4cf01b57 (diff)
Feat: add toml config
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/config/config.go b/config/config.go
new file mode 100644
index 0000000..27f8c66
--- /dev/null
+++ b/config/config.go
@@ -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
+}