mirror of https://github.com/velour/catbase.git
llm: add & shortcut
This commit is contained in:
parent
c20df2d659
commit
c09dfd46e2
|
@ -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 an LLM, use the `llm` command (or prefix your message with &)."
|
||||||
|
|
||||||
type DeadEndPlugin struct {
|
type DeadEndPlugin struct {
|
||||||
b bot.Bot
|
b bot.Bot
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/velour/catbase/bot"
|
"github.com/velour/catbase/bot"
|
||||||
"github.com/velour/catbase/config"
|
"github.com/velour/catbase/config"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,6 +49,12 @@ func (p *LLMPlugin) register() {
|
||||||
HelpText: "set the ChatGPT prompt",
|
HelpText: "set the ChatGPT prompt",
|
||||||
Handler: p.setPromptMessage,
|
Handler: p.setPromptMessage,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Kind: bot.Message, IsCmd: false,
|
||||||
|
Regex: regexp.MustCompile(`(?is)^&(?P<text>.*)`),
|
||||||
|
HelpText: "chat completion using first-available AI",
|
||||||
|
Handler: p.geminiChatMessage,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Kind: bot.Message, IsCmd: true,
|
Kind: bot.Message, IsCmd: true,
|
||||||
Regex: regexp.MustCompile(`(?is)^llm (?P<text>.*)`),
|
Regex: regexp.MustCompile(`(?is)^llm (?P<text>.*)`),
|
||||||
|
@ -55,7 +62,7 @@ func (p *LLMPlugin) register() {
|
||||||
Handler: p.geminiChatMessage,
|
Handler: p.geminiChatMessage,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Kind: bot.Message, IsCmd: true,
|
Kind: bot.Message, IsCmd: false,
|
||||||
Regex: regexp.MustCompile(`(?is)^gpt4 (?P<text>.*)`),
|
Regex: regexp.MustCompile(`(?is)^gpt4 (?P<text>.*)`),
|
||||||
HelpText: "chat completion using OpenAI",
|
HelpText: "chat completion using OpenAI",
|
||||||
Handler: p.gptMessage,
|
Handler: p.gptMessage,
|
||||||
|
@ -66,6 +73,11 @@ func (p *LLMPlugin) register() {
|
||||||
HelpText: "clear chat history",
|
HelpText: "clear chat history",
|
||||||
Handler: p.puke,
|
Handler: p.puke,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Kind: bot.Help, IsCmd: false,
|
||||||
|
Regex: regexp.MustCompile(`.*`),
|
||||||
|
Handler: p.help,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
p.b.RegisterTable(p, p.h)
|
p.b.RegisterTable(p, p.h)
|
||||||
}
|
}
|
||||||
|
@ -164,3 +176,16 @@ func (p *LLMPlugin) puke(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) help(r bot.Request) bool {
|
||||||
|
out := "Talk like a pirate commands:\n"
|
||||||
|
for _, h := range p.h {
|
||||||
|
if h.HelpText == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out += fmt.Sprintf("```%s```\t%s", h.Regex.String(), h.HelpText)
|
||||||
|
}
|
||||||
|
out = strings.TrimSpace(out)
|
||||||
|
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, out)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue