Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
shihanwan committed Oct 15, 2024
1 parent ff0dcba commit 27c1dfd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
21 changes: 11 additions & 10 deletions memonto/core/retain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import ast
import json
import uuid
from rdflib import Graph, Namespace

from memonto.llms.base_llm import LLMModel
Expand All @@ -14,6 +12,7 @@
hydrate_graph_with_ids,
)


def _run_script(
script: str,
exec_ctx: dict,
Expand Down Expand Up @@ -87,12 +86,14 @@ def update_memory(
data_list = []

for s, p, o in data:
data_list.append({
"s": str(s),
"p": str(p),
"o": str(o),
})

data_list.append(
{
"s": str(s),
"p": str(p),
"o": str(o),
}
)

logger.debug(f"existing memories\n{data_list}\n")

updates = llm.prompt(
Expand All @@ -112,7 +113,7 @@ def update_memory(
for t in updated_memory:
if str(s) == t["s"] and str(p) == t["p"] and str(o) == t["o"]:
data.remove((s, p, o))

return str(updated_memory)
else:
matched = vector_store.search(message=message, id=id, k=3)
Expand Down Expand Up @@ -180,7 +181,7 @@ def save_memory(

# debug
# _render(g=data, format="image")

if not ephemeral:
hydrate_graph_with_ids(data)
triple_store.save(ontology=ontology, data=data, id=id)
Expand Down
2 changes: 1 addition & 1 deletion memonto/utils/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def is_updated(nt: dict, o: list[dict]) -> bool:

if ns == os and np == op and no == oo:
return False

return True

return [nt for nt in n if is_updated(nt, o)]
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/test_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_find_updated_triples_ephemeral():
{"s": "9", "p": "2", "o": "1"},
{"s": "5", "p": "7", "o": "9"},
]

assert find_updated_triples_ephemeral(original, updated) == [
{"s": "1", "p": "2", "o": "9"},
{"s": "9", "p": "2", "o": "1"},
Expand All @@ -91,5 +91,5 @@ def test_find_updated_triples_ephemeral_no_updates():
{"s": "3", "p": "2", "o": "1"},
{"s": "5", "p": "7", "o": "9"},
]
assert find_updated_triples_ephemeral(original, updated) == []

assert find_updated_triples_ephemeral(original, updated) == []

0 comments on commit 27c1dfd

Please sign in to comment.