mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-29 10:56:22 +02:00
Merge branch 'mgx_ops' into add_swe_agent_ablilities_to_engineer2
This commit is contained in:
commit
2837dc16ce
29 changed files with 751 additions and 104 deletions
0
tests/metagpt/rag/__init__.py
Normal file
0
tests/metagpt/rag/__init__.py
Normal file
55
tests/metagpt/rag/test_large_pdf.py
Normal file
55
tests/metagpt/rag/test_large_pdf.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import pytest
|
||||
|
||||
from metagpt.config2 import Config
|
||||
from metagpt.const import TEST_DATA_PATH
|
||||
from metagpt.rag.engines import SimpleEngine
|
||||
from metagpt.rag.factories.embedding import RAGEmbeddingFactory
|
||||
from metagpt.utils.common import aread
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
@pytest.mark.parametrize(
|
||||
("knowledge_filename", "query_filename", "answer_filename"),
|
||||
[
|
||||
(
|
||||
TEST_DATA_PATH / "embedding/2.knowledge.md",
|
||||
TEST_DATA_PATH / "embedding/2.query.md",
|
||||
TEST_DATA_PATH / "embedding/2.answer.md",
|
||||
),
|
||||
(
|
||||
TEST_DATA_PATH / "embedding/3.knowledge.md",
|
||||
TEST_DATA_PATH / "embedding/3.query.md",
|
||||
TEST_DATA_PATH / "embedding/3.answer.md",
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_large_pdf(knowledge_filename, query_filename, answer_filename):
|
||||
Config.default(reload=True) # `config.embedding.model = "text-embedding-ada-002"` changes the cache.
|
||||
|
||||
engine = SimpleEngine.from_docs(
|
||||
input_files=[knowledge_filename],
|
||||
)
|
||||
|
||||
query = await aread(filename=query_filename)
|
||||
rsp = await engine.aretrieve(query)
|
||||
assert rsp
|
||||
|
||||
config = Config.default()
|
||||
config.embedding.model = "text-embedding-ada-002"
|
||||
factory = RAGEmbeddingFactory(config)
|
||||
embedding = factory.get_rag_embedding()
|
||||
answer = await aread(filename=answer_filename)
|
||||
answer_embedding = await embedding.aget_text_embedding(answer)
|
||||
similarity = 0
|
||||
for i in rsp:
|
||||
rsp_embedding = await embedding.aget_query_embedding(i.text)
|
||||
v = embedding.similarity(answer_embedding, rsp_embedding)
|
||||
similarity = max(similarity, v)
|
||||
|
||||
print(similarity)
|
||||
assert similarity > 0.9
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-s"])
|
||||
32
tests/metagpt/tools/libs/test_index_repo.py
Normal file
32
tests/metagpt/tools/libs/test_index_repo.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.const import DEFAULT_WORKSPACE_ROOT, TEST_DATA_PATH
|
||||
from metagpt.tools.libs.index_repo import IndexRepo
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(("path", "query"), [(TEST_DATA_PATH / "requirements", "业务线")])
|
||||
async def test_index_repo(path, query):
|
||||
index_path = DEFAULT_WORKSPACE_ROOT / ".index"
|
||||
repo = IndexRepo(persist_path=str(index_path), root_path=str(path), min_token_count=0)
|
||||
await repo.add([path])
|
||||
await repo.add([path])
|
||||
assert index_path.exists()
|
||||
|
||||
rsp = await repo.search(query)
|
||||
assert rsp
|
||||
|
||||
repo2 = IndexRepo(persist_path=str(index_path), root_path=str(path), min_token_count=0)
|
||||
rsp2 = await repo2.search(query)
|
||||
assert rsp2
|
||||
|
||||
merged_rsp = await repo.merge(query=query, indices_list=[rsp, rsp2])
|
||||
assert merged_rsp
|
||||
|
||||
shutil.rmtree(index_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-s"])
|
||||
Loading…
Add table
Add a link
Reference in a new issue