diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 121 |
1 files changed, 107 insertions, 14 deletions
@@ -345,7 +345,7 @@ func handleCustomCommand( for _, customContext := range customCommand.Context { gptMemory = append(gptMemory, openai.ChatCompletionMessage{ - Role: openai.ChatMessageRoleUser, + Role: openai.ChatMessageRoleAssistant, Content: customContext, }) } @@ -376,7 +376,7 @@ func handleCustomCommand( Parts: []genai.Part{ genai.Text(customContext), }, - Role: "user", + Role: "model", }) } @@ -396,7 +396,7 @@ func handleCustomCommand( for _, customContext := range customCommand.Context { ollamaMemory = append(ollamaMemory, MemoryElement{ - Role: "user", + Role: "assistant", Content: customContext, }) } @@ -405,6 +405,27 @@ func handleCustomCommand( if result != "" { sendToIRC(client, event, result, appConfig.ChromaFormatter) } + case "openrouter": + var memory []MemoryElement + + for _, log := range logs { + memory = append(memory, MemoryElement{ + Role: "user", + Content: log.Log, + }) + } + + for _, customContext := range customCommand.Context { + memory = append(memory, MemoryElement{ + Role: "user", + Content: customContext, + }) + } + + result := ORRequestProcessor(appConfig, client, event, &memory, customCommand.Prompt) + if result != "" { + sendToIRC(client, event, result, appConfig.ChromaFormatter) + } default: } } @@ -497,8 +518,11 @@ func runCommand( break } - - client.Cmd.Join(args[1]) + if len(args) == 3 { + IrcJoin(client, []string{args[1], args[2]}) + } else { + client.Cmd.Join(args[1]) + } case "leave": if !isFromAdmin(appConfig.Admins, event) { break @@ -570,6 +594,15 @@ func runCommand( case "forget": client.Cmd.Reply(event, "I no longer even know whether you're supposed to wear or drink a camel.'") + case "whois": + if len(args) < 2 { + client.Cmd.Reply(event, errNotEnoughArgs.Error()) + + break + } + + ianaResponse := IANAWhoisGet(args[1], appConfig) + client.Cmd.Reply(event, ianaResponse) case "roll": lowerLimit := 1 upperLimit := 6 @@ -649,6 +682,13 @@ func DoOllamaRequest( if len(*ollamaMemory) > appConfig.MemoryLimit { *ollamaMemory = []MemoryElement{} + + for _, context := range appConfig.Context { + *ollamaMemory = append(*ollamaMemory, MemoryElement{ + Role: "assistant", + Content: context, + }) + } } *ollamaMemory = append(*ollamaMemory, memoryElement) @@ -674,7 +714,7 @@ func DoOllamaRequest( ctx, cancel := context.WithTimeout(context.Background(), time.Duration(appConfig.RequestTimeout)*time.Second) defer cancel() - request, err := http.NewRequest(http.MethodPost, appConfig.OllamaEndpoint, bytes.NewBuffer(jsonPayload)) + request, err := http.NewRequest(http.MethodPost, appConfig.Endpoint, bytes.NewBuffer(jsonPayload)) if err != nil { return "", err @@ -887,6 +927,15 @@ func GeminiRequestProcessor( if len(*geminiMemory) > appConfig.MemoryLimit { *geminiMemory = []*genai.Content{} + + for _, context := range appConfig.Context { + *geminiMemory = append(*geminiMemory, &genai.Content{ + Parts: []genai.Part{ + genai.Text(context), + }, + Role: "model", + }) + } } *geminiMemory = append(*geminiMemory, &genai.Content{ @@ -995,6 +1044,10 @@ func DoChatGPTRequest( config := openai.DefaultConfig(appConfig.Apikey) config.HTTPClient = &httpClient + if appConfig.Endpoint != "" { + config.BaseURL = appConfig.Endpoint + log.Print(config.BaseURL) + } gptClient := openai.NewClientWithConfig(config) @@ -1036,6 +1089,13 @@ func ChatGPTRequestProcessor( if len(*gptMemory) > appConfig.MemoryLimit { *gptMemory = []openai.ChatCompletionMessage{} + + for _, context := range appConfig.Context { + *gptMemory = append(*gptMemory, openai.ChatCompletionMessage{ + Role: openai.ChatMessageRoleAssistant, + Content: context, + }) + } } var writer bytes.Buffer @@ -1117,7 +1177,7 @@ func connectToDB(appConfig *TomlConfig, ctx *context.Context, poolChan chan *pgx log.Printf("%s connected to database", appConfig.IRCDName) for _, channel := range appConfig.ScrapeChannels { - tableName := getTableFromChanName(channel, appConfig.IRCDName) + tableName := getTableFromChanName(channel[0], appConfig.IRCDName) query := fmt.Sprintf( `create table if not exists %s ( id serial primary key, @@ -1176,7 +1236,6 @@ func populateWatchListWords(appConfig *TomlConfig) { } } - // log.Print(appConfig.WatchLists["security"].Words) } func WatchListHandler(irc *girc.Client, appConfig TomlConfig) { @@ -1193,7 +1252,7 @@ func WatchListHandler(irc *girc.Client, appConfig TomlConfig) { for _, channel := range watchlist.WatchList { isRightEventType = false - if channel == event.Params[0] { + if channel[0] == event.Params[0] { for _, eventType := range watchlist.EventTypes { if eventType == event.Command { @@ -1220,7 +1279,7 @@ func WatchListHandler(irc *girc.Client, appConfig TomlConfig) { "\x1b[0m" + event.Last()[indexes[0]+1+nextWhitespaceIndex:] irc.Cmd.Message( - watchlist.AlertChannel, + watchlist.AlertChannel[0], fmt.Sprintf("%s: %s", watchname, rewrittenMessage)) log.Printf("matched from watchlist -- %s: %s", watchname, event.Last()) @@ -1241,6 +1300,8 @@ func runIRC(appConfig TomlConfig) { var GPTMemory []openai.ChatCompletionMessage + var ORMemory []MemoryElement + poolChan := make(chan *pgxpool.Pool, 1) irc := girc.New(girc.Config{ @@ -1306,17 +1367,49 @@ func runIRC(appConfig TomlConfig) { irc.Handlers.AddBg(girc.CONNECTED, func(c *girc.Client, _ girc.Event) { for _, channel := range appConfig.IrcChannels { - c.Cmd.Join(channel) + IrcJoin(irc, channel) } }) switch appConfig.Provider { case "ollama": + for _, context := range appConfig.Context { + OllamaMemory = append(OllamaMemory, MemoryElement{ + Role: "assistant", + Content: context, + }) + } + OllamaHandler(irc, &appConfig, &OllamaMemory) case "gemini": + for _, context := range appConfig.Context { + GeminiMemory = append(GeminiMemory, &genai.Content{ + Parts: []genai.Part{ + genai.Text(context), + }, + Role: "model", + }) + } + GeminiHandler(irc, &appConfig, &GeminiMemory) case "chatgpt": + for _, context := range appConfig.Context { + GPTMemory = append(GPTMemory, openai.ChatCompletionMessage{ + Role: openai.ChatMessageRoleAssistant, + Content: context, + }) + } + ChatGPTHandler(irc, &appConfig, &GPTMemory) + case "openrouter": + for _, context := range appConfig.Context { + ORMemory = append(ORMemory, MemoryElement{ + Role: "user", + Content: context, + }) + } + + ORHandler(irc, &appConfig, &ORMemory) } go LoadAllPlugins(&appConfig, irc) @@ -1331,7 +1424,7 @@ func runIRC(appConfig TomlConfig) { if len(appConfig.ScrapeChannels) > 0 { irc.Handlers.AddBg(girc.CONNECTED, func(c *girc.Client, _ girc.Event) { for _, channel := range appConfig.ScrapeChannels { - c.Cmd.Join(channel) + IrcJoin(irc, channel) } }) @@ -1342,10 +1435,10 @@ func runIRC(appConfig TomlConfig) { irc.Handlers.AddBg(girc.CONNECTED, func(client *girc.Client, _ girc.Event) { for _, watchlist := range appConfig.WatchLists { log.Print("joining ", watchlist.AlertChannel) - client.Cmd.Join(watchlist.AlertChannel) + IrcJoin(irc, watchlist.AlertChannel) for _, channel := range watchlist.WatchList { - client.Cmd.Join(channel) + IrcJoin(irc, channel) } } }) |