Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
fix: bug in playground
Browse files Browse the repository at this point in the history
  • Loading branch information
doomspec committed Oct 10, 2023
1 parent dc19b17 commit 24c35ba
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion evonote/gui/dictionary_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def show_document_with_key_gui(keys, documents):
if len(keys) == 0:
print("No keys to show")
print("Dict viewer: No keys to show")
return

html_documents = []
Expand Down
2 changes: 1 addition & 1 deletion evonote/mindtree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Tree:
"""


def __init__(self, root_content, rule_of_path: str = None):
def __init__(self, root_content="", rule_of_path: str = None):
"""
:param root_content: The content of the root of the tree
:param rule_of_path: The rule for creating paths.
Expand Down
6 changes: 3 additions & 3 deletions evonote/transform/build_from_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def digest_content(content):
system_message="""You are a helpful assistant for arranging knowledge. You should output merely JSON.""")
chat.add_user_message(content)
chat.add_user_message(
"""Summarize the below paragraphs into a tree. Give the result in JSON with the keys being "root_content", "statement", "subtopics". The "statement" entry should be a shortened version of original text.""")
"""Summarize the below paragraphs into a tree. Give the result in JSON with the keys being "topic", "statement", "subtopics". The "statement" entry should be a shortened version of original text.""")

res = chat.complete_chat()
if res[0] == "`":
Expand All @@ -83,9 +83,9 @@ def set_notes_by_digest(note: Note, digest: str):


def iter_and_assign(note: Note, tree: dict):
if "root_content" not in tree or "statement" not in tree:
if "topic" not in tree or "statement" not in tree:
raise Exception("incomplete tree node")
node = note.s(tree["root_content"]).be(tree["statement"])
node = note.s(tree["topic"]).be(tree["statement"])
if "subtopics" not in tree:
return
for subtopic in tree["subtopics"]:
Expand Down
Binary file removed playground/AI4Science.enb
Binary file not shown.
17 changes: 17 additions & 0 deletions playground/gen_sample_paper_tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from evonote.file_helper.cache_manage import save_used_cache
from evonote.testing.sample_paper import sample_paper
from evonote.transform.build_from_sections import digest_all_descendants, \
mindtree_from_doc
from evonote.data_cleaning.latex_converter import process_latex_into_standard

tex = sample_paper

doc, meta = process_latex_into_standard(tex)

paper_tree = mindtree_from_doc(doc, meta)

digest_tree = digest_all_descendants(paper_tree)

digest_tree.save("AI4Science.enb")

save_used_cache()
3 changes: 3 additions & 0 deletions playground/persistence.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os

from evonote.mindtree import Tree

os.system("python gen_sample_paper_tree.py")
tree = Tree.load("AI4Science.enb")

tree.show_tree_gui()
3 changes: 3 additions & 0 deletions playground/search_in_mindtree.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os

from evonote.mindtree import Tree

os.system("python gen_sample_paper_tree.py")
tree = Tree.load("AI4Science.enb")

keyword = "quantum computing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import os

from evonote import debug
from evonote.transform.build_from_sections import digest_all_descendants
from evonote.transform.tree_to_paragraph import tree_to_paragraph
from evonote.mindtree import Tree


with debug.display_chats():
os.system("python gen_sample_paper_tree.py")
tree = Tree.load("AI4Science.enb")
keyword = "quantum computing"
tree = tree.get_sub_tree_by_similarity([keyword], top_k=6)
res = tree_to_paragraph(tree,
f"You should focus on writing about {keyword}")

# Refactor the tree

new_tree = Tree(keyword)
print(res)
new_tree = Tree()
note = new_tree.get_new_note_by_path([keyword])
note.be(res)
new_tree = digest_all_descendants(new_tree)
Expand Down
29 changes: 5 additions & 24 deletions playground/visualize_paper.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
from evonote.file_helper.cache_manage import save_used_cache, save_cache
from evonote.testing.sample_paper import sample_paper
from evonote.transform.build_from_sections import digest_all_descendants, \
mindtree_from_doc
from evonote.data_cleaning.latex_converter import process_latex_into_standard
import os

from evonote.mindtree import Tree

tex = sample_paper

doc, meta = process_latex_into_standard(tex)

paper_tree = mindtree_from_doc(doc, meta)

digest_tree = digest_all_descendants(paper_tree)

# Try removing comments to show the tree before digesting

# paper_tree.show_tree_gui()

digest_tree.show_tree_gui()

save_used_cache()

# Try removing comments to save the tree

digest_tree.save("AI4Science.enb")
os.system("python gen_sample_paper_tree.py")
tree = Tree.load("AI4Science.enb")
tree.show_tree_gui()

0 comments on commit 24c35ba

Please sign in to comment.