aboutsummaryrefslogtreecommitdiffstats
path: root/types.go
blob: 3b7f3ff7be32abec36559516ba86159c19bfcbc4 (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
package main

import (
	"context"
	"time"

	"github.com/jackc/pgx/v5/pgxpool"
	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 CustomCommand struct {
	SQL    string `toml:"sql"`
	Limit  int    `toml:"limit"`
	Prompt string `toml:"prompt"`
}

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

type TomlConfig struct {
	IrcServer           string                   `toml:"ircServer"`
	IrcNick             string                   `toml:"ircNick"`
	IrcSaslUser         string                   `toml:"ircSaslUser"`
	IrcSaslPass         string                   `toml:"ircSaslPass"`
	OllamaEndpoint      string                   `toml:"ollamaEndpoint"`
	Model               string                   `toml:"model"`
	ChromaStyle         string                   `toml:"chromaStyle"`
	ChromaFormatter     string                   `toml:"chromaFormatter"`
	Provider            string                   `toml:"provider"`
	Apikey              string                   `toml:"apikey"`
	OllamaSystem        string                   `toml:"ollamaSystem"`
	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"`
	IRCDName            string                   `toml:"ircdName"`
	WebIRCPassword      string                   `toml:"webIRCPassword"`
	WebIRCGateway       string                   `toml:"webIRCGateway"`
	WebIRCHostname      string                   `toml:"webIRCHostname"`
	WebIRCAddress       string                   `toml:"webIRCAddress"`
	Plugins             []string                 `toml:"plugins"`
	CustomCommands      map[string]CustomCommand `toml:"customCommands"`
	LuaStates           map[string]LuaLstates
	Temp                float64 `toml:"temp"`
	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"`
	TopP                float32 `toml:"topP"`
	TopK                int32   `toml:"topK"`
	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
	}
	config.LuaStates[name].Cancel()
	delete(config.LuaStates, name)
}

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

type OllamaRequestOptions struct {
	Temperature float64 `json:"temperature"`
}

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"`
	Messages  []MemoryElement      `json:"messages"`
}

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