mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-20 15:38:09 +02:00
init exp pool
This commit is contained in:
parent
fb4446c0a9
commit
39360b41c5
8 changed files with 512 additions and 53 deletions
|
|
@ -62,21 +62,3 @@ class TestExperienceManager:
|
|||
mock_config.exp_pool.enable_read = False
|
||||
result = await mock_experience_manager.query_exps("query")
|
||||
assert result == []
|
||||
|
||||
def test_has_exps(self, mock_experience_manager, mock_storage):
|
||||
mock_storage._retriever._vector_store._get.return_value.ids = ["id1"]
|
||||
|
||||
assert mock_experience_manager._has_exps() is True
|
||||
|
||||
mock_storage._retriever._vector_store._get.return_value.ids = []
|
||||
assert mock_experience_manager._has_exps() is False
|
||||
|
||||
def test_init_teamleader_exps(self, mock_experience_manager, mocker):
|
||||
mock_experience_manager._init_exp = mocker.MagicMock()
|
||||
mock_experience_manager._init_teamleader_exps()
|
||||
mock_experience_manager._init_exp.assert_called_once()
|
||||
|
||||
def test_init_engineer2_exps(self, mock_experience_manager, mocker):
|
||||
mock_experience_manager._init_exp = mocker.MagicMock()
|
||||
mock_experience_manager._init_engineer2_exps()
|
||||
mock_experience_manager._init_exp.assert_called_once()
|
||||
|
|
|
|||
35
tests/metagpt/exp_pool/test_serializers/test_action_node.py
Normal file
35
tests/metagpt/exp_pool/test_serializers/test_action_node.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from typing import Type
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.actions.action_node import ActionNode
|
||||
from metagpt.exp_pool.serializers.action_node import ActionNodeSerializer
|
||||
|
||||
|
||||
class TestActionNodeSerializer:
|
||||
@pytest.fixture
|
||||
def serializer(self):
|
||||
return ActionNodeSerializer()
|
||||
|
||||
@pytest.fixture
|
||||
def action_node(self):
|
||||
class InstructContent:
|
||||
def __init__(self, json_data):
|
||||
self.json_data = json_data
|
||||
|
||||
def model_dump_json(self):
|
||||
return self.json_data
|
||||
|
||||
action_node = ActionNode(key="", expected_type=Type[str], instruction="", example="")
|
||||
action_node.instruct_content = InstructContent('{"key": "value"}')
|
||||
|
||||
return action_node
|
||||
|
||||
def test_serialize_resp(self, serializer: ActionNodeSerializer, action_node: ActionNode):
|
||||
serialized = serializer.serialize_resp(action_node)
|
||||
assert serialized == '{"key": "value"}'
|
||||
|
||||
def test_deserialize_resp(self, serializer: ActionNodeSerializer):
|
||||
deserialized = serializer.deserialize_resp('{"key": "value"}')
|
||||
assert isinstance(deserialized, ActionNode)
|
||||
assert deserialized.instruct_content.model_dump_json() == '{"key": "value"}'
|
||||
77
tests/metagpt/exp_pool/test_serializers/test_role_zero.py
Normal file
77
tests/metagpt/exp_pool/test_serializers/test_role_zero.py
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.exp_pool.serializers import RoleZeroSerializer
|
||||
|
||||
|
||||
class TestRoleZeroSerializer:
|
||||
@pytest.fixture
|
||||
def serializer(self):
|
||||
return RoleZeroSerializer()
|
||||
|
||||
def test_serialize_req_empty_input(self, serializer: RoleZeroSerializer):
|
||||
assert serializer.serialize_req([]) == ""
|
||||
|
||||
def test_serialize_req_with_content(self, serializer: RoleZeroSerializer):
|
||||
req = [
|
||||
{"content": "Command Editor.read executed: file_path=test.py"},
|
||||
{"content": "Some other content"},
|
||||
{
|
||||
"content": "# Data Structure\nsome data\n# Current Plan\nsome plan\n# Example\nsome example\n# Instruction\nsome instruction"
|
||||
},
|
||||
]
|
||||
expected_output = json.dumps(
|
||||
[
|
||||
{"content": "Command Editor.read executed: file_path=test.py"},
|
||||
{
|
||||
"content": "# Data Structure\n\n\n# Current Plan\nsome plan\n# Example\n\n\n# Instruction\nsome instruction"
|
||||
},
|
||||
]
|
||||
)
|
||||
assert serializer.serialize_req(req) == expected_output
|
||||
|
||||
def test_filter_req(self, serializer: RoleZeroSerializer):
|
||||
req = [
|
||||
{"content": "Command Editor.read executed: file_path=test1.py"},
|
||||
{"content": "Some other content"},
|
||||
{"content": "Command Editor.read executed: file_path=test2.py"},
|
||||
{"content": "Final content"},
|
||||
]
|
||||
filtered_req = serializer._filter_req(req)
|
||||
assert len(filtered_req) == 3
|
||||
assert filtered_req[0]["content"] == "Command Editor.read executed: file_path=test1.py"
|
||||
assert filtered_req[1]["content"] == "Command Editor.read executed: file_path=test2.py"
|
||||
assert filtered_req[2]["content"] == "Final content"
|
||||
|
||||
def test_clean_last_entry_content(self, serializer: RoleZeroSerializer):
|
||||
req = [
|
||||
{"content": "Some content"},
|
||||
{
|
||||
"content": "# Data Structure\nsome data\n# Current Plan\nsome plan\n# Example\nsome example\n# Instruction\nsome instruction"
|
||||
},
|
||||
]
|
||||
serializer._clean_last_entry_content(req)
|
||||
expected_content = (
|
||||
"# Data Structure\n\n\n# Current Plan\nsome plan\n# Example\n\n\n# Instruction\nsome instruction"
|
||||
)
|
||||
assert req[-1]["content"] == expected_content
|
||||
|
||||
def test_integration(self, serializer: RoleZeroSerializer):
|
||||
req = [
|
||||
{"content": "Command Editor.read executed: file_path=test.py"},
|
||||
{"content": "Some other content"},
|
||||
{
|
||||
"content": "# Data Structure\nsome data\n# Current Plan\nsome plan\n# Example\nsome example\n# Instruction\nsome instruction"
|
||||
},
|
||||
]
|
||||
result = serializer.serialize_req(req)
|
||||
expected_output = json.dumps(
|
||||
[
|
||||
{"content": "Command Editor.read executed: file_path=test.py"},
|
||||
{
|
||||
"content": "# Data Structure\n\n\n# Current Plan\nsome plan\n# Example\n\n\n# Instruction\nsome instruction"
|
||||
},
|
||||
]
|
||||
)
|
||||
assert result == expected_output
|
||||
44
tests/metagpt/exp_pool/test_serializers/test_simple.py
Normal file
44
tests/metagpt/exp_pool/test_serializers/test_simple.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import pytest
|
||||
|
||||
from metagpt.exp_pool.serializers.simple import SimpleSerializer
|
||||
|
||||
|
||||
class TestSimpleSerializer:
|
||||
@pytest.fixture
|
||||
def serializer(self):
|
||||
return SimpleSerializer()
|
||||
|
||||
def test_serialize_req(self, serializer):
|
||||
# Test with different types of input
|
||||
assert serializer.serialize_req(123) == "123"
|
||||
assert serializer.serialize_req("test") == "test"
|
||||
assert serializer.serialize_req([1, 2, 3]) == "[1, 2, 3]"
|
||||
assert serializer.serialize_req({"a": 1}) == "{'a': 1}"
|
||||
|
||||
def test_serialize_resp(self, serializer):
|
||||
# Test with different types of input
|
||||
assert serializer.serialize_resp(456) == "456"
|
||||
assert serializer.serialize_resp("response") == "response"
|
||||
assert serializer.serialize_resp([4, 5, 6]) == "[4, 5, 6]"
|
||||
assert serializer.serialize_resp({"b": 2}) == "{'b': 2}"
|
||||
|
||||
def test_deserialize_resp(self, serializer):
|
||||
# Test with different types of input
|
||||
assert serializer.deserialize_resp("789") == "789"
|
||||
assert serializer.deserialize_resp("test_response") == "test_response"
|
||||
assert serializer.deserialize_resp("[7, 8, 9]") == "[7, 8, 9]"
|
||||
assert serializer.deserialize_resp("{'c': 3}") == "{'c': 3}"
|
||||
|
||||
def test_roundtrip(self, serializer):
|
||||
# Test serialization and deserialization roundtrip
|
||||
original = "test_roundtrip"
|
||||
serialized = serializer.serialize_resp(original)
|
||||
deserialized = serializer.deserialize_resp(serialized)
|
||||
assert deserialized == original
|
||||
|
||||
@pytest.mark.parametrize("input_value", [123, "test", [1, 2, 3], {"a": 1}, None])
|
||||
def test_serialize_req_types(self, serializer, input_value):
|
||||
# Test serialize_req with various input types
|
||||
result = serializer.serialize_req(input_value)
|
||||
assert isinstance(result, str)
|
||||
assert result == str(input_value)
|
||||
Loading…
Add table
Add a link
Reference in a new issue