plugins: unknown cmd/q now use gpt3 if possible

This commit is contained in:
dece 2022-11-29 12:56:11 +01:00
parent 237e88cf16
commit 6eccd2974b
3 changed files with 25 additions and 13 deletions

View file

@ -189,10 +189,6 @@
"param_source": "from",
"param_dest": "to"
},
"unknowncommand": {
"api_key": "",
"max_pods": 1
},
"unknownquestion": {
"pass_to_misc_rate": 50
},

View file

@ -1,11 +1,19 @@
from edmond.plugin import Plugin
from edmond.plugins.gpt3 import Gpt3Plugin
class UnknownCommandPlugin(Plugin):
def __init__(self, bot):
super().__init__(bot)
self.priority = -6
self.priority: int = -6
self.gpt3_plugin: Gpt3Plugin
def on_welcome(self, _):
self.gpt3_plugin = self.bot.get_plugin("gpt3")
if self.gpt3_plugin is None or not self.gpt3_plugin:
self.bot.log_w("GPT-3 plugin is not available.")
self.is_ready = False
def on_pubmsg(self, event):
message = self.should_read_message(event.arguments[0])
@ -16,5 +24,5 @@ class UnknownCommandPlugin(Plugin):
return False
query = " ".join(words[:-1])
self.bot.say(event.target, f"UnknownCommand: {query}")
self.gpt3_plugin.reply(query, event.target)
return True

View file

@ -7,26 +7,34 @@ from edmond.utils import proc
class UnknownQuestionPlugin(Plugin):
"""Handle unknown questions.
Reply with some question marks, but there is a configurable rate to pass
processing of the message to the misc_reactions if available.
"""
REQUIRED_CONFIGS = ["pass_to_misc_rate"]
def __init__(self, bot):
super().__init__(bot)
self.priority = -7
self.misc_plugin = None
self.gpt3_plugin = None
def on_welcome(self, event):
def on_welcome(self, _):
self.misc_plugin = self.bot.get_plugin("miscreactions")
self.gpt3_plugin = self.bot.get_plugin("gpt3")
def on_pubmsg(self, event):
message = self.should_read_message(event.arguments[0])
if message is None:
return False
if self.misc_plugin and proc(self.config["pass_to_misc_rate"]):
if self.gpt3_plugin:
return self.gpt3_plugin.reply(message, event.target)
else:
return self.classic_reply(event)
def classic_reply(self, event):
if (
self.misc_plugin
and "pass_to_misc_rate" in self.config
and proc(self.config["pass_to_misc_rate"])
):
self.misc_plugin.react(event)
else:
self.bot.say(event.target, "?" * random.randint(1, 3))
return True