Compare commits

..

No commits in common. "2697e6a259ecf6a4240f707b164201294ac4c455" and "d9342f184e9569cebfc73d561c0574c34ed37e6e" have entirely different histories.

2 changed files with 18 additions and 20 deletions

View File

@ -6,7 +6,7 @@ import (
"regexp" "regexp"
) )
const defaultMessage = "I don't know how to respond to that. If you'd like to ask an LLM, use the `llm` command." const defaultMessage = "I don't know how to respond to that. If you'd like to ask GPT, use the `gpt` command."
type DeadEndPlugin struct { type DeadEndPlugin struct {
b bot.Bot b bot.Bot

View File

@ -7,6 +7,7 @@ import (
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
"github.com/velour/catbase/config" "github.com/velour/catbase/config"
"regexp" "regexp"
"slices"
) )
const gpt3URL = "https://api.openai.com/v1/engines/%s/completions" const gpt3URL = "https://api.openai.com/v1/engines/%s/completions"
@ -46,20 +47,20 @@ func (p *LLMPlugin) register() {
{ {
Kind: bot.Message, IsCmd: true, Kind: bot.Message, IsCmd: true,
Regex: regexp.MustCompile(`(?is)^llm (?P<text>.*)`), Regex: regexp.MustCompile(`(?is)^llm (?P<text>.*)`),
HelpText: "chat completion using first-available AI", HelpText: "chat completion",
Handler: p.chatMessage, Handler: p.chatMessageForce,
}, },
{ {
Kind: bot.Message, IsCmd: true, Kind: bot.Message, IsCmd: true,
Regex: regexp.MustCompile(`(?is)^gpt4 (?P<text>.*)`), Regex: regexp.MustCompile(`(?is)^gpt (?P<text>.*)`),
HelpText: "chat completion using OpenAI", HelpText: "chat completion",
Handler: p.gptMessage, Handler: p.chatMessageForce,
}, },
{ {
Kind: bot.Message, IsCmd: true, Kind: bot.Message, IsCmd: true,
Regex: regexp.MustCompile(`(?is)^llm-puke$`), Regex: regexp.MustCompile(`(?is)^got (?P<text>.*)`),
HelpText: "clear chat history", HelpText: "chat completion",
Handler: p.puke, Handler: p.chatMessageForce,
}, },
} }
p.b.RegisterTable(p, p.h) p.b.RegisterTable(p, p.h)
@ -76,6 +77,14 @@ func (p *LLMPlugin) setPromptMessage(r bot.Request) bool {
} }
func (p *LLMPlugin) chatMessage(r bot.Request) bool { func (p *LLMPlugin) chatMessage(r bot.Request) bool {
if slices.Contains(p.c.GetArray("gpt.silence", []string{}), r.Msg.Channel) {
log.Debug().Msgf("%s silenced", r.Msg.Channel)
return true
}
return p.chatMessageForce(r)
}
func (p *LLMPlugin) chatMessageForce(r bot.Request) bool {
p.chatHistory = append(p.chatHistory, chatEntry{ p.chatHistory = append(p.chatHistory, chatEntry{
Role: "user", Role: "user",
Content: r.Values["text"], Content: r.Values["text"],
@ -94,10 +103,6 @@ func (p *LLMPlugin) chatMessage(r bot.Request) bool {
} else { } else {
log.Info().Msgf("Llama is currently down") log.Info().Msgf("Llama is currently down")
} }
return p.gptMessage(r)
}
func (p *LLMPlugin) gptMessage(r bot.Request) bool {
resp, err := p.chatGPT(r.Values["text"]) resp, err := p.chatGPT(r.Values["text"])
if err != nil { if err != nil {
resp = fmt.Sprintf("Error: %s", err) resp = fmt.Sprintf("Error: %s", err)
@ -109,10 +114,3 @@ func (p *LLMPlugin) gptMessage(r bot.Request) bool {
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, resp) p.b.Send(r.Conn, bot.Message, r.Msg.Channel, resp)
return true return true
} }
func (p *LLMPlugin) puke(r bot.Request) bool {
resp := fmt.Sprintf("I just forgot %d lines of chat history.", len(p.chatHistory))
p.chatHistory = []chatEntry{}
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, resp)
return true
}