Add support of short path messages, which are not send to the AI but just added to the history.

This commit is contained in:
OK
2023-03-24 13:42:10 +01:00
parent 2e848db333
commit 78591ef13a
3 changed files with 39 additions and 0 deletions
+15
View File
@@ -3,6 +3,7 @@ import openai
import aiohttp
import logging
import time
import re
from io import BytesIO
from pprint import pformat
from typing import Optional, List, Dict, Any
@@ -84,8 +85,22 @@ class AIResponder(object):
response['picture'],
response['hack'])
def short_path(self, message: AIMessage) -> bool:
if 'short-path' not in self.config:
return False
for chan_re, user_re in self.config['short-path']:
chan_ma = re.match(chan_re, message.channel)
user_ma = re.match(user_re, message.user)
if chan_ma and user_ma:
return True
return False
async def send(self, message: AIMessage) -> AIResponse:
limit = self.config["history-limit"]
if self.short_path(message):
self.history.append({"role": "user", "content": str(message)})
self.history = self.history[-limit:]
return AIResponse(None, False, None, None, False)
for _ in range(14):
messages = self._message(message, limit)
logging.info(f"try to send this messages:\n{pformat(messages)}")
+2
View File
@@ -48,6 +48,8 @@ class FjerkroaBot(commands.Bot):
if event.src_path == self.config_file:
self.config = self.load_config(self.config_file)
self.airesponder.config = self.config
for responder in self.aichannels.values():
responder.config = self.config
async def on_ready(self):
print(f"We have logged in as {self.user}")