From e6d13afcca169436879fd932f002c36648d9f424 Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk Date: Tue, 28 Mar 2023 21:24:49 +0200 Subject: [PATCH] Reduce timeouts, introduce ignore-channels, fix the fix functions. --- fjerkroa_bot/ai_responder.py | 6 +++--- fjerkroa_bot/discord_bot.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fjerkroa_bot/ai_responder.py b/fjerkroa_bot/ai_responder.py index cc9e9a4..65bd955 100644 --- a/fjerkroa_bot/ai_responder.py +++ b/fjerkroa_bot/ai_responder.py @@ -137,7 +137,7 @@ class AIResponder(object): return answer messages = [{"role": "system", "content": self.config["fix-description"]}, {"role": "user", "content": answer}] - for _ in range(4): + for _ in range(3): try: result = await openai.ChatCompletion.acreate(model=self.config["fix-model"], messages=messages, @@ -147,7 +147,7 @@ class AIResponder(object): start, end = response.find("```"), response.rfind("```") if start == -1 or end == -1 or (start + 3) >= end: return answer - response = response[start + 3, end] + response = response[start + 3:end] logging.info(f"fixed answer:\n{pformat(response)}") return response except Exception as err: @@ -167,7 +167,7 @@ class AIResponder(object): limit = self.config["history-limit"] if self.short_path(message, limit): return AIResponse(None, False, None, None, False) - for _ in range(14): + for _ in range(5): messages = self._message(message, limit) logging.info(f"try to send this messages:\n{pformat(messages)}") answer, limit = await self._acreate(messages, limit) diff --git a/fjerkroa_bot/discord_bot.py b/fjerkroa_bot/discord_bot.py index d527ab7..98cacdd 100644 --- a/fjerkroa_bot/discord_bot.py +++ b/fjerkroa_bot/discord_bot.py @@ -85,7 +85,10 @@ class FjerkroaBot(commands.Bot): channel_name = str(channel.name) except Exception: channel_name = str(channel.id) - logging.info(f"handle message {str(message)} for channel {channel_name}") + if channel_name in self.config.get('ignore-channels', []): + logging.info(f"ignore message {repr(message)} for channel {channel_name}") + return + logging.info(f"handle message {repr(message)} for channel {channel_name}") if channel_name in self.aichannels: airesponder = self.aichannels[channel_name] else: