mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-29 01:58:14 +00:00
Compare commits
1 Commits
63028e1b20
...
devin/1745
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
155fe58ee7 |
@@ -12,7 +12,7 @@ from crewai.utilities.task_output_storage_handler import TaskOutputStorageHandle
|
||||
def reset_memories_command(
|
||||
long,
|
||||
short,
|
||||
entity,
|
||||
entities, # Changed from entity to entities to match CLI parameter
|
||||
knowledge,
|
||||
kickoff_outputs,
|
||||
all,
|
||||
@@ -23,7 +23,7 @@ def reset_memories_command(
|
||||
Args:
|
||||
long (bool): Whether to reset the long-term memory.
|
||||
short (bool): Whether to reset the short-term memory.
|
||||
entity (bool): Whether to reset the entity memory.
|
||||
entities (bool): Whether to reset the entity memory.
|
||||
kickoff_outputs (bool): Whether to reset the latest kickoff task outputs.
|
||||
all (bool): Whether to reset all memories.
|
||||
knowledge (bool): Whether to reset the knowledge.
|
||||
@@ -45,7 +45,7 @@ def reset_memories_command(
|
||||
if short:
|
||||
ShortTermMemory().reset()
|
||||
click.echo("Short term memory has been reset.")
|
||||
if entity:
|
||||
if entities: # Changed from entity to entities
|
||||
EntityMemory().reset()
|
||||
click.echo("Entity memory has been reset.")
|
||||
if kickoff_outputs:
|
||||
|
||||
@@ -14,13 +14,13 @@ class Knowledge(BaseModel):
|
||||
Knowledge is a collection of sources and setup for the vector store to save and query relevant context.
|
||||
Args:
|
||||
sources: List[BaseKnowledgeSource] = Field(default_factory=list)
|
||||
storage: Optional[KnowledgeStorage] = Field(default=None)
|
||||
storage: KnowledgeStorage = Field(default_factory=KnowledgeStorage)
|
||||
embedder_config: Optional[Dict[str, Any]] = None
|
||||
"""
|
||||
|
||||
sources: List[BaseKnowledgeSource] = Field(default_factory=list)
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
storage: Optional[KnowledgeStorage] = Field(default=None)
|
||||
storage: KnowledgeStorage = Field(default_factory=KnowledgeStorage)
|
||||
embedder_config: Optional[Dict[str, Any]] = None
|
||||
collection_name: Optional[str] = None
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource, ABC):
|
||||
default_factory=list, description="The path to the file"
|
||||
)
|
||||
content: Dict[Path, str] = Field(init=False, default_factory=dict)
|
||||
storage: Optional[KnowledgeStorage] = Field(default=None)
|
||||
storage: KnowledgeStorage = Field(default_factory=KnowledgeStorage)
|
||||
safe_file_paths: List[Path] = Field(default_factory=list)
|
||||
|
||||
@field_validator("file_path", "file_paths", mode="before")
|
||||
@@ -62,10 +62,7 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource, ABC):
|
||||
|
||||
def _save_documents(self):
|
||||
"""Save the documents to the storage."""
|
||||
if self.storage:
|
||||
self.storage.save(self.chunks)
|
||||
else:
|
||||
raise ValueError("No storage found to save documents.")
|
||||
self.storage.save(self.chunks)
|
||||
|
||||
def convert_to_path(self, path: Union[Path, str]) -> Path:
|
||||
"""Convert a path to a Path object."""
|
||||
|
||||
@@ -16,7 +16,7 @@ class BaseKnowledgeSource(BaseModel, ABC):
|
||||
chunk_embeddings: List[np.ndarray] = Field(default_factory=list)
|
||||
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
storage: Optional[KnowledgeStorage] = Field(default=None)
|
||||
storage: KnowledgeStorage = Field(default_factory=KnowledgeStorage)
|
||||
metadata: Dict[str, Any] = Field(default_factory=dict) # Currently unused
|
||||
collection_name: Optional[str] = Field(default=None)
|
||||
|
||||
@@ -46,7 +46,4 @@ class BaseKnowledgeSource(BaseModel, ABC):
|
||||
Save the documents to the storage.
|
||||
This method should be called after the chunks and embeddings are generated.
|
||||
"""
|
||||
if self.storage:
|
||||
self.storage.save(self.chunks)
|
||||
else:
|
||||
raise ValueError("No storage found to save documents.")
|
||||
self.storage.save(self.chunks)
|
||||
|
||||
62
tests/cli/test_reset_memories.py
Normal file
62
tests/cli/test_reset_memories.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import os
|
||||
import tempfile
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
|
||||
from crewai.cli.cli import reset_memories
|
||||
from crewai.cli.reset_memories_command import reset_memories_command
|
||||
|
||||
|
||||
def test_reset_memories_command_parameters():
|
||||
"""Test that the CLI parameters match the function parameters."""
|
||||
# Create a mock for reset_memories_command
|
||||
with patch('crewai.cli.cli.reset_memories_command') as mock_reset:
|
||||
runner = CliRunner()
|
||||
|
||||
# Test with entities flag
|
||||
result = runner.invoke(reset_memories, ['--entities'])
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Check that the function was called with the correct parameters
|
||||
# The third parameter should be True for entities
|
||||
mock_reset.assert_called_once_with(False, False, True, False, False, False)
|
||||
|
||||
|
||||
def test_reset_memories_all_flag():
|
||||
"""Test that the --all flag resets all memories."""
|
||||
with patch('crewai.cli.cli.reset_memories_command') as mock_reset:
|
||||
runner = CliRunner()
|
||||
|
||||
# Test with all flag
|
||||
result = runner.invoke(reset_memories, ['--all'])
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Check that the function was called with the correct parameters
|
||||
# The last parameter should be True for all
|
||||
mock_reset.assert_called_once_with(False, False, False, False, False, True)
|
||||
|
||||
|
||||
def test_reset_memories_knowledge_flag():
|
||||
"""Test that the --knowledge flag resets knowledge storage."""
|
||||
with patch('crewai.cli.cli.reset_memories_command') as mock_reset:
|
||||
runner = CliRunner()
|
||||
|
||||
# Test with knowledge flag
|
||||
result = runner.invoke(reset_memories, ['--knowledge'])
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Check that the function was called with the correct parameters
|
||||
# The fourth parameter should be True for knowledge
|
||||
mock_reset.assert_called_once_with(False, False, False, True, False, False)
|
||||
|
||||
|
||||
def test_reset_memories_no_flags():
|
||||
"""Test that an error message is shown when no flags are provided."""
|
||||
runner = CliRunner()
|
||||
|
||||
# Test with no flags
|
||||
result = runner.invoke(reset_memories, [])
|
||||
assert result.exit_code == 0
|
||||
assert "Please specify at least one memory type" in result.output
|
||||
Reference in New Issue
Block a user