Skip to content

Commit

Permalink
feat: sync di_graph_repository
Browse files Browse the repository at this point in the history
  • Loading branch information
莘权 马 committed Jun 13, 2024
1 parent e927416 commit b240173
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
20 changes: 2 additions & 18 deletions metagpt/utils/di_graph_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,12 @@ async def delete(self, subject: str = None, predicate: str = None, object_: str
deleted_count = await my_di_graph_repo.delete(subject="Node1", predicate="connects_to")
# Deletes directed relationships where Node1 is the subject and the predicate is 'connects_to'.
"""
rows = []
for s, o, p in self._repo.edges(data="predicate"):
if subject and subject != s:
continue
if object_ and object_ != o:
continue
rows.append(SPO(subject=s, object_=o, predicate=p))
rows = await self.select(subject=subject, predicate=predicate, object_=object_)
if not rows:
return 0

affected = []
unaffected = []
for r in rows:
self._repo.remove_edge(r.subject, r.object_)
if predicate and predicate == r.predicate:
affected.append(r)
else:
unaffected.append(r)

for r in unaffected:
self._repo.add_edge(r.subject, r.object_, predicate=r.predicate)
return len(affected)
return len(rows)

def json(self) -> str:
"""Convert the directed graph repository to a JSON-formatted string."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@pytest.mark.asyncio
async def test_summarize(context):
await prepare_graph_db()
await prepare_graph_db(context)

action = Summarize(context=context)
await action.run()
Expand Down

0 comments on commit b240173

Please sign in to comment.