From b27ba8476f2b81fffcba272f82ce1f92f2804050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Fri, 16 Aug 2024 11:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=BD=E6=95=B0=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/exp_pool/context_builders/role_zero.py | 8 ++++---- .../test_rolezero_context_builder.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/metagpt/exp_pool/context_builders/role_zero.py b/metagpt/exp_pool/context_builders/role_zero.py index 4a9042765..b25308153 100644 --- a/metagpt/exp_pool/context_builders/role_zero.py +++ b/metagpt/exp_pool/context_builders/role_zero.py @@ -30,10 +30,10 @@ class RoleZeroContextBuilder(BaseContextBuilder): return req_copy def replace_example_content(self, text: str, new_example_content: str) -> str: - return self.replace_content_of_example_tag(text, new_example_content) + return self.fill_experience(text, new_example_content) @staticmethod - def replace_content_of_example_tag(text: str, new_example_content: str) -> str: - pattern = "# Past Experience\n" - replaced_text = text.replace(pattern, "# Past Experience\n" + new_example_content) + def fill_experience(text: str, new_example_content: str) -> str: + pattern = "" + replaced_text = text.replace(pattern, new_example_content) return replaced_text diff --git a/tests/metagpt/exp_pool/test_context_builders/test_rolezero_context_builder.py b/tests/metagpt/exp_pool/test_context_builders/test_rolezero_context_builder.py index 795e8c26b..ee56ea094 100644 --- a/tests/metagpt/exp_pool/test_context_builders/test_rolezero_context_builder.py +++ b/tests/metagpt/exp_pool/test_context_builders/test_rolezero_context_builder.py @@ -30,20 +30,20 @@ class TestRoleZeroContextBuilder: assert result == [{"content": "Updated content"}] def test_replace_example_content(self, context_builder, mocker): - mocker.patch.object(RoleZeroContextBuilder, "replace_content_of_example_tag", return_value="Replaced content") + mocker.patch.object(RoleZeroContextBuilder, "fill_experience", return_value="Replaced content") result = context_builder.replace_example_content("Original text", "New example content") assert result == "Replaced content" - context_builder.replace_content_of_example_tag.assert_called_once_with("Original text", "New example content") + context_builder.fill_experience.assert_called_once_with("Original text", "New example content") - def test_replace_content_of_example_tag(self): + def test_fill_experience(self): text = "Start\n# Past Experience\n\n\n# Instruction\nEnd" new_content = "New content" - result = RoleZeroContextBuilder.replace_content_of_example_tag(text, new_content) + result = RoleZeroContextBuilder.fill_experience(text, new_content) expected = "Start\n# Past Experience\nNew content\n\n# Instruction\nEnd" assert result == expected - def test_replace_content_of_example_tag_no_match(self): + def test_fill_experience_no_match(self): text = "Start\nNo markers\nEnd" new_content = "New content" - result = RoleZeroContextBuilder.replace_content_of_example_tag(text, new_content) + result = RoleZeroContextBuilder.fill_experience(text, new_content) assert result == text