summaryrefslogtreecommitdiff
path: root/config/config.go
blob: 63495b51e6ad41282b22eb75dc009d8dd16d5503 (plain)
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
package config

import (
	"fmt"

	"github.com/BurntSushi/toml"
)

type Config struct {
	ChatAPI       string `toml:"ChatAPI"`
	CompletionAPI string `toml:"CompletionAPI"`
	CurrentAPI    string
	APIMap        map[string]string
	//
	ShowSys       bool   `toml:"ShowSys"`
	LogFile       string `toml:"LogFile"`
	UserRole      string `toml:"UserRole"`
	ToolRole      string `toml:"ToolRole"`
	ToolUse       bool   `toml:"ToolUse"`
	ThinkUse      bool   `toml:"ThinkUse"`
	AssistantRole string `toml:"AssistantRole"`
	SysDir        string `toml:"SysDir"`
	ChunkLimit    uint32 `toml:"ChunkLimit"`
	// embeddings
	RAGEnabled bool   `toml:"RAGEnabled"`
	EmbedURL   string `toml:"EmbedURL"`
	HFToken    string `toml:"HFToken"`
	RAGDir     string `toml:"RAGDir"`
	// rag settings
	RAGWorkers   uint32 `toml:"RAGWorkers"`
	RAGBatchSize int    `toml:"RAGBatchSize"`
	RAGWordLimit uint32 `toml:"RAGWordLimit"`
}

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.ChatAPI = "http://localhost:8080/v1/chat/completions"
		config.CompletionAPI = "http://localhost:8080/completion"
		config.RAGEnabled = false
		config.EmbedURL = "http://localhost:8080/v1/embiddings"
		config.ShowSys = true
		config.LogFile = "log.txt"
		config.UserRole = "user"
		config.ToolRole = "tool"
		config.AssistantRole = "assistant"
		config.SysDir = "sysprompts"
		config.ChunkLimit = 8192
		//
		config.RAGBatchSize = 100
		config.RAGWordLimit = 80
		config.RAGWorkers = 5
	}
	config.CurrentAPI = config.ChatAPI
	config.APIMap = map[string]string{
		config.ChatAPI: config.CompletionAPI,
	}
	if config.CompletionAPI != "" {
		config.CurrentAPI = config.CompletionAPI
		config.APIMap = map[string]string{
			config.CompletionAPI: config.ChatAPI,
		}
	}
	// if any value is empty fill with default
	return config
}