From 418eb9b2672da50d670fa9a7b63855cb7b3a2abe Mon Sep 17 00:00:00 2001 From: lukintrees Date: Sat, 18 May 2024 12:04:59 +0300 Subject: [PATCH] Save system message in case of chat summarization error --- bot/openai_helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/openai_helper.py b/bot/openai_helper.py index 5a1896cf..e7745497 100644 --- a/bot/openai_helper.py +++ b/bot/openai_helper.py @@ -246,7 +246,7 @@ async def __common_get_chat_response(self, chat_id: int, query: str, stream=Fals self.__add_to_history(chat_id, role="user", content=query) except Exception as e: logging.warning(f'Error while summarising chat history: {str(e)}. Popping elements instead...') - self.conversations[chat_id] = self.conversations[chat_id][-self.config['max_history_size']:] + self.conversations[chat_id] = [self.conversations[chat_id][0]] + self.conversations[chat_id][-self.config['max_history_size'] - 1:] common_args = { 'model': self.config['model'] if not self.conversations_vision[chat_id] else self.config['vision_model'], @@ -438,7 +438,7 @@ async def __common_get_chat_response_vision(self, chat_id: int, content: list, s self.conversations[chat_id] += [last] except Exception as e: logging.warning(f'Error while summarising chat history: {str(e)}. Popping elements instead...') - self.conversations[chat_id] = self.conversations[chat_id][-self.config['max_history_size']:] + self.conversations[chat_id] = [self.conversations[chat_id][0]] + self.conversations[chat_id][-self.config['max_history_size'] - 1:] message = {'role':'user', 'content':content}