mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-14 15:25:17 +02:00
Merge branch 'gitlab/mgx_ops' into feature/merge/mgx_intent
This commit is contained in:
commit
764a5ba299
6 changed files with 418 additions and 0 deletions
0
tests/data/tools/test_script_for_file_manager.py
Normal file
0
tests/data/tools/test_script_for_file_manager.py
Normal file
55
tests/metagpt/actions/di/test_detect_intent.py
Normal file
55
tests/metagpt/actions/di/test_detect_intent.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import pytest
|
||||
|
||||
from metagpt.actions.di.detect_intent import DetectIntent
|
||||
|
||||
SOFTWARE_DEV_REQ1 = """
|
||||
I'd like to create a personalized website that features the 'Game of Life' simulation.
|
||||
"""
|
||||
|
||||
SOFTWARE_DEV_REQ2 = """
|
||||
Create a website widget for TODO list management.
|
||||
"""
|
||||
|
||||
SOFTWARE_DEV_REQ3 = """
|
||||
Create an official website with a top bar, banner, About Us section, and footer.
|
||||
"""
|
||||
|
||||
DI_REQ1 = """
|
||||
can you finetune a 78 Llama model using https://github.com/huggingface/peft should be instructions in the Readme.
|
||||
"""
|
||||
|
||||
DI_REQ2 = """
|
||||
I came across a blog post on the website Mafengwo (https://www.mafengwo.cn/i/17171539.html) that discusses the possibility of generating images with hidden text. The post refers to a script that can be used for this purpose. Could you help me set up this script and use it to generate some images? I would like the images to have the hidden text 'MAX' and also some with 'MetaGPT' as the hidden text.
|
||||
"""
|
||||
|
||||
DI_REQ3 = """
|
||||
Extract all of the blog posts from `https://stripe.com/blog/page/1` and return a CSV with the columns `date`, `article_text`, `author` and `summary`. Generate a summary for each article yourself.
|
||||
"""
|
||||
|
||||
FIX_BUG_REQ = """
|
||||
Fix this error from the 2048 game repo: TypeError: __init__() takes 1 positional argument but 2 were given"
|
||||
"""
|
||||
|
||||
FORMAT_REPO_REQ = """
|
||||
git clone 'https://github.com/spec-first/connexion' and format to MetaGPT project
|
||||
"""
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"requirement, expected_intent_type",
|
||||
[
|
||||
(SOFTWARE_DEV_REQ1, "software development"),
|
||||
(SOFTWARE_DEV_REQ2, "software development"),
|
||||
(SOFTWARE_DEV_REQ3, "software development"),
|
||||
(DI_REQ1, "other"),
|
||||
(DI_REQ2, "other"),
|
||||
(DI_REQ3, "other"),
|
||||
(FIX_BUG_REQ, "fix bugs"),
|
||||
(FORMAT_REPO_REQ, "format repo"),
|
||||
],
|
||||
)
|
||||
async def test_detect_intent(requirement, expected_intent_type):
|
||||
di = DetectIntent()
|
||||
_, intent_type = await di.run(requirement)
|
||||
assert intent_type == expected_intent_type
|
||||
102
tests/metagpt/tools/libs/test_file_manager.py
Normal file
102
tests/metagpt/tools/libs/test_file_manager.py
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
import pytest
|
||||
|
||||
from metagpt.const import TEST_DATA_PATH
|
||||
from metagpt.tools.libs.file_manager import FileBlock, FileManager
|
||||
|
||||
TEST_FILE_CONTENT = """
|
||||
# this is line one
|
||||
def test_function_for_fm():
|
||||
"some docstring"
|
||||
a = 1
|
||||
b = 2
|
||||
c = 3
|
||||
# this is the 7th line
|
||||
""".strip()
|
||||
|
||||
TEST_FILE_PATH = TEST_DATA_PATH / "tools/test_script_for_file_manager.py"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_file():
|
||||
with open(TEST_FILE_PATH, "w") as f:
|
||||
f.write(TEST_FILE_CONTENT)
|
||||
yield
|
||||
with open(TEST_FILE_PATH, "w") as f:
|
||||
f.write("")
|
||||
|
||||
|
||||
EXPECTED_SEARCHED_BLOCK = FileBlock(
|
||||
file_path=str(TEST_FILE_PATH),
|
||||
block_content='# this is line one\ndef test_function_for_fm():\n "some docstring"\n a = 1\n b = 2\n',
|
||||
block_start_line=1,
|
||||
block_end_line=5,
|
||||
symbol="def test_function_for_fm",
|
||||
symbol_line=2,
|
||||
)
|
||||
|
||||
|
||||
def test_search_content(test_file):
|
||||
block = FileManager().search_content("def test_function_for_fm", root_path=TEST_DATA_PATH, window=3)
|
||||
assert block == EXPECTED_SEARCHED_BLOCK
|
||||
|
||||
|
||||
EXPECTED_CONTENT_AFTER_REPLACE = """
|
||||
# this is line one
|
||||
def test_function_for_fm():
|
||||
This is the new line A replacing lines 3 to 5.
|
||||
This is the new line B.
|
||||
c = 3
|
||||
# this is the 7th line
|
||||
""".strip()
|
||||
|
||||
|
||||
def test_replace_content(test_file):
|
||||
FileManager().write_content(
|
||||
file_path=str(TEST_FILE_PATH),
|
||||
start_line=3,
|
||||
end_line=5,
|
||||
new_block_content=" This is the new line A replacing lines 3 to 5.\n This is the new line B.",
|
||||
)
|
||||
with open(TEST_FILE_PATH, "r") as f:
|
||||
new_content = f.read()
|
||||
print(new_content)
|
||||
assert new_content == EXPECTED_CONTENT_AFTER_REPLACE
|
||||
|
||||
|
||||
EXPECTED_CONTENT_AFTER_DELETE = """
|
||||
# this is line one
|
||||
def test_function_for_fm():
|
||||
c = 3
|
||||
# this is the 7th line
|
||||
""".strip()
|
||||
|
||||
|
||||
def test_delete_content(test_file):
|
||||
FileManager().write_content(file_path=str(TEST_FILE_PATH), start_line=3, end_line=5)
|
||||
with open(TEST_FILE_PATH, "r") as f:
|
||||
new_content = f.read()
|
||||
assert new_content == EXPECTED_CONTENT_AFTER_DELETE
|
||||
|
||||
|
||||
EXPECTED_CONTENT_AFTER_INSERT = """
|
||||
# this is line one
|
||||
def test_function_for_fm():
|
||||
This is the new line to be inserted, at line 3
|
||||
"some docstring"
|
||||
a = 1
|
||||
b = 2
|
||||
c = 3
|
||||
# this is the 7th line
|
||||
""".strip()
|
||||
|
||||
|
||||
def test_insert_content(test_file):
|
||||
FileManager().write_content(
|
||||
file_path=str(TEST_FILE_PATH),
|
||||
start_line=3,
|
||||
end_line=-1,
|
||||
new_block_content=" This is the new line to be inserted, at line 3",
|
||||
)
|
||||
with open(TEST_FILE_PATH, "r") as f:
|
||||
new_content = f.read()
|
||||
assert new_content == EXPECTED_CONTENT_AFTER_INSERT
|
||||
Loading…
Add table
Add a link
Reference in a new issue