From b11cd11459272b993c369412c13f17cf0877806a Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:16:55 +0000 Subject: [PATCH] feat: Updated backend/memory/memory_manager.py --- backend/memory/memory_manager.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/memory/memory_manager.py b/backend/memory/memory_manager.py index 5a93cb7..96a2ff7 100644 --- a/backend/memory/memory_manager.py +++ b/backend/memory/memory_manager.py @@ -9,6 +9,7 @@ from instructor import OpenAISchema from openai import OpenAI, AsyncOpenAI import logging +from gensim.summarize import summarize CLIENT = instructor.patch(AsyncOpenAI()) @@ -34,6 +35,7 @@ def __init__(self, db_connection, project_directory) -> None: self.cur = self.conn.cursor() self.client = CLIENT self.project_directory = project_directory + self.turn_counter = 0 self.create_tables() def create_tables(self) -> None: @@ -93,6 +95,9 @@ def remove_context(self, context: str) -> None: ) self.conn.commit() + def summarize_context(self): + return summarize(self.context) + def __str__(self) -> str: return self.context @@ -321,6 +326,10 @@ def create_tables(self) -> None: async def update_context(self): ctx = self.working_context.get_context() + self.turn_counter += 1 + if self.turn_counter == 5: + self.context = self.summarize_context() + self.turn_counter = 0 print("Working Context: ", ctx) prompt = f""" You are monitoring a conversation between an engineer and their AI Assistant.