š« CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
feat(memories): Refactor memory system and add a new agent memory `LongtermAgentMemory` (#435)
Tianqi Xud7e49241bcfe
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.pyindex 3b7d876ed..96409b76d 100644--- a/camel/agents/chat_agent.py+++ b/camel/agents/chat_agent.py@@ -21,7 +21,7 @@ from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuplefrom camel.agents import BaseAgentfrom camel.configs import ChatGPTConfigfrom camel.memories import (- BaseMemory,+ AgentMemory,ChatHistoryMemory,MemoryRecord,ScoreBasedContextCreator,@@ -81,7 +81,7 @@ class ChatAgent(BaseAgent):responses. (default :obj:`ModelType.GPT_3_5_TURBO`)model_config (BaseConfig, optional): Configuration options for theLLM model. (default: :obj:`None`)- memory (BaseMemory, optional): The agent memory for managing chat+ memory (AgentMemory, optional): The agent memory for managing chatmessages. If `None`, a :obj:`ChatHistoryMemory` will be used.(default: :obj:`None`)message_window_size (int, optional): The maximum number of previous@@ -105,7 +105,7 @@ class ChatAgent(BaseAgent):system_message: BaseMessage,model_type: Optional[ModelType] = None,model_config: Optional[BaseConfig] = None,- memory: Optional[BaseMemory] = None,+ memory: Optional[AgentMemory] = None,message_window_size: Optional[int] = None,token_limit: Optional[int] = None,output_language: Optional[str] = None,@@ -137,7 +137,7 @@ class ChatAgent(BaseAgent):self.model_backend.token_counter,self.model_token_limit,)- self.memory: BaseMemory = memory or ChatHistoryMemory(+ self.memory: AgentMemory = memory or ChatHistoryMemory(context_creator, window_size=message_window_size)self.terminated: bool = Falsediff --git a/camel/agents/critic_agent.py b/camel/agents/critic_agent.pyindex 19f25a98c..1bdb02491 100644--- a/camel/agents/critic_agent.py+++ b/camel/agents/critic_agent.py@@ -18,7 +18,7 @@ from typing import Any, Dict, Optional, Sequencefrom colorama import Forefrom camel.agents import ChatAgent-from camel.memories import BaseMemory+from camel.memories import AgentMemoryfrom camel.messages import BaseMessagefrom camel.responses import ChatAgentResponsefrom camel.types import ModelType@@ -50,7 +50,7 @@ class CriticAgent(ChatAgent):system_message: BaseMessage,model_type: ModelType = ModelType.GPT_3_5_TURBO,model_config: Optional[Any] = None,- memory: Optional[BaseMemory] = None,+ memory: Optional[AgentMemory] = None,message_window_size: int = 6,retry_attempts: int = 2,verbose: bool = False,diff --git a/camel/memories/__init__.py b/camel/memories/__init__.pyindex ab1a30b46..71c508860 100644--- a/camel/memories/__init__.py+++ b/camel/memories/__init__.py@@ -13,16 +13,26 @@# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========from .records import MemoryRecord, ContextRecord-from .base import BaseMemory-from .context_creators.base import BaseContextCreator+from .base import MemoryBlock, AgentMemory, BaseContextCreatorfrom .context_creators.score_based import ScoreBasedContextCreator-from .chat_history_memory import ChatHistoryMemory+from .blocks.chat_history_block import ChatHistoryBlock+from .blocks.vectordb_block import VectorDBBlock+from .agent_memories import (+ VectorDBMemory,+ ChatHistoryMemory,+ LongtermAgentMemory,+)__all__ = ['MemoryRecord','ContextRecord',- 'BaseMemory',+ 'MemoryBlock',+ "AgentMemory",+ 'BaseContextCreator',+ 'ScoreBasedContextCreator','ChatHistoryMemory',- "BaseContextCreator",- "ScoreBasedContextCreator",+ 'VectorDBMemory',+ 'ChatHistoryBlock',+ 'VectorDBBlock',+ 'LongtermAgentMemory',]diff --git a/camel/memories/agent_memories.py b/camel/memories/agent_memories.pynew file mode 100644index 000000000..a0ef0b132--- /dev/null+++ b/camel/memories/agent_memories.py@@ -0,0 +1,156 @@+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+# Licensed under the Apache License, Version 2.0 (the āLicenseā);+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an āAS ISā BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========++from typing import List, Optional++from camel.memories import (+ AgentMemory,+ BaseContextCreator,+ ContextRecord,+ MemoryRecord,+)+from camel.memories.blocks import ChatHistoryBlock, VectorDBBlock+from camel.storages import BaseKeyValueStorage, BaseVectorStorage+from camel.types import OpenAIBackendRole+++class ChatHistoryMemory(AgentMemory):+ r"""An agent memory wrapper of :obj:`ChatHistoryBlock`.++ Args:+ context_creator (BaseContextCreator): A model context creator.+ storage (BaseKeyValueStorage, optional): A storage backend for storing+ chat history. If `None`, an :obj:`InMemoryKeyValueStorage`+ will be used. (default: :obj:`None`)+ window_size (int, optional): The number of recent chat messages to+ retrieve. If not provided, the entire chat history will be+ retrieved. (default: :obj:`None`)+ """++ def __init__(+ self,+ context_creator: BaseContextCreator,+ storage: Optional[BaseKeyValueStorage] = None,+ window_size: Optional[int] = None,+ ) -> None:+ if window_size is not None and not isinstance(window_size, int):+ raise TypeError("`window_size` must be an integer or None.")+ if window_size is not None and window_size < 0:+ raise ValueError("`window_size` must be non-negative.")+ self._context_creator = context_creator+ self._window_size = window_size+ self._chat_history_block = ChatHistoryBlock(storage=storage)++ def retrieve(self) -> List[ContextRecord]:+ return self._chat_history_block.retrieve(self._window_size)++ def write_records(self, records: List[MemoryRecord]) -> None:+ self._chat_history_block.write_records(records)++ def get_context_creator(self) -> BaseContextCreator:+ return self._context_creator++ def clear(self) -> None:+ self._chat_history_block.clear()+++class VectorDBMemory(AgentMemory):+ r"""An agent memory wrapper of :obj:`VectorDBBlock`. This memory queries+ messages stored in the vector database. Notice that the most recent+ messages will not be added to the context.++ Args:+ context_creator (BaseContextCreator): A model context creator.+ storage (BaseVectorStorage, optional): A vector storage storage. If+ `None`, an :obj:`QdrantStorage` will be used.+ (default: :obj:`None`)+ retrieve_limit (int, optional): The maximum number of messages+ to be added into the context. (default: :obj:`3`)+ """++ def __init__(+ self,+ context_creator: BaseContextCreator,+ storage: Optional[BaseVectorStorage] = None,+ retrieve_limit: int = 3,+ ) -> None:+ self._context_creator = context_creator+ self._retrieve_limit = retrieve_limit+ self._vectordb_block = VectorDBBlock(storage=storage)++ self._current_topic: str = ""++ def retrieve(self) -> List[ContextRecord]:+ return self._vectordb_block.retrieve(+ self._current_topic,+ limit=self._retrieve_limit,+ )++ def write_records(self, records: List[MemoryRecord]) -> None:+ # Assume the last user input is the current topic.+ for record in records:+ if record.role_at_backend == OpenAIBackendRole.USER:+ self._current_topic = record.message.content+ self._vectordb_block.write_records(records)++ def get_context_creator(self) -> BaseContextCreator:+ return self._context_creator+++class LongtermAgentMemory(AgentMemory):+ r"""An implementation of the :obj:`AgentMemory` abstract base class for+ augumenting ChatHistoryMemory with VectorDBMemory.+ """++ def __init__(+ self,+ context_creator: BaseContextCreator,+ chat_history_block: Optional[ChatHistoryBlock] = None,+ vector_db_block: Optional[VectorDBBlock] = None,+ retrieve_limit: int = 3,+ ) -> None:+ self.chat_history_block = chat_history_block or ChatHistoryBlock()+ self.vector_db_block = vector_db_block or VectorDBBlock()+ self.retrieve_limit = retrieve_limit+ self._context_creator = context_creator+ self._current_topic: str = ""++ def get_context_creator(self) -> BaseContextCreator:+ return self._context_creator++ def retrieve(self) -> List[ContextRecord]:+ chat_history = self.chat_history_block.retrieve()+ vector_db_retrieve = self.vector_db_block.retrieve(+ self._current_topic, self.retrieve_limit)+ return chat_history[:1] + vector_db_retrieve + chat_history[1:]++ def write_records(self, records: List[MemoryRecord]) -> None:+ r"""Converts the provided chat messages into vector representations and+ writes them to the vector database.++ Args:+ records (List[MemoryRecord]): Messages to be added to the vector+ database.+ """+ self.vector_db_block.write_records(records)+ self.chat_history_block.write_records(records)++ for record in records:+ if record.role_at_backend == OpenAIBackendRole.USER:+ self._current_topic = record.message.content++ def clear(self) -> None:+ r"""Removes all records from the memory."""+ self.chat_history_block.clear()+ self.vector_db_block.clear()diff --git a/camel/memories/base.py b/camel/memories/base.pyindex dd5bf72b5..ee693d64f 100644--- a/camel/memories/base.py+++ b/camel/memories/base.py@@ -15,42 +15,19 @@from abc import ABC, abstractmethodfrom typing import List, Tuple-from camel.memories import MemoryRecord+from camel.memories import ContextRecord, MemoryRecordfrom camel.messages import OpenAIMessage+from camel.utils import BaseTokenCounter-class BaseMemory(ABC):- r"""An abstract base class that defines the foundational operations for a- memory component within an agent's memory system.-- The memory component is tasked with functions like saving chat histories,- fetching or storing information in vector databases, and other related- operations. Every memory system should incorporate at least one instance of- a subclass derived from :obj:`BaseMemory`.-- These instances, known as "memories", typically communicate using the- :obj:`MemoryRecord` object. Usually, a memory has at least one "storage"- mechanism, allowing it to interface with various storage systems, such as- disks or vector databases. Additionally, some memories might embed other- memory instances, enabling them to function as a high-level controller- within the broader memory system.-- By default, when executing the :obj:`step()` method, an agent retrieves- messages from its designated memory and combines them with an incoming- message for input to the agent. Subsequently, both the response message and- the incoming messages are archived back into the memory.+class MemoryBlock(ABC):+ r"""An abstract class serves as the fundamental component within the agent+ memory system. This class is equipped with "write" and "clear" functions.+ However, it intentionally does not define a retrieval interface, as the+ structure of the data to be retrieved may vary in different types of+ memory blocks."""- @abstractmethod- def get_context(self) -> Tuple[List[OpenAIMessage], int]:- r"""Gets chat context with a proper size for the agent.-- Returns:- (List[OpenAIMessage], int): A tuple containing the constructed- context in OpenAIMessage format and the total token count.- """- pass-@abstractmethoddef write_records(self, records: List[MemoryRecord]) -> None:r"""Writes records to the memory, appending them to existing ones.@@ -70,6 +47,94 @@ class BaseMemory(ABC):@abstractmethoddef clear(self) -> None:- r"""Clears all messages from the memory.+ r"""Clears all messages from the memory."""+ pass+++class BaseContextCreator(ABC):+ r"""An abstract base class defining the interface for context creation+ strategies.++ This class provides a foundational structure for different strategies to+ generate conversational context from a list of context records. The+ primary goal is to create a context that is aligned with a specified token+ count limit, allowing subclasses to define their specific approach.++ Subclasses should implement the :obj:`token_counter`,:obj: `token_limit`,+ and :obj:`create_context` methods to provide specific context creation+ logic.++ Attributes:+ token_counter (BaseTokenCounter): A token counter instance responsible+ for counting tokens in a message.+ token_limit (int): The maximum number of tokens allowed in the+ generated context.+ """++ @property+ @abstractmethod+ def token_counter(self) -> BaseTokenCounter:+ pass++ @property+ @abstractmethod+ def token_limit(self) -> int:+ pass++ @abstractmethod+ def create_context(+ self,+ records: List[ContextRecord],+ ) -> Tuple[List[OpenAIMessage], int]:+ r"""An abstract method to create conversational context from the chat+ history.++ Constructs the context from provided records. The specifics of how this+ is done and how the token count is managed should be provided by+ subclasses implementing this method. The output messages order+ should keep same as the input order.++ Args:+ records (List[ContextRecord]): A list of context records from+ which to generate the context.++ Returns:+ Tuple[List[OpenAIMessage], int]: A tuple containing the constructed+ context in OpenAIMessage format and the total token count.+ """+ pass+++class AgentMemory(MemoryBlock, ABC):+ r"""Represents a specialized form of `MemoryBlock`, uniquely designed for+ direct integration with an agent. Two key abstract functions, "retrieve"+ and "get_context_creator", are used for generating model context based on+ the memory records stored within the AgentMemory.+ """++ @abstractmethod+ def retrieve(self) -> List[ContextRecord]:+ r"""Get a record list from the memory for creating model context.++ Returns:+ List[ContextRecord]: A record list for creating model context."""pass++ @abstractmethod+ def get_context_creator(self) -> BaseContextCreator:+ r"""Gets context creator.++ Returns:+ BaseContextCreator: A model context creator.+ """+ pass++ def get_context(self) -> Tuple[List[OpenAIMessage], int]:+ r"""Gets chat context with a proper size for the agent from the memory.++ Returns:+ (List[OpenAIMessage], int): A tuple containing the constructed+ context in OpenAIMessage format and the total token count.+ """+ return self.get_context_creator().create_context(self.retrieve())diff --git a/camel/memories/blocks/__init__.py b/camel/memories/blocks/__init__.pynew file mode 100644index 000000000..4202a2bba--- /dev/null+++ b/camel/memories/blocks/__init__.py@@ -0,0 +1,21 @@+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+# Licensed under the Apache License, Version 2.0 (the āLicenseā);+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an āAS ISā BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========++from .chat_history_block import ChatHistoryBlock+from .vectordb_block import VectorDBBlock++__all__ = [+ 'ChatHistoryBlock',+ 'VectorDBBlock',+]diff --git a/camel/memories/chat_history_memory.py b/camel/memories/blocks/chat_history_block.pysimilarity index 61%rename from camel/memories/chat_history_memory.pyrename to camel/memories/blocks/chat_history_block.pyindex 37f7a866c..69652253d 100644--- a/camel/memories/chat_history_memory.py+++ b/camel/memories/blocks/chat_history_block.py@@ -11,68 +11,68 @@# See the License for the specific language governing permissions and# limitations under the License.# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========-from typing import List, Optional, Tuple+import warnings+from typing import List, Optional-from camel.memories import BaseMemory, ContextRecord, MemoryRecord-from camel.memories.context_creators import BaseContextCreator-from camel.messages import OpenAIMessage+from camel.memories import ContextRecord, MemoryBlock, MemoryRecordfrom camel.storages import BaseKeyValueStorage, InMemoryKeyValueStoragefrom camel.types import OpenAIBackendRole-class ChatHistoryMemory(BaseMemory):- r"""An implementation of the :obj:`BaseMemory` abstract base class for+class ChatHistoryBlock(MemoryBlock):+ r"""An implementation of the :obj:`MemoryBlock` abstract base class formaintaining a record of chat histories.- This memory class helps manage conversation histories with a designated- storage mechanism, either provided by the user or using a default+ This memory block helps manage conversation histories with a key-value+ storage backend, either provided by the user or using a defaultin-memory storage. It offers a windowed approach to retrieving chathistories, allowing users to specify how many recent messages they'dlike to fetch.- `ChatHistoryMemory` requires messages to be stored with certain- metadata (e.g., `role_at_backend`) to maintain consistency and validate- the chat history.-Args:- context_creator (BaseContextCreator): A context creator contianing- the context limit and the message pruning strategy.storage (BaseKeyValueStorage, optional): A storage mechanism forstoring chat history. If `None`, an :obj:`InMemoryKeyValueStorage`will be used. (default: :obj:`None`)- window_size (int, optional): Specifies the number of recent chat- messages to retrieve. If not provided, the entire chat history- will be retrieved. (default: :obj:`None`)+ keep_rate (float, optional): In historical messages, the score of the+ last message is 1.0, and with each step taken backward, the score+ of the message is multiplied by the `keep_rate`. Higher `keep_rate`+ leads to high possiblity to keep history messages during context+ creation."""def __init__(self,- context_creator: BaseContextCreator,storage: Optional[BaseKeyValueStorage] = None,- window_size: Optional[int] = None,+ keep_rate: float = 0.9,) -> None:- self.context_creator = context_creator+ if keep_rate > 1 or keep_rate < 0:+ raise ValueError("`keep_rate` should be in [0,1]")self.storage = storage or InMemoryKeyValueStorage()- self.window_size = window_size+ self.keep_rate = keep_rate- def get_context(self) -> Tuple[List[OpenAIMessage], int]:- r"""Gets chat context with a proper size for the agent from the memory+ def retrieve(+ self,+ window_size: Optional[int] = None,+ ) -> List[ContextRecord]:+ r"""Retrieves records with a proper size for the agent from the memorybased on the window size or fetches the entire chat history if nowindow size is specified.+ Args:+ window_size (int, optional): Specifies the number of recent chat+ messages to retrieve. If not provided, the entire chat history+ will be retrieved. (default: :obj:`None`)+Returns:- (List[OpenAIMessage], int): A tuple containing the constructed- context in OpenAIMessage format and the total token count.- Raises:- ValueError: If the memory is empty or if the first message in the- memory is not a system message.+ List[ContextRecord]: A list of retrieved records."""record_dicts = self.storage.load()if len(record_dicts) == 0:- raise ValueError("The `ChatHistoryMemory` is empty.")+ warnings.warn("The `ChatHistoryMemory` is empty.")+ return list()chat_records: List[MemoryRecord] = []- truncate_idx = -self.window_size if self.window_size is not None else 0+ truncate_idx = -window_size if window_size is not None else 0for record_dict in record_dicts[truncate_idx:]:chat_records.append(MemoryRecord.from_dict(record_dict))@@ -86,11 +86,11 @@ class ChatHistoryMemory(BaseMemory):output_records.append(ContextRecord(record, 1.0))else:# Other messages' score drops down gradually- score *= 0.99+ score *= self.keep_rateoutput_records.append(ContextRecord(record, score))output_records.reverse()- return self.context_creator.create_context(output_records)+ return output_recordsdef write_records(self, records: List[MemoryRecord]) -> None:r"""Writes memory records to the memory. Additionally, performs@@ -106,6 +106,5 @@ class ChatHistoryMemory(BaseMemory):self.storage.save(stored_records)def clear(self) -> None:- r"""Clears all chat messages from the memory.- """+ r"""Clears all chat messages from the memory."""self.storage.clear()diff --git a/camel/memories/blocks/vectordb_block.py b/camel/memories/blocks/vectordb_block.pynew file mode 100644index 000000000..9981e7582--- /dev/null+++ b/camel/memories/blocks/vectordb_block.py@@ -0,0 +1,97 @@+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+# Licensed under the Apache License, Version 2.0 (the āLicenseā);+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an āAS ISā BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========++from typing import List, Optional++from camel.embeddings import BaseEmbedding, OpenAIEmbedding+from camel.memories import ContextRecord, MemoryBlock, MemoryRecord+from camel.storages.vectordb_storages import (+ BaseVectorStorage,+ QdrantStorage,+ VectorDBQuery,+ VectorRecord,+)+++class VectorDBBlock(MemoryBlock):+ r"""An implementation of the :obj:`MemoryBlock` abstract base class for+ maintaining and retrieving information using vector embeddings within a+ vector database.++ Args:+ storage (Optional[BaseVectorStorage], optional): The storage mechanism+ for the vector database. Defaults to in-memory :obj:`Qdrant` if not+ provided. (default: :obj:`None`)+ embedding (Optional[BaseEmbedding], optional): Embedding mechanism to+ convert chat messages into vector representations. Defaults to+ :obj:`OpenAiEmbedding` if not provided. (default: :obj:`None`)+ """++ def __init__(+ self,+ storage: Optional[BaseVectorStorage] = None,+ embedding: Optional[BaseEmbedding] = None,+ ) -> None:+ self.embedding = embedding or OpenAIEmbedding()+ self.vector_dim = self.embedding.get_output_dim()+ self.storage = storage or QdrantStorage(vector_dim=self.vector_dim)++ def retrieve(+ self,+ keyword: str,+ limit: int = 3,+ ) -> List[ContextRecord]:+ r"""Retrieves similar records from the vector database based on the+ content of the keyword.++ Args:+ keyword (str): This string will be converted into a vector+ representation to query the database.+ limit (int, optional): The maximum number of similar messages to+ retrieve. (default: :obj:`3`).++ Returns:+ List[ContextRecord]: A list of memory records retrieved from the+ vector database based on similarity to :obj:`current_state`.+ """+ query_vector = self.embedding.embed(keyword)+ results = self.storage.query(VectorDBQuery(query_vector, top_k=limit))+ return [+ ContextRecord(+ memory_record=MemoryRecord.from_dict(result.record.payload),+ score=result.similarity,+ ) for result in results if result.record.payload is not None+ ]++ def write_records(self, records: List[MemoryRecord]) -> None:+ """+ Converts the provided chat messages into vector representations and+ writes them to the vector database.++ Args:+ records (List[MemoryRecord]): Memory records to be added to the+ memory.+ """+ v_records = [+ VectorRecord(+ vector=self.embedding.embed(record.message.content),+ payload=record.to_dict(),+ id=str(record.uuid),+ ) for record in records+ ]+ self.storage.add(v_records)++ def clear(self) -> None:+ r"""Removes all records from the vector database memory."""+ self.storage.clear()diff --git a/camel/memories/context_creators/__init__.py b/camel/memories/context_creators/__init__.pyindex 5b1db8e27..8608415fc 100644--- a/camel/memories/context_creators/__init__.py+++ b/camel/memories/context_creators/__init__.py@@ -12,7 +12,8 @@# limitations under the License.# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========-from .base import BaseContextCreatorfrom .score_based import ScoreBasedContextCreator-__all__ = ['BaseContextCreator', 'ScoreBasedContextCreator']+__all__ = [+ 'ScoreBasedContextCreator',+]diff --git a/camel/memories/context_creators/base.py b/camel/memories/context_creators/base.pydeleted file mode 100644index cdc6046b2..000000000--- a/camel/memories/context_creators/base.py+++ /dev/null@@ -1,72 +0,0 @@-# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========-# Licensed under the Apache License, Version 2.0 (the āLicenseā);-# you may not use this file except in compliance with the License.-# You may obtain a copy of the License at-#-# http://www.apache.org/licenses/LICENSE-2.0-#-# Unless required by applicable law or agreed to in writing, software-# distributed under the License is distributed on an āAS ISā BASIS,-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.-# See the License for the specific language governing permissions and-# limitations under the License.-# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========-from abc import ABC, abstractmethod-from typing import List, Tuple--from camel.memories import ContextRecord-from camel.messages import OpenAIMessage-from camel.utils import BaseTokenCounter---class BaseContextCreator(ABC):- r"""An abstract base class defining the interface for context creation- strategies.-- This class provides a foundational structure for different strategies to- generate conversational context from a list of context records. The- primary goal is to create a context that is aligned with a specified token- count limit, allowing subclasses to define their specific approach.-- Subclasses should implement the `token_counter`, `token_limit`, and- `create_context` methods to provide specific context creation logic.-- Attributes:- token_counter (BaseTokenCounter): A token counter instance responsible- for counting tokens in a message.- token_limit (int): The maximum number of tokens allowed in the- generated context.- """-- @property- @abstractmethod- def token_counter(self) -> BaseTokenCounter:- pass-- @property- @abstractmethod- def token_limit(self) -> int:- pass-- @abstractmethod- def create_context(- self,- records: List[ContextRecord],- ) -> Tuple[List[OpenAIMessage], int]:- r"""An abstract method to create conversational context from the chat- history.-- Constructs the context from provided records. The specifics of how this- is done and how the token count is managed should be provided by- subclasses implementing this method. The the output messages order- should keep same as the input order.-- Args:- records (List[ContextRecord]): A list of context records from- which to generate the context.-- Returns:- Tuple[List[OpenAIMessage], int]: A tuple containing the constructed- context in OpenAIMessage format and the total token count.- """- passdiff --git a/camel/memories/context_creators/score_based.py b/camel/memories/context_creators/score_based.pyindex 70be64bdb..b892311ed 100644--- a/camel/memories/context_creators/score_based.py+++ b/camel/memories/context_creators/score_based.py@@ -14,8 +14,7 @@from dataclasses import dataclassfrom typing import List, Tuple-from camel.memories import ContextRecord-from camel.memories.context_creators import BaseContextCreator+from camel.memories import BaseContextCreator, ContextRecordfrom camel.messages import OpenAIMessagefrom camel.utils import BaseTokenCounter@@ -79,14 +78,20 @@ class ScoreBasedContextCreator(BaseContextCreator):RuntimeError: If it's impossible to create a valid context withoutexceeding the token limit."""- context_units = [- _ContextUnit(- idx,- record,- self.token_counter.count_tokens_from_messages(- [record.memory_record.to_openai_message()]),- ) for idx, record in enumerate(records)- ]+ # Create unique context units list+ uuid_set = set()+ context_units = []+ for idx, record in enumerate(records):+ if record.memory_record.uuid not in uuid_set:+ uuid_set.add(record.memory_record.uuid)+ context_units.append(+ _ContextUnit(+ idx,+ record,+ self.token_counter.count_tokens_from_messages(+ [record.memory_record.to_openai_message()]),+ ))+# TODO: optimize the process, may give information back to memory# If not exceed token limit, simply returndiff --git a/camel/memories/records.py b/camel/memories/records.pyindex ad4a2be5e..a40f32801 100644--- a/camel/memories/records.py+++ b/camel/memories/records.py@@ -86,7 +86,6 @@ class MemoryRecord:@dataclass(frozen=True)class ContextRecord:- r"""The result of memory retrieving.- """+ r"""The result of memory retrieving."""memory_record: MemoryRecordscore: floatdiff --git a/poetry.lock b/poetry.lockindex fb6fd0a4d..33de4272c 100644--- a/poetry.lock+++ b/poetry.lock@@ -1,4 +1,4 @@-# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand.+# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.[[package]]name = "accelerate"@@ -178,13 +178,13 @@ files = [[[package]]name = "altair"-version = "5.2.0"+version = "5.3.0"description = "Vega-Altair: A declarative statistical visualization library for Python."optional = falsepython-versions = ">=3.8"files = [- {file = "altair-5.2.0-py3-none-any.whl", hash = "sha256:8c4888ad11db7c39f3f17aa7f4ea985775da389d79ac30a6c22856ab238df399"},- {file = "altair-5.2.0.tar.gz", hash = "sha256:2ad7f0c8010ebbc46319cc30febfb8e59ccf84969a201541c207bc3a4fa6cf81"},+ {file = "altair-5.3.0-py3-none-any.whl", hash = "sha256:7084a1dab4d83c5e7e5246b92dc1b4451a6c68fd057f3716ee9d315c8980e59a"},+ {file = "altair-5.3.0.tar.gz", hash = "sha256:5a268b1a0983b23d8f9129f819f956174aa7aea2719ed55a52eba9979b9f6675"},][package.dependencies]@@ -197,7 +197,8 @@ toolz = "*"typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""}[package.extras]-dev = ["anywidget", "geopandas", "hatch", "ipython", "m2r", "mypy", "pandas-stubs", "pyarrow (>=11)", "pytest", "pytest-cov", "ruff (>=0.1.3)", "types-jsonschema", "types-setuptools", "vega-datasets", "vegafusion[embed] (>=1.4.0)", "vl-convert-python (>=1.1.0)"]+all = ["altair-tiles (>=0.3.0)", "anywidget (>=0.9.0)", "pyarrow (>=11)", "vega-datasets (>=0.9.0)", "vegafusion[embed] (>=1.6.6)", "vl-convert-python (>=1.3.0)"]+dev = ["geopandas", "hatch", "ipython", "m2r", "mypy", "pandas-stubs", "pytest", "pytest-cov", "ruff (>=0.3.0)", "types-jsonschema", "types-setuptools"]doc = ["docutils", "jinja2", "myst-parser", "numpydoc", "pillow (>=9,<10)", "pydata-sphinx-theme (>=0.14.1)", "scipy", "sphinx", "sphinx-copybutton", "sphinx-design", "sphinxext-altair"][[package]]@@ -1689,13 +1690,13 @@ socks = ["socksio (==1.*)"][[package]]name = "huggingface-hub"-version = "0.22.1"+version = "0.22.2"description = "Client library to download and publish models, datasets and other repos on the huggingface.co hub"optional = falsepython-versions = ">=3.8.0"files = [- {file = "huggingface_hub-0.22.1-py3-none-any.whl", hash = "sha256:eac63947923d15c9a68681d7ed2d9599e058860617064e3ee6bd91a4b954faaf"},- {file = "huggingface_hub-0.22.1.tar.gz", hash = "sha256:5b8aaee5f3618cd432f49886da9935bbe8fab92d719011826430907b93171dd8"},+ {file = "huggingface_hub-0.22.2-py3-none-any.whl", hash = "sha256:3429e25f38ccb834d310804a3b711e7e4953db5a9e420cc147a5e194ca90fd17"},+ {file = "huggingface_hub-0.22.2.tar.gz", hash = "sha256:32e9a9a6843c92f253ff9ca16b9985def4d80a93fb357af5353f770ef74a81be"},][package.dependencies]@@ -2108,96 +2109,132 @@ tesseract = ["pytesseract"][[package]]name = "lxml"-version = "5.1.0"+version = "5.2.0"description = "Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API."optional = truepython-versions = ">=3.6"files = [- {file = "lxml-5.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:704f5572ff473a5f897745abebc6df40f22d4133c1e0a1f124e4f2bd3330ff7e"},- {file = "lxml-5.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:9d3c0f8567ffe7502d969c2c1b809892dc793b5d0665f602aad19895f8d508da"},- {file = "lxml-5.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:5fcfbebdb0c5d8d18b84118842f31965d59ee3e66996ac842e21f957eb76138c"},- {file = "lxml-5.1.0-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2f37c6d7106a9d6f0708d4e164b707037b7380fcd0b04c5bd9cae1fb46a856fb"},- {file = "lxml-5.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2befa20a13f1a75c751f47e00929fb3433d67eb9923c2c0b364de449121f447c"},- {file = "lxml-5.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:22b7ee4c35f374e2c20337a95502057964d7e35b996b1c667b5c65c567d2252a"},- {file = "lxml-5.1.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:bf8443781533b8d37b295016a4b53c1494fa9a03573c09ca5104550c138d5c05"},- {file = "lxml-5.1.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:82bddf0e72cb2af3cbba7cec1d2fd11fda0de6be8f4492223d4a268713ef2147"},- {file = "lxml-5.1.0-cp310-cp310-win32.whl", hash = "sha256:b66aa6357b265670bb574f050ffceefb98549c721cf28351b748be1ef9577d93"},- {file = "lxml-5.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:4946e7f59b7b6a9e27bef34422f645e9a368cb2be11bf1ef3cafc39a1f6ba68d"},- {file = "lxml-5.1.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:14deca1460b4b0f6b01f1ddc9557704e8b365f55c63070463f6c18619ebf964f"},- {file = "lxml-5.1.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ed8c3d2cd329bf779b7ed38db176738f3f8be637bb395ce9629fc76f78afe3d4"},- {file = "lxml-5.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:436a943c2900bb98123b06437cdd30580a61340fbdb7b28aaf345a459c19046a"},- {file = "lxml-5.1.0-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:acb6b2f96f60f70e7f34efe0c3ea34ca63f19ca63ce90019c6cbca6b676e81fa"},- {file = "lxml-5.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:af8920ce4a55ff41167ddbc20077f5698c2e710ad3353d32a07d3264f3a2021e"},- {file = "lxml-5.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7cfced4a069003d8913408e10ca8ed092c49a7f6cefee9bb74b6b3e860683b45"},- {file = "lxml-5.1.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:9e5ac3437746189a9b4121db2a7b86056ac8786b12e88838696899328fc44bb2"},- {file = "lxml-5.1.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:f4c9bda132ad108b387c33fabfea47866af87f4ea6ffb79418004f0521e63204"},- {file = "lxml-5.1.0-cp311-cp311-win32.whl", hash = "sha256:bc64d1b1dab08f679fb89c368f4c05693f58a9faf744c4d390d7ed1d8223869b"},- {file = "lxml-5.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:a5ab722ae5a873d8dcee1f5f45ddd93c34210aed44ff2dc643b5025981908cda"},- {file = "lxml-5.1.0-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:9aa543980ab1fbf1720969af1d99095a548ea42e00361e727c58a40832439114"},- {file = "lxml-5.1.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:6f11b77ec0979f7e4dc5ae081325a2946f1fe424148d3945f943ceaede98adb8"},- {file = "lxml-5.1.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a36c506e5f8aeb40680491d39ed94670487ce6614b9d27cabe45d94cd5d63e1e"},- {file = "lxml-5.1.0-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f643ffd2669ffd4b5a3e9b41c909b72b2a1d5e4915da90a77e119b8d48ce867a"},- {file = "lxml-5.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:16dd953fb719f0ffc5bc067428fc9e88f599e15723a85618c45847c96f11f431"},- {file = "lxml-5.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:16018f7099245157564d7148165132c70adb272fb5a17c048ba70d9cc542a1a1"},- {file = "lxml-5.1.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:82cd34f1081ae4ea2ede3d52f71b7be313756e99b4b5f829f89b12da552d3aa3"},- {file = "lxml-5.1.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:19a1bc898ae9f06bccb7c3e1dfd73897ecbbd2c96afe9095a6026016e5ca97b8"},- {file = "lxml-5.1.0-cp312-cp312-win32.whl", hash = "sha256:13521a321a25c641b9ea127ef478b580b5ec82aa2e9fc076c86169d161798b01"},- {file = "lxml-5.1.0-cp312-cp312-win_amd64.whl", hash = "sha256:1ad17c20e3666c035db502c78b86e58ff6b5991906e55bdbef94977700c72623"},- {file = "lxml-5.1.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:24ef5a4631c0b6cceaf2dbca21687e29725b7c4e171f33a8f8ce23c12558ded1"},- {file = "lxml-5.1.0-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8d2900b7f5318bc7ad8631d3d40190b95ef2aa8cc59473b73b294e4a55e9f30f"},- {file = "lxml-5.1.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:601f4a75797d7a770daed8b42b97cd1bb1ba18bd51a9382077a6a247a12aa38d"},- {file = "lxml-5.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b4b68c961b5cc402cbd99cca5eb2547e46ce77260eb705f4d117fd9c3f932b95"},- {file = "lxml-5.1.0-cp36-cp36m-musllinux_1_1_aarch64.whl", hash = "sha256:afd825e30f8d1f521713a5669b63657bcfe5980a916c95855060048b88e1adb7"},- {file = "lxml-5.1.0-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:262bc5f512a66b527d026518507e78c2f9c2bd9eb5c8aeeb9f0eb43fcb69dc67"},- {file = "lxml-5.1.0-cp36-cp36m-win32.whl", hash = "sha256:e856c1c7255c739434489ec9c8aa9cdf5179785d10ff20add308b5d673bed5cd"},- {file = "lxml-5.1.0-cp36-cp36m-win_amd64.whl", hash = "sha256:c7257171bb8d4432fe9d6fdde4d55fdbe663a63636a17f7f9aaba9bcb3153ad7"},- {file = "lxml-5.1.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b9e240ae0ba96477682aa87899d94ddec1cc7926f9df29b1dd57b39e797d5ab5"},- {file = "lxml-5.1.0-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a96f02ba1bcd330807fc060ed91d1f7a20853da6dd449e5da4b09bfcc08fdcf5"},- {file = "lxml-5.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3e3898ae2b58eeafedfe99e542a17859017d72d7f6a63de0f04f99c2cb125936"},- {file = "lxml-5.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61c5a7edbd7c695e54fca029ceb351fc45cd8860119a0f83e48be44e1c464862"},- {file = "lxml-5.1.0-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:3aeca824b38ca78d9ee2ab82bd9883083d0492d9d17df065ba3b94e88e4d7ee6"},- {file = "lxml-5.1.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:8f52fe6859b9db71ee609b0c0a70fea5f1e71c3462ecf144ca800d3f434f0764"},- {file = "lxml-5.1.0-cp37-cp37m-win32.whl", hash = "sha256:d42e3a3fc18acc88b838efded0e6ec3edf3e328a58c68fbd36a7263a874906c8"},- {file = "lxml-5.1.0-cp37-cp37m-win_amd64.whl", hash = "sha256:eac68f96539b32fce2c9b47eb7c25bb2582bdaf1bbb360d25f564ee9e04c542b"},- {file = "lxml-5.1.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:ae15347a88cf8af0949a9872b57a320d2605ae069bcdf047677318bc0bba45b1"},- {file = "lxml-5.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:c26aab6ea9c54d3bed716b8851c8bfc40cb249b8e9880e250d1eddde9f709bf5"},- {file = "lxml-5.1.0-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:342e95bddec3a698ac24378d61996b3ee5ba9acfeb253986002ac53c9a5f6f84"},- {file = "lxml-5.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:725e171e0b99a66ec8605ac77fa12239dbe061482ac854d25720e2294652eeaa"},- {file = "lxml-5.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3d184e0d5c918cff04cdde9dbdf9600e960161d773666958c9d7b565ccc60c45"},- {file = "lxml-5.1.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:98f3f020a2b736566c707c8e034945c02aa94e124c24f77ca097c446f81b01f1"},- {file = "lxml-5.1.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:6d48fc57e7c1e3df57be5ae8614bab6d4e7b60f65c5457915c26892c41afc59e"},- {file = "lxml-5.1.0-cp38-cp38-win32.whl", hash = "sha256:7ec465e6549ed97e9f1e5ed51c657c9ede767bc1c11552f7f4d022c4df4a977a"},- {file = "lxml-5.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:b21b4031b53d25b0858d4e124f2f9131ffc1530431c6d1321805c90da78388d1"},- {file = "lxml-5.1.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:52427a7eadc98f9e62cb1368a5079ae826f94f05755d2d567d93ee1bc3ceb354"},- {file = "lxml-5.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:6a2a2c724d97c1eb8cf966b16ca2915566a4904b9aad2ed9a09c748ffe14f969"},- {file = "lxml-5.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:843b9c835580d52828d8f69ea4302537337a21e6b4f1ec711a52241ba4a824f3"},- {file = "lxml-5.1.0-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9b99f564659cfa704a2dd82d0684207b1aadf7d02d33e54845f9fc78e06b7581"},- {file = "lxml-5.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4f8b0c78e7aac24979ef09b7f50da871c2de2def043d468c4b41f512d831e912"},- {file = "lxml-5.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9bcf86dfc8ff3e992fed847c077bd875d9e0ba2fa25d859c3a0f0f76f07f0c8d"},- {file = "lxml-5.1.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:49a9b4af45e8b925e1cd6f3b15bbba2c81e7dba6dce170c677c9cda547411e14"},- {file = "lxml-5.1.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:280f3edf15c2a967d923bcfb1f8f15337ad36f93525828b40a0f9d6c2ad24890"},- {file = "lxml-5.1.0-cp39-cp39-win32.whl", hash = "sha256:ed7326563024b6e91fef6b6c7a1a2ff0a71b97793ac33dbbcf38f6005e51ff6e"},- {file = "lxml-5.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:8d7b4beebb178e9183138f552238f7e6613162a42164233e2bda00cb3afac58f"},- {file = "lxml-5.1.0-pp310-pypy310_pp73-macosx_10_9_x86_64.whl", hash = "sha256:9bd0ae7cc2b85320abd5e0abad5ccee5564ed5f0cc90245d2f9a8ef330a8deae"},- {file = "lxml-5.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d8c1d679df4361408b628f42b26a5d62bd3e9ba7f0c0e7969f925021554755aa"},- {file = "lxml-5.1.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:2ad3a8ce9e8a767131061a22cd28fdffa3cd2dc193f399ff7b81777f3520e372"},- {file = "lxml-5.1.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl", hash = "sha256:304128394c9c22b6569eba2a6d98392b56fbdfbad58f83ea702530be80d0f9df"},- {file = "lxml-5.1.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d74fcaf87132ffc0447b3c685a9f862ffb5b43e70ea6beec2fb8057d5d2a1fea"},- {file = "lxml-5.1.0-pp37-pypy37_pp73-win_amd64.whl", hash = "sha256:8cf5877f7ed384dabfdcc37922c3191bf27e55b498fecece9fd5c2c7aaa34c33"},- {file = "lxml-5.1.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:877efb968c3d7eb2dad540b6cabf2f1d3c0fbf4b2d309a3c141f79c7e0061324"},- {file = "lxml-5.1.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3f14a4fb1c1c402a22e6a341a24c1341b4a3def81b41cd354386dcb795f83897"},- {file = "lxml-5.1.0-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:25663d6e99659544ee8fe1b89b1a8c0aaa5e34b103fab124b17fa958c4a324a6"},- {file = "lxml-5.1.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:8b9f19df998761babaa7f09e6bc169294eefafd6149aaa272081cbddc7ba4ca3"},- {file = "lxml-5.1.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5e53d7e6a98b64fe54775d23a7c669763451340c3d44ad5e3a3b48a1efbdc96f"},- {file = "lxml-5.1.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:c3cd1fc1dc7c376c54440aeaaa0dcc803d2126732ff5c6b68ccd619f2e64be4f"},- {file = "lxml-5.1.0.tar.gz", hash = "sha256:3eea6ed6e6c918e468e693c41ef07f3c3acc310b70ddd9cc72d9ef84bc9564ca"},+ {file = "lxml-5.2.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:c54f8d6160080831a76780d850302fdeb0e8d0806f661777b0714dfb55d9a08a"},+ {file = "lxml-5.2.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:0e95ae029396382a0d2e8174e4077f96befcd4a2184678db363ddc074eb4d3b2"},+ {file = "lxml-5.2.0-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5810fa80e64a0c689262a71af999c5735f48c0da0affcbc9041d1ef5ef3920be"},+ {file = "lxml-5.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ae69524fd6a68b288574013f8fadac23cacf089c75cd3fc5b216277a445eb736"},+ {file = "lxml-5.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fadda215e32fe375d65e560b7f7e2a37c7f9c4ecee5315bb1225ca6ac9bf5838"},+ {file = "lxml-5.2.0-cp310-cp310-manylinux_2_28_aarch64.whl", hash = "sha256:f1f164e4cc6bc646b1fc86664c3543bf4a941d45235797279b120dc740ee7af5"},+ {file = "lxml-5.2.0-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:3603a8a41097daf7672cae22cc4a860ab9ea5597f1c5371cb21beca3398b8d6a"},+ {file = "lxml-5.2.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:b3b4bb89a785f4fd60e05f3c3a526c07d0d68e3536f17f169ca13bf5b5dd75a5"},+ {file = "lxml-5.2.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:1effc10bf782f0696e76ecfeba0720ea02c0c31d5bffb7b29ba10debd57d1c3d"},+ {file = "lxml-5.2.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:b03531f6cd6ce4b511dcece060ca20aa5412f8db449274b44f4003f282e6272f"},+ {file = "lxml-5.2.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:7fac15090bb966719df06f0c4f8139783746d1e60e71016d8a65db2031ca41b8"},+ {file = "lxml-5.2.0-cp310-cp310-win32.whl", hash = "sha256:92bb37c96215c4b2eb26f3c791c0bf02c64dd251effa532b43ca5049000c4478"},+ {file = "lxml-5.2.0-cp310-cp310-win_amd64.whl", hash = "sha256:b0181c22fdb89cc19e70240a850e5480817c3e815b1eceb171b3d7a3aa3e596a"},+ {file = "lxml-5.2.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:ada8ce9e6e1d126ef60d215baaa0c81381ba5841c25f1d00a71cdafdc038bd27"},+ {file = "lxml-5.2.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:3cefb133c859f06dab2ae63885d9f405000c4031ec516e0ed4f9d779f690d8e3"},+ {file = "lxml-5.2.0-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1ede2a7a86a977b0c741654efaeca0af7860a9b1ae39f9268f0936246a977ee0"},+ {file = "lxml-5.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d46df6f0b1a0cda39d12c5c4615a7d92f40342deb8001c7b434d7c8c78352e58"},+ {file = "lxml-5.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc2259243ee734cc736e237719037efb86603c891fd363cc7973a2d0ac8a0e3f"},+ {file = "lxml-5.2.0-cp311-cp311-manylinux_2_28_aarch64.whl", hash = "sha256:c53164f29ed3c3868787144e8ea8a399ffd7d8215f59500a20173593c19e96eb"},+ {file = "lxml-5.2.0-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:371aab9a397dcc76625ad3b02fa9b21be63406d69237b773156e7d1fc2ce0cae"},+ {file = "lxml-5.2.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:e08784288a179b59115b5e57abf6d387528b39abb61105fe17510a199a277a40"},+ {file = "lxml-5.2.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:4c232726f7b6df5143415a06323faaa998ef8abbe1c0ed00d718755231d76f08"},+ {file = "lxml-5.2.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:e4366e58c0508da4dee4c7c70cee657e38553d73abdffa53abbd7d743711ee11"},+ {file = "lxml-5.2.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:c84dce8fb2e900d4fb094e76fdad34a5fd06de53e41bddc1502c146eb11abd74"},+ {file = "lxml-5.2.0-cp311-cp311-win32.whl", hash = "sha256:0947d1114e337dc2aae2fa14bbc9ed5d9ca1a0acd6d2f948df9926aef65305e9"},+ {file = "lxml-5.2.0-cp311-cp311-win_amd64.whl", hash = "sha256:1eace37a9f4a1bef0bb5c849434933fd6213008ec583c8e31ee5b8e99c7c8500"},+ {file = "lxml-5.2.0-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f2cb157e279d28c66b1c27e0948687dc31dc47d1ab10ce0cd292a8334b7de3d5"},+ {file = "lxml-5.2.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:53c0e56f41ef68c1ce4e96f27ecdc2df389730391a2fd45439eb3facb02d36c8"},+ {file = "lxml-5.2.0-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:703d60e59ab45c17485c2c14b11880e4f7f0eab07134afa9007573fa5a779a5a"},+ {file = "lxml-5.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:eaf5e308a5e50bc0548c4fdca0117a31ec9596f8cfc96592db170bcecc71a957"},+ {file = "lxml-5.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:af64df85fecd3cf3b2e792f0b5b4d92740905adfa8ce3b24977a55415f1a0c40"},+ {file = "lxml-5.2.0-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:df7dfbdef11702fd22c2eaf042d7098d17edbc62d73f2199386ad06cbe466f6d"},+ {file = "lxml-5.2.0-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:7250030a7835bfd5ba6ca7d1ad483ec90f9cbc29978c5e75c1cc3e031d3c4160"},+ {file = "lxml-5.2.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:be5faa2d5c8c8294d770cfd09d119fb27b5589acc59635b0cf90f145dbe81dca"},+ {file = "lxml-5.2.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:347ec08250d5950f5b016caa3e2e13fb2cb9714fe6041d52e3716fb33c208663"},+ {file = "lxml-5.2.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:dc7b630c4fb428b8a40ddd0bfc4bc19de11bb3c9b031154f77360e48fe8b4451"},+ {file = "lxml-5.2.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:ae550cbd7f229cdf2841d9b01406bcca379a5fb327b9efb53ba620a10452e835"},+ {file = "lxml-5.2.0-cp312-cp312-win32.whl", hash = "sha256:7c61ce3cdd6e6c9f4003ac118be7eb3036d0ce2afdf23929e533e54482780f74"},+ {file = "lxml-5.2.0-cp312-cp312-win_amd64.whl", hash = "sha256:f90c36ca95a44d2636bbf55a51ca30583b59b71b6547b88d954e029598043551"},+ {file = "lxml-5.2.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:1cce2eaad7e38b985b0f91f18468dda0d6b91862d32bec945b0e46e2ffe7222e"},+ {file = "lxml-5.2.0-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:60a3983d32f722a8422c01e4dc4badc7a307ca55c59e2485d0e14244a52c482f"},+ {file = "lxml-5.2.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:60847dfbdfddf08a56c4eefe48234e8c1ab756c7eda4a2a7c1042666a5516564"},+ {file = "lxml-5.2.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2bbe335f0d1a86391671d975a1b5e9b08bb72fba6b567c43bdc2e55ca6e6c086"},+ {file = "lxml-5.2.0-cp36-cp36m-manylinux_2_28_aarch64.whl", hash = "sha256:3ac7c8a60b8ad51fe7bca99a634dd625d66492c502fd548dc6dc769ce7d94b6a"},+ {file = "lxml-5.2.0-cp36-cp36m-manylinux_2_28_x86_64.whl", hash = "sha256:73e69762cf740ac3ae81137ef9d6f15f93095f50854e233d50b29e7b8a91dbc6"},+ {file = "lxml-5.2.0-cp36-cp36m-musllinux_1_1_aarch64.whl", hash = "sha256:281ee1ffeb0ab06204dfcd22a90e9003f0bb2dab04101ad983d0b1773bc10588"},+ {file = "lxml-5.2.0-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:ba3a86b0d5a5c93104cb899dff291e3ae13729c389725a876d00ef9696de5425"},+ {file = "lxml-5.2.0-cp36-cp36m-musllinux_1_2_aarch64.whl", hash = "sha256:356f8873b1e27b81793e30144229adf70f6d3e36e5cb7b6d289da690f4398953"},+ {file = "lxml-5.2.0-cp36-cp36m-musllinux_1_2_x86_64.whl", hash = "sha256:2a34e74ffe92c413f197ff4967fb1611d938ee0691b762d062ef0f73814f3aa4"},+ {file = "lxml-5.2.0-cp36-cp36m-win32.whl", hash = "sha256:6f0d2b97a5a06c00c963d4542793f3e486b1ed3a957f8c19f6006ed39d104bb0"},+ {file = "lxml-5.2.0-cp36-cp36m-win_amd64.whl", hash = "sha256:35e39c6fd089ad6674eb52d93aa874d6027b3ae44d2381cca6e9e4c2e102c9c8"},+ {file = "lxml-5.2.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:5f6e4e5a62114ae76690c4a04c5108d067442d0a41fd092e8abd25af1288c450"},+ {file = "lxml-5.2.0-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:93eede9bcc842f891b2267c7f0984d811940d1bc18472898a1187fe560907a99"},+ {file = "lxml-5.2.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2ad364026c2cebacd7e01d1138bd53639822fefa8f7da90fc38cd0e6319a2699"},+ {file = "lxml-5.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3f06e4460e76468d99cc36d5b9bc6fc5f43e6662af44960e13e3f4e040aacb35"},+ {file = "lxml-5.2.0-cp37-cp37m-manylinux_2_28_aarch64.whl", hash = "sha256:ca3236f31d565555139d5b00b790ed2a98ac6f0c4470c4032f8b5e5a5dba3c1a"},+ {file = "lxml-5.2.0-cp37-cp37m-manylinux_2_28_x86_64.whl", hash = "sha256:a9b67b850ab1d304cb706cf71814b0e0c3875287083d7ec55ee69504a9c48180"},+ {file = "lxml-5.2.0-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:5261c858c390ae9a19aba96796948b6a2d56649cbd572968970dc8da2b2b2a42"},+ {file = "lxml-5.2.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:e8359fb610c8c444ac473cfd82dae465f405ff807cabb98a9b9712bbd0028751"},+ {file = "lxml-5.2.0-cp37-cp37m-musllinux_1_2_aarch64.whl", hash = "sha256:f9e27841cddfaebc4e3ffbe5dbdff42891051acf5befc9f5323944b2c61cef16"},+ {file = "lxml-5.2.0-cp37-cp37m-musllinux_1_2_x86_64.whl", hash = "sha256:641a8da145aca67671205f3e89bfec9815138cf2fe06653c909eab42e486d373"},+ {file = "lxml-5.2.0-cp37-cp37m-win32.whl", hash = "sha256:931a3a13e0f574abce8f3152b207938a54304ccf7a6fd7dff1fdb2f6691d08af"},+ {file = "lxml-5.2.0-cp37-cp37m-win_amd64.whl", hash = "sha256:246c93e2503c710cf02c7e9869dc0258223cbefe5e8f9ecded0ac0aa07fd2bf8"},+ {file = "lxml-5.2.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:11acfcdf5a38cf89c48662123a5d02ae0a7d99142c7ee14ad90de5c96a9b6f06"},+ {file = "lxml-5.2.0-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:200f70b5d95fc79eb9ed7f8c4888eef4e274b9bf380b829d3d52e9ed962e9231"},+ {file = "lxml-5.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ba4d02aed47c25be6775a40d55c5774327fdedba79871b7c2485e80e45750cb2"},+ {file = "lxml-5.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e283b24c14361fe9e04026a1d06c924450415491b83089951d469509900d9f32"},+ {file = "lxml-5.2.0-cp38-cp38-manylinux_2_28_aarch64.whl", hash = "sha256:03e3962d6ad13a862dacd5b3a3ea60b4d092a550f36465234b8639311fd60989"},+ {file = "lxml-5.2.0-cp38-cp38-manylinux_2_28_x86_64.whl", hash = "sha256:6e45fd5213e5587a610b7e7c8c5319a77591ab21ead42df46bb342e21bc1418d"},+ {file = "lxml-5.2.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:27877732946843f4b6bfc56eb40d865653eef34ad2edeed16b015d5c29c248df"},+ {file = "lxml-5.2.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:4d16b44ad0dd8c948129639e34c8d301ad87ebc852568ace6fe9a5ad9ce67ee1"},+ {file = "lxml-5.2.0-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:b8f842df9ba26135c5414e93214e04fe0af259bb4f96a32f756f89467f7f3b45"},+ {file = "lxml-5.2.0-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:c74e77df9e36c8c91157853e6cd400f6f9ca7a803ba89981bfe3f3fc7e5651ef"},+ {file = "lxml-5.2.0-cp38-cp38-win32.whl", hash = "sha256:1459a998c10a99711ac532abe5cc24ba354e4396dafef741c7797f8830712d56"},+ {file = "lxml-5.2.0-cp38-cp38-win_amd64.whl", hash = "sha256:a00f5931b7cccea775123c3c0a2513aee58afdad8728550cc970bff32280bdd2"},+ {file = "lxml-5.2.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:ddda5ba8831f258ac7e6364be03cb27aa62f50c67fd94bc1c3b6247959cc0369"},+ {file = "lxml-5.2.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:56835b9e9a7767202fae06310c6b67478963e535fe185bed3bf9af5b18d2b67e"},+ {file = "lxml-5.2.0-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:25fef8794f0dc89f01bdd02df6a7fec4bcb2fbbe661d571e898167a83480185e"},+ {file = "lxml-5.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:32d44af078485c4da9a7ec460162392d49d996caf89516fa0b75ad0838047122"},+ {file = "lxml-5.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f354d62345acdf22aa3e171bd9723790324a66fafe61bfe3873b86724cf6daaa"},+ {file = "lxml-5.2.0-cp39-cp39-manylinux_2_28_aarch64.whl", hash = "sha256:6a7e0935f05e1cf1a3aa1d49a87505773b04f128660eac2a24a5594ea6b1baa7"},+ {file = "lxml-5.2.0-cp39-cp39-manylinux_2_28_x86_64.whl", hash = "sha256:75a4117b43694c72a0d89f6c18a28dc57407bde4650927d4ef5fd384bdf6dcc7"},+ {file = "lxml-5.2.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:57402d6cdd8a897ce21cf8d1ff36683583c17a16322a321184766c89a1980600"},+ {file = "lxml-5.2.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:56591e477bea531e5e1854f5dfb59309d5708669bc921562a35fd9ca5182bdcd"},+ {file = "lxml-5.2.0-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:7efbce96719aa275d49ad5357886845561328bf07e1d5ab998f4e3066c5ccf15"},+ {file = "lxml-5.2.0-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:a3c39def0965e8fb5c8d50973e0c7b4ce429a2fa730f3f9068a7f4f9ce78410b"},+ {file = "lxml-5.2.0-cp39-cp39-win32.whl", hash = "sha256:5188f22c00381cb44283ecb28c8d85c2db4a3035774dd851876c8647cb809c27"},+ {file = "lxml-5.2.0-cp39-cp39-win_amd64.whl", hash = "sha256:ed1fe80e1fcdd1205a443bddb1ad3c3135bb1cd3f36cc996a1f4aed35960fbe8"},+ {file = "lxml-5.2.0-pp310-pypy310_pp73-macosx_10_9_x86_64.whl", hash = "sha256:d2b339fb790fc923ae2e9345c8633e3d0064d37ea7920c027f20c8ae6f65a91f"},+ {file = "lxml-5.2.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:06036d60fccb21e22dd167f6d0e422b9cbdf3588a7e999a33799f9cbf01e41a5"},+ {file = "lxml-5.2.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7a1611fb9de0a269c05575c024e6d8cdf2186e3fa52b364e3b03dcad82514d57"},+ {file = "lxml-5.2.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:05fc3720250d221792b6e0d150afc92d20cb10c9cdaa8c8f93c2a00fbdd16015"},+ {file = "lxml-5.2.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:11e41ffd3cd27b0ca1c76073b27bd860f96431d9b70f383990f1827ca19f2f52"},+ {file = "lxml-5.2.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:0382e6a3eefa3f6699b14fa77c2eb32af2ada261b75120eaf4fc028a20394975"},+ {file = "lxml-5.2.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl", hash = "sha256:be5c8e776ecbcf8c1bce71a7d90e3a3680c9ceae516cac0be08b47e9fac0ca43"},+ {file = "lxml-5.2.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:da12b4efc93d53068888cb3b58e355b31839f2428b8f13654bd25d68b201c240"},+ {file = "lxml-5.2.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f46f8033da364bacc74aca5e319509a20bb711c8a133680ca5f35020f9eaf025"},+ {file = "lxml-5.2.0-pp37-pypy37_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:50a26f68d090594477df8572babac64575cd5c07373f7a8319c527c8e56c0f99"},+ {file = "lxml-5.2.0-pp37-pypy37_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:57cbadf028727705086047994d2e50124650e63ce5a035b0aa79ab50f001989f"},+ {file = "lxml-5.2.0-pp37-pypy37_pp73-win_amd64.whl", hash = "sha256:8aa11638902ac23f944f16ce45c9f04c9d5d57bb2da66822abb721f4efe5fdbb"},+ {file = "lxml-5.2.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:b7150e630b879390e02121e71ceb1807f682b88342e2ea2082e2c8716cf8bd93"},+ {file = "lxml-5.2.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4add722393c99da4d51c8d9f3e1ddf435b30677f2d9ba9aeaa656f23c1b7b580"},+ {file = "lxml-5.2.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dd0f25a431cd16f70ec1c47c10b413e7ddfe1ccaaddd1a7abd181e507c012374"},+ {file = "lxml-5.2.0-pp38-pypy38_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:883e382695f346c2ea3ad96bdbdf4ca531788fbeedb4352be3a8fcd169fc387d"},+ {file = "lxml-5.2.0-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:80cc2b55bb6e35d3cb40936b658837eb131e9f16357241cd9ba106ae1e9c5ecb"},+ {file = "lxml-5.2.0-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:59ec2948385336e9901008fdf765780fe30f03e7fdba8090aafdbe5d1b7ea0cd"},+ {file = "lxml-5.2.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:ddbea6e58cce1a640d9d65947f1e259423fc201c9cf9761782f355f53b7f3097"},+ {file = "lxml-5.2.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:52d6cdea438eb7282c41c5ac00bd6d47d14bebb6e8a8d2a1c168ed9e0cacfbab"},+ {file = "lxml-5.2.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7c556bbf88a8b667c849d326dd4dd9c6290ede5a33383ffc12b0ed17777f909d"},+ {file = "lxml-5.2.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:947fa8bf15d1c62c6db36c6ede9389cac54f59af27010251747f05bddc227745"},+ {file = "lxml-5.2.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:e6cb8f7a332eaa2d876b649a748a445a38522e12f2168e5e838d1505a91cdbb7"},+ {file = "lxml-5.2.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:16e65223f34fd3d65259b174f0f75a4bb3d9893698e5e7d01e54cd8c5eb98d85"},+ {file = "lxml-5.2.0.tar.gz", hash = "sha256:21dc490cdb33047bc7f7ad76384f3366fa8f5146b86cc04c4af45de901393b90"},][package.extras]cssselect = ["cssselect (>=0.7)"]+html-clean = ["lxml-html-clean"]html5 = ["html5lib"]htmlsoup = ["BeautifulSoup4"]-source = ["Cython (>=3.0.7)"]+source = ["Cython (>=3.0.10)"][[package]]name = "markdown"@@ -3476,13 +3513,13 @@ files = [[[package]]name = "pycparser"-version = "2.21"+version = "2.22"description = "C parser in Python"optional = true-python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"+python-versions = ">=3.8"files = [- {file = "pycparser-2.21-py2.py3-none-any.whl", hash = "sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9"},- {file = "pycparser-2.21.tar.gz", hash = "sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206"},+ {file = "pycparser-2.22-py3-none-any.whl", hash = "sha256:c3702b6d3dd8c7abc1afa565d7e63d53a1d0bd86cdc24edd75470f4de499cfcc"},+ {file = "pycparser-2.22.tar.gz", hash = "sha256:491c8be9c040f5390f5bf44a5b07752bd07f56edf992381b05c701439eec10f6"},][[package]]@@ -5516,13 +5553,13 @@ files = [[[package]]name = "types-docutils"-version = "0.20.0.20240317"+version = "0.20.0.20240331"description = "Typing stubs for docutils"optional = falsepython-versions = ">=3.8"files = [- {file = "types-docutils-0.20.0.20240317.tar.gz", hash = "sha256:23657aab0de58634d111914b677b1855867f16cd9a9ea110254e23b48653e1a8"},- {file = "types_docutils-0.20.0.20240317-py3-none-any.whl", hash = "sha256:4f11b3986b74f39169313ab528ffac101c45fca9c36c4cd22dbeec6143c99b7f"},+ {file = "types-docutils-0.20.0.20240331.tar.gz", hash = "sha256:ac99cdf34040c982081f54237d6017f8f5dafe0bebb818a598bf97a65f5b1715"},+ {file = "types_docutils-0.20.0.20240331-py3-none-any.whl", hash = "sha256:b9042e1cf064b4a82c87a71ed3c5f0f96e81fb6d402ca4daa6ced65a91397679"},][[package]]@@ -5538,13 +5575,13 @@ files = [[[package]]name = "types-pillow"-version = "10.2.0.20240324"+version = "10.2.0.20240331"description = "Typing stubs for Pillow"optional = falsepython-versions = ">=3.8"files = [- {file = "types-Pillow-10.2.0.20240324.tar.gz", hash = "sha256:e0108f0b30ea926a3a5d00f201cde627cde1574181b586eb36dd6be1e4ba09cf"},- {file = "types_Pillow-10.2.0.20240324-py3-none-any.whl", hash = "sha256:e0ac3b50ade911b2a238b6633cc6be9559a6f8bc54141db6ad13b70989fd3d99"},+ {file = "types-Pillow-10.2.0.20240331.tar.gz", hash = "sha256:c604e39aeb70719e463d359157a2238bfc0e81bf9c658375703f7b98cfd607da"},+ {file = "types_Pillow-10.2.0.20240331-py3-none-any.whl", hash = "sha256:ceec177ab78d9d7c110b8efdb592298ae9ae3bb4da90f7de28b99818dfbe5179"},][[package]]diff --git a/pyproject.toml b/pyproject.tomlindex 101a44441..378599919 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -203,6 +203,7 @@ module = ["docx2txt","PyMuPDF","fitz",+ "qdrant_client.*","unstructured.*","sentence_transformers.*","pymilvus",diff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.pyindex 4ec716ea5..45dfde732 100644--- a/test/agents/test_chat_agent.py+++ b/test/agents/test_chat_agent.py@@ -93,9 +93,12 @@ def test_chat_agent_messages_window():user_msg = BaseMessage(role_name="User", role_type=RoleType.USER,meta_dict=dict(), content="Tell me a joke.")- user_record = MemoryRecord(user_msg, OpenAIBackendRole.USER)- assistant.memory.write_records([user_record] * 5)+ assistant.memory.write_records(+ [MemoryRecord(+ user_msg,+ OpenAIBackendRole.USER,+ ) for _ in range(5)])openai_messages, _ = assistant.memory.get_context()assert len(openai_messages) == 2diff --git a/test/memories/test_agent_memories.py b/test/memories/test_agent_memories.pynew file mode 100644index 000000000..c2d4f9fc3--- /dev/null+++ b/test/memories/test_agent_memories.py@@ -0,0 +1,109 @@+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+# Licensed under the Apache License, Version 2.0 (the āLicenseā);+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an āAS ISā BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+from unittest.mock import MagicMock++import pytest++from camel.memories import (+ BaseContextCreator,+ ChatHistoryBlock,+ LongtermAgentMemory,+ MemoryRecord,+ VectorDBBlock,+)+from camel.messages import BaseMessage+from camel.types import OpenAIBackendRole, RoleType+++class TestLongtermAgentMemory:++ @pytest.fixture+ def mock_chat_history_block(self):+ return MagicMock(spec=ChatHistoryBlock)++ @pytest.fixture+ def mock_vector_db_block(self):+ return MagicMock(spec=VectorDBBlock)++ @pytest.fixture+ def mock_context_creator(self):+ return MagicMock(spec=BaseContextCreator)++ def test_init_with_default_components(self, mock_context_creator):+ memory = LongtermAgentMemory(mock_context_creator)+ assert memory.chat_history_block is not None+ assert memory.vector_db_block is not None++ def test_init_with_custom_components(self, mock_chat_history_block,+ mock_vector_db_block,+ mock_context_creator):+ memory = LongtermAgentMemory(+ mock_context_creator, chat_history_block=mock_chat_history_block,+ vector_db_block=mock_vector_db_block)+ assert memory.chat_history_block == mock_chat_history_block+ assert memory.vector_db_block == mock_vector_db_block++ def test_retrieve(self, mock_chat_history_block, mock_vector_db_block,+ mock_context_creator):+ mock_chat_history_block.retrieve.return_value = ["chat_history_record"]+ mock_vector_db_block.retrieve.return_value = ["vector_db_record"]+ memory = LongtermAgentMemory(+ mock_context_creator, chat_history_block=mock_chat_history_block,+ vector_db_block=mock_vector_db_block)++ records = memory.retrieve()+ assert records == ["chat_history_record", "vector_db_record"]++ def test_write_records(+ self,+ mock_chat_history_block,+ mock_vector_db_block,+ mock_context_creator,+ ):+ memory = LongtermAgentMemory(+ mock_context_creator,+ chat_history_block=mock_chat_history_block,+ vector_db_block=mock_vector_db_block,+ )+ records = [+ MemoryRecord(+ BaseMessage(+ "user",+ RoleType.USER,+ None,+ "test message {}".format(i),+ ),+ OpenAIBackendRole.USER,+ ) for i in range(5)+ ]++ memory.write_records(records)+ mock_chat_history_block.write_records.assert_called_once_with(records)+ mock_vector_db_block.write_records.assert_called_once_with(records)+ assert memory._current_topic == "test message 4"++ def test_clear(+ self,+ mock_chat_history_block,+ mock_vector_db_block,+ mock_context_creator,+ ):+ memory = LongtermAgentMemory(+ mock_context_creator,+ chat_history_block=mock_chat_history_block,+ vector_db_block=mock_vector_db_block,+ )+ memory.clear()+ mock_chat_history_block.clear.assert_called_once()+ mock_vector_db_block.clear.assert_called_once()diff --git a/test/memories/test_blocks.py b/test/memories/test_blocks.pynew file mode 100644index 000000000..ef9774131--- /dev/null+++ b/test/memories/test_blocks.py@@ -0,0 +1,179 @@+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+# Licensed under the Apache License, Version 2.0 (the āLicenseā);+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an āAS ISā BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+from unittest.mock import MagicMock, create_autospec+from uuid import uuid4++import pytest++from camel.embeddings import BaseEmbedding+from camel.memories import (+ ChatHistoryBlock,+ ContextRecord,+ MemoryRecord,+ VectorDBBlock,+)+from camel.messages import BaseMessage+from camel.storages import (+ BaseKeyValueStorage,+ BaseVectorStorage,+ VectorDBQueryResult,+)+from camel.types import OpenAIBackendRole, RoleType+++def generate_mock_records(num_records: int):+ return [{+ "uuid": str(uuid4()),+ "message": {+ "__class__": "BaseMessage",+ "role_name": "user",+ "role_type": RoleType.USER,+ "meta_dict": None,+ "content": f"test message {i}"+ },+ "role_at_backend": "user",+ "extra_info": {}+ } for i in range(num_records)]+++class TestChatHistoryBlock:++ @pytest.fixture+ def mock_storage(self):+ return create_autospec(BaseKeyValueStorage)++ def test_init_with_default_storage(self):+ chat_history = ChatHistoryBlock()+ assert chat_history.storage is not None++ def test_init_with_custom_storage(self, mock_storage):+ chat_history = ChatHistoryBlock(storage=mock_storage)+ assert chat_history.storage == mock_storage++ def test_retrieve_with_window_size(self, mock_storage):+ mock_records = generate_mock_records(10)+ mock_storage.load.return_value = mock_records+ chat_history = ChatHistoryBlock(storage=mock_storage)++ records = chat_history.retrieve(window_size=5)+ assert all(isinstance(record, ContextRecord) for record in records)+ assert len(records) == 5++ def test_retrieve_without_window_size(self, mock_storage):+ mock_records = generate_mock_records(10)+ mock_storage.load.return_value = mock_records+ chat_history = ChatHistoryBlock(storage=mock_storage)++ records = chat_history.retrieve()+ assert all(isinstance(record, ContextRecord) for record in records)+ assert len(records) == 10++ def test_retrieve_empty_history(self, mock_storage):+ mock_storage.load.return_value = []+ chat_history = ChatHistoryBlock(storage=mock_storage)++ records = chat_history.retrieve()+ assert records == []++ def test_write_records(self, mock_storage):+ chat_history = ChatHistoryBlock(storage=mock_storage)+ records_to_write = [+ MemoryRecord(+ BaseMessage(+ "user",+ RoleType.USER,+ None,+ "test message {}".format(i),+ ),+ OpenAIBackendRole.USER,+ ) for i in range(5)+ ]++ chat_history.write_records(records_to_write)+ mock_storage.save.assert_called_once()++ def test_clear_history(self, mock_storage):+ chat_history = ChatHistoryBlock(storage=mock_storage)+ chat_history.clear()+ mock_storage.clear.assert_called_once()+++class TestVectorDBBlock:++ @pytest.fixture+ def mock_storage(self):+ return create_autospec(BaseVectorStorage)++ @pytest.fixture+ def mock_embedding(self):+ mock = MagicMock(spec=BaseEmbedding)+ mock.get_output_dim.return_value = 128+ mock.embed.return_value = [0.1] * 128 # Example vector representation+ return mock++ def test_init_with_default_components(self):+ vector_db = VectorDBBlock()+ assert vector_db.storage is not None+ assert vector_db.embedding is not None++ def test_init_with_custom_components(self, mock_storage, mock_embedding):+ vector_db = VectorDBBlock(storage=mock_storage,+ embedding=mock_embedding)+ assert vector_db.storage == mock_storage+ assert vector_db.embedding == mock_embedding++ def test_retrieve(self, mock_storage, mock_embedding):+ # Generate mock records+ mock_records = generate_mock_records(2)++ # Create VectorDBQueryResult list using mock_records+ mock_query_results = [+ VectorDBQueryResult.construct(+ similarity=0.9,+ vector=[0.1] * 128, # Example vector+ id=record["uuid"],+ payload=record) for record in mock_records+ ]+ mock_storage.query.return_value = mock_query_results+ vector_db = VectorDBBlock(storage=mock_storage,+ embedding=mock_embedding)++ records = vector_db.retrieve("keyword", limit=2)+ assert len(records) == 2+ assert all(isinstance(record, ContextRecord) for record in records)+ assert records[0].memory_record.message.content == "test message 0"+ assert records[1].memory_record.message.content == "test message 1"++ def test_write_records(self, mock_storage, mock_embedding):+ vector_db = VectorDBBlock(storage=mock_storage,+ embedding=mock_embedding)+ records_to_write = [+ MemoryRecord(+ BaseMessage(+ "user",+ RoleType.USER,+ None,+ "test message {}".format(i),+ ),+ OpenAIBackendRole.USER,+ ) for i in range(5)+ ]++ vector_db.write_records(records_to_write)+ mock_storage.add.assert_called_once()++ def test_clear_history(self, mock_storage):+ vector_db = VectorDBBlock(storage=mock_storage)+ vector_db.clear()+ mock_storage.clear.assert_called_once()diff --git a/test/storages/vector_storages/test_all_vectordbs.py b/test/storages/vector_storages/test_all_vectordbs.pyindex fb1d0ee6d..ddcefb9d8 100644--- a/test/storages/vector_storages/test_all_vectordbs.py+++ b/test/storages/vector_storages/test_all_vectordbs.py@@ -36,13 +36,12 @@ def storage(request):params = request.param.split(":")if params[0] == "qdrant":if params[1] == "built-in":- yield QdrantStorage(vector_dim=4, create_collection=True)+ yield QdrantStorage(vector_dim=4)elif params[1] == "local":tmpdir = tempfile.mkdtemp()yield QdrantStorage(vector_dim=4,path=tmpdir,- create_collection=True,)shutil.rmtree(tmpdir)