aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-11-16 04:51:09 +0000
committerterminaldweller <devi@terminaldweller.com>2024-11-16 04:51:09 +0000
commit8fd3bf7c17615a0a058305436fa7b755b1de7c10 (patch)
treea9e1ef0ffc8569046c0f8704f70bb588a4db3ff5
parentadded the iana whois command. added the new genelirc option (diff)
downloadmilla-main.tar.gz
milla-main.zip
moves some functions to utils.goHEADmain
-rw-r--r--Dockerfile1
-rw-r--r--README.md5
-rw-r--r--main.go77
-rw-r--r--openrouter.go2
-rw-r--r--utils.go53
5 files changed, 81 insertions, 57 deletions
diff --git a/Dockerfile b/Dockerfile
index 4734f7f..552ff6d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -13,4 +13,5 @@ RUN set -eux; \
chown -R user:user "$HOME"
COPY --from=builder /milla/milla "$HOME/milla"
RUN chown user:user "$HOME/milla"
+USER user
ENTRYPOINT ["home/user/milla"]
diff --git a/README.md b/README.md
index 134be91..5d0b41a 100644
--- a/README.md
+++ b/README.md
@@ -132,8 +132,12 @@ Ping timeout for the IRC server.
#### topP
+set the Top_p paramater
+
#### topK
+set the Top_k parameter
+
#### skipTLSVerify
Skip verifying the IRC server's TLS certificate. This only makes sense if you are trying to connect to an IRC server with a self-signed certificate.
@@ -482,6 +486,7 @@ Rolls a number between 1 and 6 if no arguments are given. With one argument it r
#### whois
IANA whois endpoint query: `milla: /whois xyz`
+This command uses the `generalProxy` option.
## Deploy
diff --git a/main.go b/main.go
index 31b9c88..082586f 100644
--- a/main.go
+++ b/main.go
@@ -165,52 +165,6 @@ func extractLast256ColorEscapeCode(str string) (string, error) {
return lastMatch[1], nil
}
-func chunker(inputString string, chromaFormatter string) []string {
- chunks := strings.Split(inputString, "\n")
-
- switch chromaFormatter {
- case "terminal":
- fallthrough
- case "terminal8":
- fallthrough
- case "terminal16":
- fallthrough
- case "terminal256":
- for count, chunk := range chunks {
- lastColorCode, err := extractLast256ColorEscapeCode(chunk)
- if err != nil {
- continue
- }
-
- if count <= len(chunks)-2 {
- chunks[count+1] = fmt.Sprintf("\033[38;5;%sm", lastColorCode) + chunks[count+1]
- }
- }
- case "terminal16m":
- fallthrough
- default:
- }
-
- return chunks
-}
-
-func sendToIRC(
- client *girc.Client,
- event girc.Event,
- message string,
- chromaFormatter string,
-) {
- chunks := chunker(message, chromaFormatter)
-
- for _, chunk := range chunks {
- if len(strings.TrimSpace(chunk)) == 0 {
- continue
- }
-
- client.Cmd.Reply(event, chunk)
- }
-}
-
func getHelpString() string {
helpString := "Commands:\n"
helpString += "help - show this help message\n"
@@ -242,6 +196,13 @@ func setFieldByName(v reflect.Value, field string, value string) error {
switch fieldValue.Kind() {
case reflect.String:
fieldValue.SetString(value)
+ case reflect.Int32:
+ intValue, err := strconv.ParseInt(value, 10, 32)
+ if err != nil {
+ return errWrongDataForField
+ }
+
+ fieldValue.SetInt(int64(intValue))
case reflect.Int:
intValue, err := strconv.Atoi(value)
if err != nil {
@@ -357,7 +318,7 @@ func handleCustomCommand(
result := ChatGPTRequestProcessor(appConfig, client, event, &gptMemory, customCommand.Prompt)
if result != "" {
- sendToIRC(client, event, result, appConfig.ChromaFormatter)
+ SendToIRC(client, event, result, appConfig.ChromaFormatter)
}
case "gemini":
var geminiMemory []*genai.Content
@@ -382,7 +343,7 @@ func handleCustomCommand(
result := GeminiRequestProcessor(appConfig, client, event, &geminiMemory, customCommand.Prompt)
if result != "" {
- sendToIRC(client, event, result, appConfig.ChromaFormatter)
+ SendToIRC(client, event, result, appConfig.ChromaFormatter)
}
case "ollama":
var ollamaMemory []MemoryElement
@@ -403,7 +364,7 @@ func handleCustomCommand(
result := OllamaRequestProcessor(appConfig, client, event, &ollamaMemory, customCommand.Prompt)
if result != "" {
- sendToIRC(client, event, result, appConfig.ChromaFormatter)
+ SendToIRC(client, event, result, appConfig.ChromaFormatter)
}
case "openrouter":
var memory []MemoryElement
@@ -424,7 +385,7 @@ func handleCustomCommand(
result := ORRequestProcessor(appConfig, client, event, &memory, customCommand.Prompt)
if result != "" {
- sendToIRC(client, event, result, appConfig.ChromaFormatter)
+ SendToIRC(client, event, result, appConfig.ChromaFormatter)
}
default:
}
@@ -460,7 +421,7 @@ func runCommand(
switch args[0] {
case "help":
- sendToIRC(client, event, getHelpString(), "noop")
+ SendToIRC(client, event, getHelpString(), "noop")
case "set":
if len(args) < 3 { //nolint: mnd,gomnd
client.Cmd.Reply(event, errNotEnoughArgs.Error())
@@ -498,7 +459,13 @@ func runCommand(
for i := range value.NumField() {
field := t.Field(i)
fieldValue := value.Field(i).Interface()
- client.Cmd.Reply(event, fmt.Sprintf("%s: %v", field.Name, fieldValue))
+
+ fieldValueString, ok := fieldValue.(string)
+ if !ok {
+ continue
+ }
+
+ client.Cmd.Reply(event, fmt.Sprintf("%s: %v", field.Name, fieldValueString))
}
case "memstats":
var memStats runtime.MemStats
@@ -842,7 +809,7 @@ func OllamaHandler(
result := OllamaRequestProcessor(appConfig, client, event, ollamaMemory, prompt)
if result != "" {
- sendToIRC(client, event, result, appConfig.ChromaFormatter)
+ SendToIRC(client, event, result, appConfig.ChromaFormatter)
}
})
}
@@ -1005,7 +972,7 @@ func GeminiHandler(
result := GeminiRequestProcessor(appConfig, client, event, geminiMemory, prompt)
if result != "" {
- sendToIRC(client, event, result, appConfig.ChromaFormatter)
+ SendToIRC(client, event, result, appConfig.ChromaFormatter)
}
})
}
@@ -1150,7 +1117,7 @@ func ChatGPTHandler(
result := ChatGPTRequestProcessor(appConfig, client, event, gptMemory, prompt)
if result != "" {
- sendToIRC(client, event, result, appConfig.ChromaFormatter)
+ SendToIRC(client, event, result, appConfig.ChromaFormatter)
}
})
}
diff --git a/openrouter.go b/openrouter.go
index 8a1a1e5..09e78b5 100644
--- a/openrouter.go
+++ b/openrouter.go
@@ -193,7 +193,7 @@ func ORHandler(
result := ORRequestProcessor(appConfig, client, event, memory, prompt)
if result != "" {
- sendToIRC(client, event, result, appConfig.ChromaFormatter)
+ SendToIRC(client, event, result, appConfig.ChromaFormatter)
}
})
diff --git a/utils.go b/utils.go
index e09456e..6bf0015 100644
--- a/utils.go
+++ b/utils.go
@@ -1,6 +1,11 @@
package main
-import "github.com/lrstanley/girc"
+import (
+ "fmt"
+ "strings"
+
+ "github.com/lrstanley/girc"
+)
func IrcJoin(irc *girc.Client, channel []string) {
if len(channel) > 1 && channel[1] != "" {
@@ -9,3 +14,49 @@ func IrcJoin(irc *girc.Client, channel []string) {
irc.Cmd.Join(channel[0])
}
}
+
+func chunker(inputString string, chromaFormatter string) []string {
+ chunks := strings.Split(inputString, "\n")
+
+ switch chromaFormatter {
+ case "terminal":
+ fallthrough
+ case "terminal8":
+ fallthrough
+ case "terminal16":
+ fallthrough
+ case "terminal256":
+ for count, chunk := range chunks {
+ lastColorCode, err := extractLast256ColorEscapeCode(chunk)
+ if err != nil {
+ continue
+ }
+
+ if count <= len(chunks)-2 {
+ chunks[count+1] = fmt.Sprintf("\033[38;5;%sm", lastColorCode) + chunks[count+1]
+ }
+ }
+ case "terminal16m":
+ fallthrough
+ default:
+ }
+
+ return chunks
+}
+
+func SendToIRC(
+ client *girc.Client,
+ event girc.Event,
+ message string,
+ chromaFormatter string,
+) {
+ chunks := chunker(message, chromaFormatter)
+
+ for _, chunk := range chunks {
+ if len(strings.TrimSpace(chunk)) == 0 {
+ continue
+ }
+
+ client.Cmd.Reply(event, chunk)
+ }
+}