mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-25 20:41:21 -05:00
Gemini: Add error handling/logging on query
This commit is contained in:
parent
a122a14e0e
commit
75927e79bb
@ -31,6 +31,7 @@
|
|||||||
from supybot import utils, plugins, ircutils, callbacks
|
from supybot import utils, plugins, ircutils, callbacks
|
||||||
from supybot.commands import *
|
from supybot.commands import *
|
||||||
from supybot.i18n import PluginInternationalization
|
from supybot.i18n import PluginInternationalization
|
||||||
|
import supybot.log as log
|
||||||
import re
|
import re
|
||||||
import google.generativeai as genai
|
import google.generativeai as genai
|
||||||
|
|
||||||
@ -65,10 +66,14 @@ class Gemini(callbacks.Plugin):
|
|||||||
if not self.history[channel] or max_history < 1:
|
if not self.history[channel] or max_history < 1:
|
||||||
self.history[channel] = []
|
self.history[channel] = []
|
||||||
chat = model.start_chat(history=self.history[channel][-max_history:])
|
chat = model.start_chat(history=self.history[channel][-max_history:])
|
||||||
if self.registryValue("nick_include", msg.channel):
|
try:
|
||||||
response = chat.send_message("%s: %s" % (msg.nick, text))
|
if self.registryValue("nick_include", msg.channel):
|
||||||
else:
|
response = chat.send_message("%s: %s" % (msg.nick, text))
|
||||||
response = chat.send_message(text)
|
else:
|
||||||
|
response = chat.send_message(text)
|
||||||
|
except Exception as e:
|
||||||
|
log.error("Gemini failed to fetch response: %s", e)
|
||||||
|
return
|
||||||
if self.registryValue("nick_strip", msg.channel):
|
if self.registryValue("nick_strip", msg.channel):
|
||||||
content = re.sub(r"^%s: " % (irc.nick), "", response.text)
|
content = re.sub(r"^%s: " % (irc.nick), "", response.text)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user