aboutsummaryrefslogtreecommitdiffstats
path: root/types.go
blob: be8b06449617b6e76e8f5b533a255d4c1cdda43e (plain) (blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package main

import (
	"context"
	"log"
	"runtime"
	"time"

	"github.com/jackc/pgx/v5/pgxpool"
	"github.com/mmcdole/gofeed"
	lua "github.com/yuin/gopher-lua"
)

type LogModel struct {
	// Id        int64       `db:"id"`
	// Channel   string      `db:"channel"`
	Log string `db:"log"`
	// Nick      string      `db:"nick"`
	// DateAdded pgtype.Date `db:"dateadded"`
}

type PluginType struct {
	Name    string     `toml:"name"`
	Path    string     `toml:"path"`
	EnvVars [][]string `toml:"envVars"`
}

type CustomCommand struct {
	SQL          string   `toml:"sql"`
	Limit        int      `toml:"limit"`
	Context      []string `toml:"context"`
	Prompt       string   `toml:"prompt"`
	SystemPrompt string   `toml:"systemPrompt"`
}

type LuaLstates struct {
	LuaState *lua.LState
	Cancel   context.CancelFunc
}

type WatchList struct {
	AlertChannel []string   `toml:"alertChannel"`
	WatchList    [][]string `toml:"watchList"`
	WatchFiles   []string   `toml:"watchFiles"`
	Words        []string   `toml:"watchWords"`
	EventTypes   []string   `toml:"eventTypes"`
	FGColor      int        `toml:"fgColor"`
	BGColor      int        `toml:"bgColor"`
}

type LuaCommand struct {
	Path     string
	FuncName string
}

type TriggeredScripts struct {
	Path        string
	FuncName    string
	Channels    [][]string
	TriggerType []string
}

type RssFile struct {
	RssFile string   `toml:"rssFile"`
	Channel []string `toml:"channel"`
}

type TomlConfig struct {
	IrcServer                     string                   `toml:"ircServer"`
	IrcNick                       string                   `toml:"ircNick"`
	IrcSaslUser                   string                   `toml:"ircSaslUser"`
	IrcSaslPass                   string                   `toml:"ircSaslPass"`
	Endpoint                      string                   `toml:"endpoint"`
	Model                         string                   `toml:"model"`
	ChromaStyle                   string                   `toml:"chromaStyle"`
	ChromaFormatter               string                   `toml:"chromaFormatter"`
	Provider                      string                   `toml:"provider"`
	Apikey                        string                   `toml:"apikey"`
	ClientCertPath                string                   `toml:"clientCertPath"`
	ServerPass                    string                   `toml:"serverPass"`
	Bind                          string                   `toml:"bind"`
	Name                          string                   `toml:"name"`
	DatabaseAddress               string                   `toml:"databaseAddress"`
	DatabasePassword              string                   `toml:"databasePassword"`
	DatabaseUser                  string                   `toml:"databaseUser"`
	DatabaseName                  string                   `toml:"databaseName"`
	LLMProxy                      string                   `toml:"llmProxy"`
	IRCProxy                      string                   `toml:"ircProxy"`
	GeneralProxy                  string                   `toml:"generalProxy"`
	IRCDName                      string                   `toml:"ircdName"`
	WebIRCPassword                string                   `toml:"webIRCPassword"`
	WebIRCGateway                 string                   `toml:"webIRCGateway"`
	WebIRCHostname                string                   `toml:"webIRCHostname"`
	WebIRCAddress                 string                   `toml:"webIRCAddress"`
	RSSFile                       string                   `toml:"rssFile"`
	AnthropicVersion              string                   `toml:"anthropicVersion"`
	Plugins                       []string                 `toml:"plugins"`
	Context                       []string                 `toml:"context"`
	SystemPrompt                  string                   `toml:"systemPrompt"`
	CustomCommands                map[string]CustomCommand `toml:"customCommands"`
	WatchLists                    map[string]WatchList     `toml:"watchList"`
	LuaStates                     map[string]LuaLstates
	LuaCommands                   map[string]LuaCommand
	TriggeredScripts              map[string]TriggeredScripts
	Rss                           map[string]RssFile `toml:"rss"`
	RequestTimeout                int                `toml:"requestTimeout"`
	MillaReconnectDelay           int                `toml:"millaReconnectDelay"`
	IrcPort                       int                `toml:"ircPort"`
	KeepAlive                     int                `toml:"keepAlive"`
	MemoryLimit                   int                `toml:"memoryLimit"`
	PingDelay                     int                `toml:"pingDelay"`
	PingTimeout                   int                `toml:"pingTimeout"`
	OllamaMirostat                int                `json:"ollamaMirostat"`
	OllamaMirostatEta             float64            `json:"ollamaMirostatEta"`
	OllamaMirostatTau             float64            `json:"ollamaMirostatTau"`
	OllamaNumCtx                  int                `json:"ollamaNumCtx"`
	OllamaRepeatLastN             int                `json:"ollamaRepeatLastN"`
	OllamaRepeatPenalty           float64            `json:"ollamaRepeatPenalty"`
	Temperature                   float64            `json:"temperature"`
	OllamaSeed                    int                `json:"ollamaSeed"`
	OllamaNumPredict              int                `json:"ollamaNumPredict"`
	OllamaMinP                    float64            `json:"ollamaMinP"`
	TopP                          float32            `toml:"topP"`
	TopK                          int32              `toml:"topK"`
	IrcBackOffInitialInterval     int                `toml:"ircBackOffInitialInterval"`
	IrcBackOffRandomizationFactor float64            `toml:"ircbackOffRandomizationFactor"`
	IrcBackOffMultiplier          float64            `toml:"ircBackOffMultiplier"`
	IrcBackOffMaxInterval         int                `toml:"ircBackOffMaxInterval"`
	DbBackOffInitialInterval      int                `toml:"dbBackOffInitialInterval"`
	DbBackOffRandomizationFactor  float64            `toml:"dbBackOffRandomizationFactor"`
	DbBackOffMultiplier           float64            `toml:"dbBackOffMultiplier"`
	DbBackOffMaxInterval          int                `toml:"dbBackOffMaxInterval"`
	EnableSasl                    bool               `toml:"enableSasl"`
	SkipTLSVerify                 bool               `toml:"skipTLSVerify"`
	UseTLS                        bool               `toml:"useTLS"`
	DisableSTSFallback            bool               `toml:"disableSTSFallback"`
	AllowFlood                    bool               `toml:"allowFlood"`
	Debug                         bool               `toml:"debug"`
	Out                           bool               `toml:"out"`
	AdminOnly                     bool               `toml:"adminOnly"`
	pool                          *pgxpool.Pool
	Admins                        []string   `toml:"admins"`
	IrcChannels                   [][]string `toml:"ircChannels"`
	ScrapeChannels                [][]string `toml:"scrapeChannels"`
}

func (config *TomlConfig) insertLState(
	name string,
	luaState *lua.LState,
	cancel context.CancelFunc,
) {
	if config.LuaStates == nil {
		config.LuaStates = make(map[string]LuaLstates)
	}
	config.LuaStates[name] = LuaLstates{
		LuaState: luaState,
		Cancel:   cancel,
	}
}

func (config *TomlConfig) deleteLstate(name string) {
	if config.LuaStates == nil {
		return
	}

	if config.LuaStates[name].Cancel != nil {
		config.LuaStates[name].Cancel()
	}
	delete(config.LuaStates, name)
}

func (config *TomlConfig) insertLuaCommand(
	cmd, path, name string,
) {
	if config.LuaCommands == nil {
		config.LuaCommands = make(map[string]LuaCommand)
	}
	config.LuaCommands[cmd] = LuaCommand{Path: path, FuncName: name}
}

func (config *TomlConfig) deleteLuaCommand(name string) {
	if config.LuaCommands == nil {
		return
	}
	delete(config.LuaCommands, name)
}

func (config *TomlConfig) insertTriggeredScript(path, cmd string, triggerType []string) {
	if config.TriggeredScripts == nil {
		config.TriggeredScripts = make(map[string]TriggeredScripts)
	}
	config.TriggeredScripts[path] = TriggeredScripts{
		Path:        path,
		FuncName:    cmd,
		TriggerType: triggerType,
	}
}

func (config *TomlConfig) deleteTriggeredScript(name string) {
	if config.TriggeredScripts == nil {
		return
	}

	delete(config.TriggeredScripts, name)
}

type AppConfig struct {
	Ircd map[string]TomlConfig `toml:"ircd"`
}

type OllamaRequestOptions struct {
	Mirostat      int     `json:"mirostat"`
	MirostatEta   float64 `json:"mirostat_eta"`
	MirostatTau   float64 `json:"mirostat_tau"`
	NumCtx        int     `json:"num_ctx"`
	RepeatLastN   int     `json:"repeat_last_n"`
	RepeatPenalty float64 `json:"repeat_penalty"`
	Temperature   float64 `json:"temperature"`
	Seed          int     `json:"seed"`
	NumPredict    int     `json:"num_predict"`
	TopK          int32   `json:"top_k"`
	TopP          float32 `json:"top_p"`
	MinP          float64 `json:"min_p"`
}

type OllamaChatResponse struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type OllamaChatMessagesResponse struct {
	Messages OllamaChatResponse `json:"message"`
}

type OllamaChatRequest struct {
	Model     string               `json:"model"`
	Stream    bool                 `json:"stream"`
	KeepAlive time.Duration        `json:"keep_alive"`
	Options   OllamaRequestOptions `json:"options"`
	System    string               `json:"system"`
	Messages  []MemoryElement      `json:"messages"`
}

type ORMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
	Refusal string `json:"refusal"`
}

