From fc9a985d67ae92efc57c6c47a971c964ce9d5d79 Mon Sep 17 00:00:00 2001 From: Kye Date: Thu, 10 Aug 2023 10:50:19 -0400 Subject: [PATCH] circular import --- swarms/agents/base.py | 4 +-- swarms/agents/memory/base_memory.py | 29 +++++++++++++------- swarms/agents/memory/chat_message_history.py | 21 -------------- 3 files changed, 20 insertions(+), 34 deletions(-) delete mode 100644 swarms/agents/memory/chat_message_history.py diff --git a/swarms/agents/base.py b/swarms/agents/base.py index e81e9e39..afb98d88 100644 --- a/swarms/agents/base.py +++ b/swarms/agents/base.py @@ -6,12 +6,10 @@ from langchain.chains.llm import LLMChain from pydantic import ValidationError from swarms.agents.memory.base import VectorStoreRetriever -from swarms.agents.memory.base_memory import ChatMessageHistory, BaseChatMessageHistory - +from swarms.agents.memory.base_memory import BaseChatMessageHistory, ChatMessageHistory from swarms.agents.memory.document import Document from swarms.agents.models.base import AbstractModel -from swarms.agents.models.prompts.agent_output_parser import AgentOutputParser from swarms.agents.models.prompts.agent_prompt import ( AIMessage, diff --git a/swarms/agents/memory/base_memory.py b/swarms/agents/memory/base_memory.py index 6853db38..6a96697f 100644 --- a/swarms/agents/memory/base_memory.py +++ b/swarms/agents/memory/base_memory.py @@ -1,19 +1,13 @@ from __future__ import annotations from abc import ABC, abstractmethod -from typing import Any, Dict, List - -from abc import ABC -from typing import Any, Dict, Optional, Tuple - -from pydantic import Field +from typing import Any, Dict, List, Optional, Tuple +from langchain.memory.utils import get_prompt_input_key +from pydantic import BaseModel, Field from swarms.agents.models.prompts.base import AIMessage, BaseMessage, HumanMessage from swarms.utils.serializable import Serializable -from swarms.agents.memory.chat_message_history import ChatMessageHistory - -from langchain.memory.utils import get_prompt_input_key class BaseMemory(Serializable, ABC): @@ -132,6 +126,20 @@ class BaseChatMessageHistory(ABC): """Remove all messages from the store""" +class ChatMessageHistory(BaseChatMessageHistory, BaseModel): + """In memory implementation of chat message history. + + Stores messages in an in memory list. + """ + + messages: List[BaseMessage] = [] + + def add_message(self, message: BaseMessage) -> None: + """Add a self-created message to the store""" + self.messages.append(message) + + def clear(self) -> None: + self.messages = [] class BaseChatMemory(BaseMemory, ABC): """Abstract base class for chat memory.""" @@ -164,4 +172,5 @@ class BaseChatMemory(BaseMemory, ABC): def clear(self) -> None: """Clear memory contents.""" - self.chat_memory.clear() \ No newline at end of file + self.chat_memory.clear() + diff --git a/swarms/agents/memory/chat_message_history.py b/swarms/agents/memory/chat_message_history.py deleted file mode 100644 index 2d70451b..00000000 --- a/swarms/agents/memory/chat_message_history.py +++ /dev/null @@ -1,21 +0,0 @@ -from typing import List - -from pydantic import BaseModel - -from swarms.agents.memory.base_memory import BaseChatMessageHistory, BaseMessage - - -class ChatMessageHistory(BaseChatMessageHistory, BaseModel): - """In memory implementation of chat message history. - - Stores messages in an in memory list. - """ - - messages: List[BaseMessage] = [] - - def add_message(self, message: BaseMessage) -> None: - """Add a self-created message to the store""" - self.messages.append(message) - - def clear(self) -> None: - self.messages = [] \ No newline at end of file