mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-02 14:45:17 +02:00
feat: +visual graph repo
This commit is contained in:
parent
c1552d7319
commit
fb7518c12b
13 changed files with 217 additions and 18 deletions
|
|
@ -20,21 +20,21 @@ from metagpt.utils.graph_repository import SPO
|
|||
@pytest.mark.asyncio
|
||||
async def test_rebuild(context, mocker):
|
||||
# Mock
|
||||
data = await aread(filename=Path(__file__).parent / "../../data/graph_db/networkx.json")
|
||||
data = await aread(filename=Path(__file__).parent / "../../data/graph_db/networkx.class_view.json")
|
||||
graph_db_filename = Path(context.repo.workdir.name).with_suffix(".json")
|
||||
await context.repo.docs.graph_repo.save(filename=str(graph_db_filename), content=data)
|
||||
context.git_repo.add_change({f"{GRAPH_REPO_FILE_REPO}/{graph_db_filename}": ChangeType.UNTRACTED})
|
||||
context.git_repo.commit("commit1")
|
||||
# mock_spo = SPO(
|
||||
# subject="metagpt/startup.py:__name__:__main__",
|
||||
# predicate="has_page_info",
|
||||
# object_='{"lineno":78,"end_lineno":79,"type_name":"ast.If","tokens":["__name__","__main__"],"properties":{}}',
|
||||
# )
|
||||
mock_spo = SPO(
|
||||
subject="metagpt/tools/search_engine_serpapi.py:__name__:__main__",
|
||||
subject="metagpt/startup.py:__name__:__main__",
|
||||
predicate="has_page_info",
|
||||
object_='{"lineno":113,"end_lineno":116,"type_name":"ast.If","tokens":["__name__","__main__"],"properties":{}}',
|
||||
object_='{"lineno":78,"end_lineno":79,"type_name":"ast.If","tokens":["__name__","__main__"],"properties":{}}',
|
||||
)
|
||||
# mock_spo = SPO(
|
||||
# subject="metagpt/tools/search_engine_serpapi.py:__name__:__main__",
|
||||
# predicate="has_page_info",
|
||||
# object_='{"lineno":113,"end_lineno":116,"type_name":"ast.If","tokens":["__name__","__main__"],"properties":{}}',
|
||||
# )
|
||||
mocker.patch.object(RebuildSequenceView, "_search_main_entry", return_value=[mock_spo])
|
||||
|
||||
action = RebuildSequenceView(
|
||||
|
|
|
|||
26
tests/metagpt/utils/test_visual_graph_repo.py
Normal file
26
tests/metagpt/utils/test_visual_graph_repo.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.utils.visual_graph_repo import VisualDiGraphRepo
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_visual_di_graph_repo(context, mocker):
|
||||
filename = Path(__file__).parent / "../../data/graph_db/networkx.sequence_view.json"
|
||||
repo = await VisualDiGraphRepo.load_from(filename=filename)
|
||||
|
||||
class_view = await repo.get_mermaid_class_view()
|
||||
assert class_view
|
||||
await context.repo.resources.graph_repo.save(filename="class_view.md", content=f"```mermaid\n{class_view}\n```\n")
|
||||
|
||||
sequence_views = await repo.get_mermaid_sequence_views()
|
||||
assert sequence_views
|
||||
for ns, sqv in sequence_views:
|
||||
filename = re.sub(r"[:/\\\.]+", "_", ns) + ".sequence_view.md"
|
||||
await context.repo.resources.graph_repo.save(filename=filename, content=f"```mermaid\n{sqv}\n```\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-s"])
|
||||
Loading…
Add table
Add a link
Reference in a new issue