type ORChoice struct {
	FinishReason string    `json:"finish_reason"`
	Index        int       `json:"index"`
	Message      ORMessage `json:"message"`
}

type ORUsage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}
type ORResponse struct {
	Id                string     `json:"id"`
	Provider          string     `json:"provider"`
	Model             string     `json:"model"`
	Object            string     `json:"object"`
	Created           int64      `json:"created"`
	Choices           []ORChoice `json:"choices"`
	SystemFingerprint string     `json:"system_fingerprint"`
	Usage             ORUsage    `json:"usage"`
}

type MemoryElement struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type FeedConfig struct {
	Name       string `json:"name"`
	URL        string `json:"url"`
	UserAgent  string `json:"userAgent"`
	Proxy      string `json:"proxy"`
	Timeout    int    `json:"timeout"`
	FeedParser *gofeed.Parser
}

type RSSConfig struct {
	Feeds  []FeedConfig `json:"feeds"`
	Period int          `json:"period"`
}

func LogError(err error) {
	fn, file, line, ok := runtime.Caller(1)
	if ok {
		log.Printf("%s: %s-%d >>> %v", runtime.FuncForPC(fn).Name(), file, line, err)
	} else {
		log.Print(err)
	}
}

func LogErrorFatal(err error) {
	fn, file, line, ok := runtime.Caller(1)
	if ok {
		log.Fatalf("%s: %s-%d >>> %v", runtime.FuncForPC(fn).Name(), file, line, err)
	} else {
		log.Fatal(err)
	}
}

type ProxyRoundTripper struct {
	APIKey string

	ProxyURL string
}