From 8b82421b9cfa4e27c49f9c4a9f0d9b459dcecf00 Mon Sep 17 00:00:00 2001 From: Toran Bruce Richards Date: Sun, 30 Apr 2023 17:17:18 +1200 Subject: [PATCH] Run Black and Isort --- autogpt/agent/agent.py | 4 +++- autogpt/llm/chat.py | 12 +++++++++--- autogpt/memory_management/summary_memory.py | 14 ++++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/autogpt/agent/agent.py b/autogpt/agent/agent.py index d8890f4685..99bb48aa39 100644 --- a/autogpt/agent/agent.py +++ b/autogpt/agent/agent.py @@ -56,7 +56,9 @@ class Agent: cfg = Config() self.ai_name = ai_name self.memory = memory - self.summary_memory = "I was created." # Initial memory necessary to avoid hilucination + self.summary_memory = ( + "I was created." # Initial memory necessary to avoid hilucination + ) self.last_memory_index = 0 self.full_message_history = full_message_history self.next_action_count = next_action_count diff --git a/autogpt/llm/chat.py b/autogpt/llm/chat.py index 78e80f9219..610f9d17ae 100644 --- a/autogpt/llm/chat.py +++ b/autogpt/llm/chat.py @@ -155,12 +155,18 @@ def chat_with_ai( # Insert Memories if len(full_message_history) > 0: - newly_trimmed_messages, agent.last_memory_index = get_newly_trimmed_messages( + ( + newly_trimmed_messages, + agent.last_memory_index, + ) = get_newly_trimmed_messages( full_message_history=full_message_history, current_context=current_context, - last_memory_index=agent.last_memory_index + last_memory_index=agent.last_memory_index, + ) + agent.summary_memory = update_running_summary( + current_memory=agent.summary_memory, + new_events=newly_trimmed_messages, ) - agent.summary_memory = update_running_summary(current_memory=agent.summary_memory, new_events=newly_trimmed_messages) current_context.insert(insertion_index, agent.summary_memory) api_manager = ApiManager() diff --git a/autogpt/memory_management/summary_memory.py b/autogpt/memory_management/summary_memory.py index 39f79ef99b..9e6126377b 100644 --- a/autogpt/memory_management/summary_memory.py +++ b/autogpt/memory_management/summary_memory.py @@ -1,3 +1,4 @@ +import json from typing import Dict, List, Tuple from autogpt.config import Config @@ -5,8 +6,12 @@ from autogpt.llm.llm_utils import create_chat_completion cfg = Config() + def get_newly_trimmed_messages( - full_message_history: List[Dict[str, str]], current_context: List[Dict[str, str]], last_memory_index: int) -> Tuple[List[Dict[str, str]], int]: + full_message_history: List[Dict[str, str]], + current_context: List[Dict[str, str]], + last_memory_index: int, +) -> Tuple[List[Dict[str, str]], int]: """ This function returns a list of dictionaries contained in full_message_history with an index higher than prev_index that are absent from current_context. @@ -21,7 +26,9 @@ def get_newly_trimmed_messages( int: The new index value for use in the next loop. """ # Select messages in full_message_history with an index higher than last_memory_index - new_messages = [msg for i, msg in enumerate(full_message_history) if i > last_memory_index] + new_messages = [ + msg for i, msg in enumerate(full_message_history) if i > last_memory_index + ] # Remove messages that are already present in current_context new_messages_not_in_context = [ @@ -34,7 +41,6 @@ def get_newly_trimmed_messages( last_message = new_messages_not_in_context[-1] new_index = full_message_history.index(last_message) - return new_messages_not_in_context, new_index @@ -71,7 +77,7 @@ def update_running_summary(current_memory: str, new_events: List[Dict]) -> str: new_events.remove(event) # This can happen at any point during execturion, not just the beginning - if (len(new_events) == 0): + if len(new_events) == 0: new_events = "Nothing new happened." prompt = f'''Your task is to create a concise running summary of actions and information results in the provided text, focusing on key and potentially important information to remember.