Gemini: Add error handling/logging on query

This commit is contained in:
Gordon Shumway 2024-08-07 12:03:44 -04:00 committed by GitHub
parent a122a14e0e
commit 75927e79bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,6 +31,7 @@
from supybot import utils, plugins, ircutils, callbacks
from supybot.commands import *
from supybot.i18n import PluginInternationalization
import supybot.log as log
import re
import google.generativeai as genai
@ -65,10 +66,14 @@ class Gemini(callbacks.Plugin):
if not self.history[channel] or max_history < 1:
self.history[channel] = []
chat = model.start_chat(history=self.history[channel][-max_history:])
if self.registryValue("nick_include", msg.channel):
response = chat.send_message("%s: %s" % (msg.nick, text))
else:
response = chat.send_message(text)
try:
if self.registryValue("nick_include", msg.channel):
response = chat.send_message("%s: %s" % (msg.nick, 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):
content = re.sub(r"^%s: " % (irc.nick), "", response.text)
else: