From 8c718ad2729ed013fda10350f153f83f79d4cfee Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk Date: Mon, 21 Aug 2023 13:38:43 +0200 Subject: [PATCH] Do not historise the boreness question. --- fjerkroa_bot/ai_responder.py | 14 ++++++++++---- fjerkroa_bot/discord_bot.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/fjerkroa_bot/ai_responder.py b/fjerkroa_bot/ai_responder.py index aa60520..8acff91 100644 --- a/fjerkroa_bot/ai_responder.py +++ b/fjerkroa_bot/ai_responder.py @@ -87,11 +87,12 @@ class AIMessageBase(object): class AIMessage(AIMessageBase): - def __init__(self, user: str, message: str, channel: str = "chat", direct: bool = False) -> None: + def __init__(self, user: str, message: str, channel: str = "chat", direct: bool = False, historise_question: bool = True) -> None: self.user = user self.message = message self.channel = channel self.direct = direct + self.historise_question = historise_question class AIResponse(AIMessageBase): @@ -322,8 +323,13 @@ class AIResponder(object): else: self.shrink_history_by_one(index + 1) - def update_history(self, question: Dict[str, Any], answer: Dict[str, Any], limit: int) -> None: - self.history.append(question) + def update_history(self, + question: Dict[str, Any], + answer: Dict[str, Any], + limit: int, + historise_question: bool = True) -> None: + if historise_question: + self.history.append(question) self.history.append(answer) while len(self.history) > limit: self.shrink_history_by_one() @@ -382,7 +388,7 @@ class AIResponder(object): answer['content'] = str(answer_message) # Update message history - self.update_history(messages[-1], answer, limit) + self.update_history(messages[-1], answer, limit, message.historise_question) logging.info(f"got this answer:\n{str(answer_message)}") # Return the updated answer message diff --git a/fjerkroa_bot/discord_bot.py b/fjerkroa_bot/discord_bot.py index dcaea3b..01af77b 100644 --- a/fjerkroa_bot/discord_bot.py +++ b/fjerkroa_bot/discord_bot.py @@ -73,7 +73,7 @@ class FjerkroaBot(commands.Bot): if random.random() < probability: logging.info(f'Borred with {probability} probability after {elapsed_time}') boreness_prompt = self.config.get('boreness-prompt', 'Pretend that you just now thought of something, be creative.') - message = AIMessage('system', boreness_prompt, self.config.get('chat-channel', 'chat'), True) + message = AIMessage('system', boreness_prompt, self.config.get('chat-channel', 'chat'), True, False) try: await self.respond(message, self.chat_channel) except Exception as err: