diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index d1df529..5472eef 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -4,7 +4,7 @@ on: - main paths: - evonote/** - - doc_in_py/** + - docinpy/** env: OPENAI_API_KEY: NAN diff --git a/docinpy/README.md b/docinpy/README.md new file mode 100644 index 0000000..0101d60 --- /dev/null +++ b/docinpy/README.md @@ -0,0 +1,11 @@ + +See [DocInPy](https://evonote.org/docinpy) for a project overview. + +## Project todos + +- Extract variables from module and classes +- Extract comments for class variables (What should be the format of the comments?) +- Process code of function and extract comments +- TODO decorator for functions + +- Serialization from structs to Python code \ No newline at end of file diff --git a/doc_in_py/__init__.py b/docinpy/__init__.py similarity index 100% rename from doc_in_py/__init__.py rename to docinpy/__init__.py diff --git a/doc_in_py/comment_parser.py b/docinpy/comment_parser.py similarity index 99% rename from doc_in_py/comment_parser.py rename to docinpy/comment_parser.py index f140392..185a9b7 100644 --- a/doc_in_py/comment_parser.py +++ b/docinpy/comment_parser.py @@ -3,7 +3,7 @@ import re from typing import List -from doc_in_py import Struct +from docinpy import Struct """ This module is for parse and extract comments diff --git a/doc_in_py/core.py b/docinpy/core.py similarity index 99% rename from doc_in_py/core.py rename to docinpy/core.py index f1355a6..742e387 100644 --- a/doc_in_py/core.py +++ b/docinpy/core.py @@ -9,8 +9,8 @@ import yaml -from doc_in_py import Struct -from doc_in_py.comment_parser import prepare_raw_comment_struct, parse_raw_comments +from docinpy import Struct +from docinpy.comment_parser import prepare_raw_comment_struct, parse_raw_comments def get_module_members(module) -> Struct: diff --git a/doc_in_py/decorator.py b/docinpy/decorator.py similarity index 100% rename from doc_in_py/decorator.py rename to docinpy/decorator.py diff --git a/doc_in_py/docs_parser.py b/docinpy/docs_parser.py similarity index 100% rename from doc_in_py/docs_parser.py rename to docinpy/docs_parser.py diff --git a/doc_in_py/test/test_decorator.py b/docinpy/test/test_decorator.py similarity index 97% rename from doc_in_py/test/test_decorator.py rename to docinpy/test/test_decorator.py index ffb95c3..53b45aa 100644 --- a/doc_in_py/test/test_decorator.py +++ b/docinpy/test/test_decorator.py @@ -1,4 +1,4 @@ -from doc_in_py.core import get_module_members +from docinpy.core import get_module_members from utils import to_dict diff --git a/doc_in_py/test/test_module_multi.py b/docinpy/test/test_module_multi.py similarity index 96% rename from doc_in_py/test/test_module_multi.py rename to docinpy/test/test_module_multi.py index 0d1c02e..56bad63 100644 --- a/doc_in_py/test/test_module_multi.py +++ b/docinpy/test/test_module_multi.py @@ -1,4 +1,4 @@ -from doc_in_py.core import get_module_members +from docinpy.core import get_module_members from utils import to_dict diff --git a/doc_in_py/test/test_section.py b/docinpy/test/test_section.py similarity index 96% rename from doc_in_py/test/test_section.py rename to docinpy/test/test_section.py index 396a584..0c14a1b 100644 --- a/doc_in_py/test/test_section.py +++ b/docinpy/test/test_section.py @@ -1,4 +1,4 @@ -from doc_in_py.core import get_module_members +from docinpy.core import get_module_members from utils import to_dict diff --git a/doc_in_py/test/testing_module_decorator.py b/docinpy/test/testing_module_decorator.py similarity index 88% rename from doc_in_py/test/testing_module_decorator.py rename to docinpy/test/testing_module_decorator.py index 51e0554..e241805 100644 --- a/doc_in_py/test/testing_module_decorator.py +++ b/docinpy/test/testing_module_decorator.py @@ -1,4 +1,4 @@ -from doc_in_py.decorator import todo, example +from docinpy.decorator import todo, example """ # Todo for the function diff --git a/doc_in_py/test/testing_module_multi/.tree.yml b/docinpy/test/testing_module_multi/.tree.yml similarity index 100% rename from doc_in_py/test/testing_module_multi/.tree.yml rename to docinpy/test/testing_module_multi/.tree.yml diff --git a/doc_in_py/test/testing_module_multi/__init__.py b/docinpy/test/testing_module_multi/__init__.py similarity index 100% rename from doc_in_py/test/testing_module_multi/__init__.py rename to docinpy/test/testing_module_multi/__init__.py diff --git a/doc_in_py/test/testing_module_multi/a.py b/docinpy/test/testing_module_multi/a.py similarity index 100% rename from doc_in_py/test/testing_module_multi/a.py rename to docinpy/test/testing_module_multi/a.py diff --git a/doc_in_py/test/testing_module_multi/another.py b/docinpy/test/testing_module_multi/another.py similarity index 100% rename from doc_in_py/test/testing_module_multi/another.py rename to docinpy/test/testing_module_multi/another.py diff --git a/doc_in_py/test/testing_module_multi/b.py b/docinpy/test/testing_module_multi/b.py similarity index 100% rename from doc_in_py/test/testing_module_multi/b.py rename to docinpy/test/testing_module_multi/b.py diff --git a/doc_in_py/test/testing_module_multi/c.py b/docinpy/test/testing_module_multi/c.py similarity index 100% rename from doc_in_py/test/testing_module_multi/c.py rename to docinpy/test/testing_module_multi/c.py diff --git a/doc_in_py/test/testing_module_multi/d.py b/docinpy/test/testing_module_multi/d.py similarity index 100% rename from doc_in_py/test/testing_module_multi/d.py rename to docinpy/test/testing_module_multi/d.py diff --git a/doc_in_py/test/testing_module_multi/e.py b/docinpy/test/testing_module_multi/e.py similarity index 100% rename from doc_in_py/test/testing_module_multi/e.py rename to docinpy/test/testing_module_multi/e.py diff --git a/doc_in_py/test/testing_module_section.py b/docinpy/test/testing_module_section.py similarity index 100% rename from doc_in_py/test/testing_module_section.py rename to docinpy/test/testing_module_section.py diff --git a/doc_in_py/test/utils.py b/docinpy/test/utils.py similarity index 92% rename from doc_in_py/test/utils.py rename to docinpy/test/utils.py index 4333124..5aa11b9 100644 --- a/doc_in_py/test/utils.py +++ b/docinpy/test/utils.py @@ -1,4 +1,4 @@ -from doc_in_py import Struct +from docinpy import Struct def to_dict(struct: Struct): diff --git a/docs/.vuepress/config.ts b/docs/.vuepress/config.ts index 1d192e7..cc6917f 100644 --- a/docs/.vuepress/config.ts +++ b/docs/.vuepress/config.ts @@ -42,6 +42,10 @@ export default defineUserConfig({ text: 'Development', link: '/development', }, + { + text: 'DocInPy', + link: '/docinpy', + }, { text: 'Project tree', link: 'https://evonote.org/html/project_tree.html', diff --git a/docs/.vuepress/styles/index.scss b/docs/.vuepress/styles/index.scss index b00d355..baaf73e 100644 --- a/docs/.vuepress/styles/index.scss +++ b/docs/.vuepress/styles/index.scss @@ -26,7 +26,7 @@ --c-border-dark: #dfe2e5; // custom container colors - --c-tip: #4a8ee5; + --c-tip: #5d98e1; --c-tip-bg: var(--c-bg-light); --c-tip-title: var(--c-text); --c-tip-text: var(--c-text); @@ -171,7 +171,7 @@ html.dark { --c-border-dark: #34404c; // custom container colors - --c-tip: #318a62; + --c-tip: #5d83a8; --c-warning: #e0ad15; --c-warning-bg: #2d2f2d; --c-warning-bg-light: #423e2a; diff --git a/docs/README.md b/docs/README.md index 097ecc4..fd3a8c1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,22 @@ +## Website development setup + +Install pnpm +```shell +curl -fsSL https://get.pnpm.io/install.sh | sh - +``` + +Install dependencies +```shell +pnpm i +``` + Dev mode for the docs ```shell pnpm docs:dev ``` -If you want to edit the sidebars: See `.vuepress/config.ts`. \ No newline at end of file +## Website content development + +Edit sidebars + +- See `.vuepress/config.ts`. \ No newline at end of file diff --git a/docs/development/index.md b/docs/development/index.md index 9f4b719..d980bd8 100644 --- a/docs/development/index.md +++ b/docs/development/index.md @@ -6,7 +6,7 @@ Docstring style: rst ## DocInPy -Please use the [DocInPy](https://github.com/EvoEvolver/EvoNote/tree/main/doc_in_py) style for adding sections in the codes. +Please use the [DocInPy](https://github.com/EvoEvolver/EvoNote/tree/main/docinpy) style for adding sections in the codes. ## Installation diff --git a/doc_in_py/README.md b/docs/docinpy/index.md similarity index 85% rename from doc_in_py/README.md rename to docs/docinpy/index.md index 5312406..6cfe520 100644 --- a/doc_in_py/README.md +++ b/docs/docinpy/index.md @@ -13,7 +13,7 @@ codebase. It is also important for AI-based agents to understand the codebase an ## EvoNote EvoNote is using DocInPy to document its codebase. You can have a good visualization of EvoNote's codebase by -running [EvoNote visualization](https://github.com/EvoEvolver/EvoNote/blob/main/playground/visualize_paper.py). +running [EvoNote visualization](/html/project_tree.html). ## How to use @@ -82,12 +82,31 @@ def baz(): pass ``` +### Section in folder + +You add `.tree.yml` file in a folder to add sections in it. For example, in the following folder +``` +a_folder +- __init__.py +- a.py +- b.py +- c.py +- .tree.yml +``` +You can put `a`,`b` in a section by putting +```yaml +sections +``` + + + + ### Mark examples You can also add examples to your functions and classes. Just use the `@example` decorator. For example, ```python -from doc_in_py.decorator import example +from docinpy.decorator import example @example @@ -104,7 +123,7 @@ def how_to_use_foo(): In a similar way, you can also mark todos in your code. Just use the `@todo` decorator. For example, ```python -from doc_in_py.decorator import todo +from docinpy.decorator import todo @todo def todo_foo(): @@ -119,14 +138,6 @@ def buggy_foo(): foo(a=b) ``` -## Project todos - -- Extract variables from module and classes -- Extract comments for class variables (What should be the format of the comments?) -- Process code of function and extract comments -- TODO decorator for functions - -- Serialization from structs to Python code ## Philosophy behind DocInPy @@ -143,4 +154,4 @@ structure. DocInPy helps this by adding a zero-cost way to add sections to your functions and classes. It makes another step towards a more tree-like structure of the codebase. We believe this will help the programmers to understand the codebase -better. See [Method of Loci](docs/introduction/2.1 Method of Loci.md) for more details. \ No newline at end of file +better. See [Method of Loci](/writings/2.1%20Method%20of%20Loci%20and%20sparsity.html) for more details. \ No newline at end of file diff --git a/evonote/.tree.yml b/evonote/.tree.yml index 07f200c..463c6bc 100644 --- a/evonote/.tree.yml +++ b/evonote/.tree.yml @@ -1,6 +1,13 @@ sections: - core: - - notetree + Core: + - mindtree - indexing + Auxiliary: - file_helper - - model \ No newline at end of file + - model + - gui + - testing + Applications: + - agent + - transform + - data_cleaning \ No newline at end of file diff --git a/evonote/agent/general.py b/evonote/agent/general.py index ce151d0..a4dafd0 100644 --- a/evonote/agent/general.py +++ b/evonote/agent/general.py @@ -1,9 +1,9 @@ -from evonote.notetree import Tree +from evonote.mindtree import Tree class AgentState: def __init__(self): - self.root_notetree = Tree( - "root notetree that indexes all available notetrees") + self.root_tree = Tree( + "root tree that indexes all available trees") self.objective_stack = [] self.logs = [] diff --git a/evonote/gui/notetree.py b/evonote/gui/mindtree.py similarity index 83% rename from evonote/gui/notetree.py rename to evonote/gui/mindtree.py index 1c47570..81ffe41 100644 --- a/evonote/gui/notetree.py +++ b/evonote/gui/mindtree.py @@ -8,7 +8,7 @@ from evonote.gui.utlis import hypenate_texts if TYPE_CHECKING: - from evonote.notetree import Note, Tree + from evonote.mindtree import Note, Tree h_en = Hyphenator('en_US') @@ -52,12 +52,12 @@ def get_json_for_treemap(root: Note): def prepare_tree_parameters(root): - notetree = root.notetree + mindtree = root.tree labels = [] parents = [] texts = [] ids = [] - add_note_to_list(labels, parents, texts, ids, root, notetree) + add_note_to_list(labels, parents, texts, ids, root, mindtree) line_width = 40 for i in range(len(texts)): if len(texts[i].strip()) == 0: @@ -67,15 +67,15 @@ def prepare_tree_parameters(root): return ids, labels, parents, texts -def add_note_to_list(labels, parents, values, ids, note: Note, notetree: Tree): +def add_note_to_list(labels, parents, values, ids, note: Note, mindtree: Tree): i = 1 - children = notetree.get_children_dict(note) + children = mindtree.get_children_dict(note) for key, child in children.items(): - notepath = notetree.get_note_path(child) + notepath = mindtree.get_note_path(child) label = str(i) + ". " + key if len(children) > 1 else key labels.append(label) parents.append("/".join(notepath[:-1])) values.append(child.content) ids.append("/".join(notepath)) - add_note_to_list(labels, parents, values, ids, child, notetree) + add_note_to_list(labels, parents, values, ids, child, mindtree) i += 1 diff --git a/evonote/indexing/code_indexer.py b/evonote/indexing/code_indexer.py index a736a07..ed137eb 100644 --- a/evonote/indexing/code_indexer.py +++ b/evonote/indexing/code_indexer.py @@ -2,7 +2,7 @@ from typing import List from evonote.indexing.core import AbsEmbeddingIndexer, Indexing -from evonote.notetree import Note +from evonote.mindtree import Note class CodeParameterIndexer(AbsEmbeddingIndexer): diff --git a/evonote/indexing/core.py b/evonote/indexing/core.py index 19f8c11..b46f566 100644 --- a/evonote/indexing/core.py +++ b/evonote/indexing/core.py @@ -10,8 +10,8 @@ from evonote.model.chat import Chat if TYPE_CHECKING: - from evonote.notetree import Note - from evonote.notetree import Tree + from evonote.mindtree import Note + from evonote.mindtree import Tree from evonote.file_helper.cache_manage import save_cache, cached_function from evonote.model.openai import get_embeddings @@ -41,11 +41,11 @@ def remove_note(cls, note: Note): class Indexing: def __init__(self, notes: List[Note], indexer: Type[Indexer], - notetree: Tree): + tree: Tree): self.notes_without_indexer: List[Note] = notes[:] self.indexer: Type[Indexer] = indexer self.data: Any = None - self.notetree = notetree + self.tree = tree def add_new_note(self, note: Note): self.notes_without_indexer.append(note) @@ -223,7 +223,7 @@ class FragmentedEmbeddingIndexer(AbsEmbeddingIndexer): def process_note_with_content(cls, notes: List[Note], indexing: Indexing, ): notes_content = [note.content for note in notes] - notetree = indexing.notetree + tree = indexing.tree new_src_list = [] new_weights = [] @@ -233,9 +233,9 @@ def process_note_with_content(cls, notes: List[Note], indexing: Indexing, executor.map(process_sent_into_frags, notes_content)): new_src = [] new_src.extend(frags) - note_path = notetree.get_note_path(note) + note_path = tree.get_note_path(note) if len(note_path) > 0: - new_src.append(notetree.get_note_path(note)[-1]) + new_src.append(tree.get_note_path(note)[-1]) new_src.append(note.content) new_src_list.append(new_src) @@ -274,13 +274,13 @@ def process_note_without_content(cls, notes: List[Note], indexing: Indexing, def prepare_src_weight_list(cls, new_notes: List[Note], indexing: Indexing, ): - notetree = indexing.notetree + tree = indexing.tree notes_with_content = [] notes_content = [] notes_without_content = [] for note in new_notes: if len(note.content) == 0: - keywords_on_path = notetree.get_note_path(note) + keywords_on_path = tree.get_note_path(note) if len(keywords_on_path) != 0: notes_without_content.append(note) continue diff --git a/evonote/notetree/__init__.py b/evonote/mindtree/__init__.py similarity index 100% rename from evonote/notetree/__init__.py rename to evonote/mindtree/__init__.py diff --git a/evonote/notetree/analysis.py b/evonote/mindtree/analysis.py similarity index 79% rename from evonote/notetree/analysis.py rename to evonote/mindtree/analysis.py index 42d4e6f..f24c536 100644 --- a/evonote/notetree/analysis.py +++ b/evonote/mindtree/analysis.py @@ -1,11 +1,11 @@ -from evonote.notetree import Tree +from evonote.mindtree import Tree -def analyze_notetree_sparsity(notetree: Tree): +def analyze_tree_sparsity(tree: Tree): """ Return the average number of children per note. """ - notes = notetree.get_note_list() + notes = tree.get_note_list() max_children = -1 total_children = 0 n_non_leaf_notes = 0 @@ -16,7 +16,7 @@ def analyze_notetree_sparsity(notetree: Tree): total_children += n_children max_children = max(max_children, n_children) average_children = total_children / n_non_leaf_notes - heavy_notes = get_children_heavy_notes(notetree) + heavy_notes = get_children_heavy_notes(tree) print("Total_notes:", len(notes)) print("Average children per non-leaf note:", average_children) print("Max children per note:", max_children) @@ -27,11 +27,11 @@ def analyze_notetree_sparsity(notetree: Tree): print("Content:", note.content) print("") -def get_children_heavy_notes(notetree: Tree, min_children=8): +def get_children_heavy_notes(tree: Tree, min_children=8): """ Return a list of notes with at least min_children children. """ - notes = notetree.get_note_list() + notes = tree.get_note_list() heavy_notes = [] for note in notes: n_children = len(note.children()) diff --git a/evonote/mindtree/bookshelf.py b/evonote/mindtree/bookshelf.py new file mode 100644 index 0000000..bef6f0e --- /dev/null +++ b/evonote/mindtree/bookshelf.py @@ -0,0 +1,21 @@ +from typing import List + +from evonote.mindtree import Note +from evonote.mindtree import Tree + + +class Bookshelf(Tree): + def __init__(self, root_content): + super().__init__(root_content) + + def add_mindtree_by_path(self, path: List[str], tree: Tree): + note = get_note_for_mindtree(tree, self) + self.add_note_by_path(path, note) + return note + + +def get_note_for_mindtree(tree: Tree, default_tree: Tree) -> Note: + note = Note(default_tree) + note.resource.add_tree(tree, tree.topic) + note.be("A tree with root_content: " + tree.topic) + return note diff --git a/evonote/notetree/note.py b/evonote/mindtree/note.py similarity index 81% rename from evonote/notetree/note.py rename to evonote/mindtree/note.py index 9ec74cc..ce2d282 100644 --- a/evonote/notetree/note.py +++ b/evonote/mindtree/note.py @@ -4,12 +4,12 @@ from typing import TYPE_CHECKING, Dict if TYPE_CHECKING: - from evonote.notetree import Tree + from evonote.mindtree import Tree class Note: """ - A tree-like data structure that stores notetree + A tree-like data structure that stores tree usually for the direct summary of paragraphs The relation of the items are mainly represented by the tree structure @@ -18,18 +18,18 @@ class Note: Notice that Note object can be indexed by embedding vectors because its """ - def __init__(self, notetree: Tree): + def __init__(self, tree: Tree): super().__init__() # content is string no matter what _content_type is self.content: str = "" - # The root note helps merge two notetree bases - self.notetree: Tree = notetree + # The root note helps merge two tree bases + self.tree: Tree = tree # The resource is the data that is indicated by the note self.resource: NoteResource = NoteResource() - def copy_to(self, notetree: Tree): - new_note = Note(notetree) + def copy_to(self, tree: Tree): + new_note = Note(tree) new_note.content = copy(self.content) new_note.resource = copy(self.resource) return new_note @@ -39,13 +39,13 @@ def copy_to(self, notetree: Tree): """ def note_path(self): - return self.notetree.get_note_path(self) + return self.tree.get_note_path(self) def parent(self): - return self.notetree.get_parent(self) + return self.tree.get_parent(self) def children(self) -> Dict[str, Note]: - return self.notetree.get_children_dict(self) + return self.tree.get_children_dict(self) def title(self) -> str: note_path = self.note_path() @@ -54,19 +54,19 @@ def title(self) -> str: return note_path[-1] def has_child(self, key: str): - return self.notetree.has_child(self, key) + return self.tree.has_child(self, key) """ ## Functions for adding children of note """ def add_child(self, key: str, note) -> Note: - self.notetree.add_child(key, self, note) + self.tree.add_child(key, self, note) return note def new_child(self, key: str) -> Note: - note = Note(self.notetree) - self.notetree.add_child(key, self, note) + note = Note(self.tree) + self.tree.add_child(key, self, note) return note """ @@ -79,12 +79,12 @@ def s(self, key) -> Note: :param key: the key of the child note :return: """ - notetree = self.notetree + tree = self.tree if isinstance(key, int) or isinstance(key, str): - children = notetree.get_children_dict(self) + children = tree.get_children_dict(self) if key not in children: - note = Note(notetree) - notetree.add_child(key, self, note) + note = Note(tree) + tree.add_child(key, self, note) return note return children[key] else: @@ -158,8 +158,8 @@ def add_resource(self, resource, resource_type: str, key: str): def add_text(self, text, key: str): self.add_resource(text, "text", key) - def add_notetree(self, notetree, key: str): - self.add_resource(notetree, "notetree", key) + def add_tree(self, tree, key: str): + self.add_resource(tree, "tree", key) def add_function(self, function, key: str): self.add_resource(function, "function", key) diff --git a/evonote/notetree/tree.py b/evonote/mindtree/tree.py similarity index 81% rename from evonote/notetree/tree.py rename to evonote/mindtree/tree.py index c418b4a..ad247c0 100644 --- a/evonote/notetree/tree.py +++ b/evonote/mindtree/tree.py @@ -5,10 +5,10 @@ import dill from bidict import bidict -from evonote.gui.notetree import draw_treemap +from evonote.gui.mindtree import draw_treemap from evonote.indexing.core import FragmentedEmbeddingIndexer from evonote.indexing.core import Indexing, Indexer -from evonote.notetree.note import Note +from evonote.mindtree.note import Note class Tree: @@ -19,14 +19,14 @@ class Tree: :cvar children: The children of each note :cvar note_path: The path of each note - :cvar indexings: The dict for indexings made for the notetree + :cvar indexings: The dict for indexings made for the tree The key is the class of the indexer and the value is the indexing """ def __init__(self, root_content, rule_of_path: str = None): """ - :param root_content: The content of the root of the notetree + :param root_content: The content of the root of the tree :param rule_of_path: The rule for creating paths. """ self.children: Dict[Note, Dict[str, Note]] = {} @@ -41,7 +41,7 @@ def __init__(self, root_content, rule_of_path: str = None): self.note_path[root] = tuple() root.set_content(root_content) - # TODO: this can be note, notetree, or string in the future + # TODO: this can be note, tree, or string in the future self.rule_of_path = rule_of_path @@ -140,7 +140,7 @@ def get_note_list(self): return list(self.note_path.keys()) def add_child(self, key: str, parent: Note, child: Note): - if child.notetree is not self: + if child.tree is not self: child = child.copy_to(self) if child not in self.children: self.children[child] = {} @@ -164,8 +164,8 @@ def add_child(self, key: str, parent: Note, child: Note): def remove_note(self, note: Note): """ Remove a note from the tree - This will remove all the indexing data of the notetree - It is better to create another notetree that removing a note + This will remove all the indexing data of the tree + It is better to create another tree that removing a note :param note: :return: """ @@ -186,10 +186,10 @@ def remove_note(self, note: Note): indexing.remove_note(note) """ - ## Representation of notetree in prompt + ## Representation of tree in prompt """ - def get_notetree_dict(self, add_index=True): + def get_tree_dict(self, add_index=True): tree = { "subtopics": {}, } @@ -212,7 +212,7 @@ def get_notetree_dict(self, add_index=True): return tree, note_indexed def get_dict_for_prompt(self): - dict_without_indices, note_indexed = self.get_notetree_dict(add_index=False) + dict_without_indices, note_indexed = self.get_tree_dict(add_index=False) delete_extra_keys_for_prompt(dict_without_indices) return dict_without_indices @@ -228,22 +228,22 @@ def get_path_content_str_for_prompt(self): return "\n".join(res) def get_dict_with_indices_for_prompt(self): - dict_with_indices, note_indexed = self.get_notetree_dict() + dict_with_indices, note_indexed = self.get_tree_dict() delete_extra_keys_for_prompt(dict_with_indices) return dict_with_indices, note_indexed """ - ## Visualization of notetree + ## Visualization of tree """ - def show_notetree_gui(self): + def show_tree_gui(self): """ - Show the notetree in a webpage + Show the tree in a webpage """ draw_treemap(self.root) """ - ## Sub-notetree extraction + ## Sub-tree extraction """ def get_notes_by_similarity(self, query_list: List[str], @@ -262,33 +262,33 @@ def get_notes_by_similarity(self, query_list: List[str], return top_k_notes - def get_sub_notetree_by_similarity(self, query_list: List[str], - weights: List[float] | None = None, - top_k: int = 10, - note_filter: Callable[[Note], bool] = None, - indexer_class: Type[Indexer] = None - ) -> Tree: + def get_sub_tree_by_similarity(self, query_list: List[str], + weights: List[float] | None = None, + top_k: int = 10, + note_filter: Callable[[Note], bool] = None, + indexer_class: Type[Indexer] = None + ) -> Tree: top_k_descendants = self.get_notes_by_similarity(query_list, weights, top_k, note_filter, indexer_class) - new_notetree = new_notetree_from_note_subset(top_k_descendants, self) - return new_notetree + new_tree = new_tree_from_note_subset(top_k_descendants, self) + return new_tree - def duplicate_notetree_by_note_mapping(self, note_mapping: Callable[ + def duplicate_tree_by_note_mapping(self, note_mapping: Callable[ [Note, Tree], Note]) -> Tree: """ - Duplicate the notetree by mapping each note to a new note - It can also be used for creating a copy of the notetree + Duplicate the tree by mapping each note to a new note + It can also be used for creating a copy of the tree :param note_mapping: The mapping function for each note - :return: A new notetree + :return: A new tree """ - new_notetree = Tree(self.topic, rule_of_path=self.rule_of_path) + new_tree = Tree(self.topic, rule_of_path=self.rule_of_path) for note in self.get_note_list(): new_path = self.get_note_path(note) - new_notetree.add_note_by_path(new_path, note_mapping(note, new_notetree)) - return new_notetree + new_tree.add_note_by_path(new_path, note_mapping(note, new_tree)) + return new_tree """ - ## Persistence of the notetree + ## Persistence of the tree """ def save(self, path: str, save_indexing: bool = False): @@ -309,8 +309,8 @@ def save(self, path: str, save_indexing: bool = False): def load(path: str) -> Tree: # TODO: We need to test this function and make sure it works with open(path, "rb") as f: - notetree = dill.load(f) - return notetree + tree = dill.load(f) + return tree def __repr__(self): return f"<{self.__class__.__name__}> {self.root.content!r}" @@ -321,11 +321,11 @@ def __repr__(self): """ -def new_notetree_from_note_subset(notes: List[Note], notetree: Tree) -> Tree: - new_notetree = Tree(root_content=notetree.topic) +def new_tree_from_note_subset(notes: List[Note], tree: Tree) -> Tree: + new_tree = Tree(root_content=tree.topic) for note in notes: - new_notetree.add_note_by_path(notetree.get_note_path(note), note) - return new_notetree + new_tree.add_note_by_path(tree.get_note_path(note), note) + return new_tree def delete_extra_keys_for_prompt(tree): diff --git a/evonote/notetree/bookshelf.py b/evonote/notetree/bookshelf.py deleted file mode 100644 index cd3c45b..0000000 --- a/evonote/notetree/bookshelf.py +++ /dev/null @@ -1,21 +0,0 @@ -from typing import List - -from evonote.notetree import Note -from evonote.notetree import Tree - - -class Bookshelf(Tree): - def __init__(self, root_content): - super().__init__(root_content) - - def add_notetree_by_path(self, path: List[str], notetree: Tree): - note = get_note_for_notetree(notetree, self) - self.add_note_by_path(path, note) - return note - - -def get_note_for_notetree(notetree: Tree, default_notetree: Tree) -> Note: - note = Note(default_notetree) - note.resource.add_notetree(notetree, notetree.topic) - note.be("A notetree with root_content: " + notetree.topic) - return note diff --git a/evonote/search/code_searcher.py b/evonote/search/code_searcher.py index 57a4a09..c7676d5 100644 --- a/evonote/search/code_searcher.py +++ b/evonote/search/code_searcher.py @@ -1,9 +1,9 @@ from evonote.indexing.code_indexer import CodeDocsIndexer from evonote.model.chat import Chat -from evonote.notetree import Tree +from evonote.mindtree import Tree """ -This module contains functions for searching in notetrees of python functions. +This module contains functions for searching in mind trees of python functions. The python functions can be indexed by their docstrings, function names, parameter names, return values, etc. """ @@ -35,18 +35,18 @@ def possible_docstring(description: str): return res -def search_function(description: str, notetree: Tree, top_k=10): +def search_function(description: str, tree: Tree, top_k=10): """ Plan: TODO 1. Imagine the docstring of the function by the description 2. Imagine the function name by the description 3. Imagine the parameter names by the description 4. Imagine the return value by the description - 5. Search the notetree by the above 4 things with CodeDocsIndexer, CodeParamIndexer, CodeReturnIndexer + 5. Search the tree by the above 4 things with CodeDocsIndexer, CodeParamIndexer, CodeReturnIndexer """ names = possible_function_names(description) docstring = possible_docstring(description) query_keys = names + [docstring] - return notetree.get_sub_notetree_by_similarity(query_keys, top_k=top_k, - indexer_class=CodeDocsIndexer) + return tree.get_sub_tree_by_similarity(query_keys, top_k=top_k, + indexer_class=CodeDocsIndexer) diff --git a/evonote/search/fine_searcher.py b/evonote/search/fine_searcher.py index e609712..2a910cb 100644 --- a/evonote/search/fine_searcher.py +++ b/evonote/search/fine_searcher.py @@ -4,24 +4,24 @@ from evonote.file_helper.cache_manage import cached_function from evonote.model.chat import Chat -from evonote.notetree.tree import Tree, new_notetree_from_note_subset +from evonote.mindtree.tree import Tree, new_tree_from_note_subset """ -This module is for fine-grained search. The object notetree will be put in the prompt and LLM can select useful notes by a certain criteria. +This module is for fine-grained search. The object tree will be put in the prompt and LLM can select useful notes by a certain criteria. However, fine-grained search should not be adopted because it is slow and expensive. """ system_message = "You are a helpful processor for NLP problems. Output answer concisely as if you are a computer program." -@cached_function("notetree_filtering") -def filter_notetree_indices(notetree_yaml, criteria_prompt) -> \ +@cached_function("tree_filtering") +def filter_tree_indices(tree_yaml, criteria_prompt) -> \ List[int]: prompt = f"You are working on filtering notes in a database according to its content and the path it is stored. The databased is stored in a YAML file, with each note labelled by an index." \ f"\n{criteria_prompt}" chat = Chat( user_message=prompt, system_message=system_message) - chat.add_user_message("The database: \n" + notetree_yaml) + chat.add_user_message("The database: \n" + tree_yaml) chat.add_user_message( f"Output the indices of the notes that satisfies the criteria with indices " f"separated by comma (output none when none matches): \n" @@ -51,20 +51,20 @@ def filter_notetree_indices(notetree_yaml, criteria_prompt) -> \ return useful_indices -def filter_notetree_in_group(notetree: Tree, criteria_prompt: str) -> Tree: - tree_with_indices, note_indexed = notetree.get_dict_with_indices_for_prompt() +def filter_tree_in_group(tree: Tree, criteria_prompt: str) -> Tree: + tree_with_indices, note_indexed = tree.get_dict_with_indices_for_prompt() tree_in_yaml = yaml.dump(tree_with_indices) - useful_indices = filter_notetree_indices(tree_in_yaml, criteria_prompt) + useful_indices = filter_tree_indices(tree_in_yaml, criteria_prompt) useful_notes = [note_indexed[i] for i in useful_indices] - filtered = new_notetree_from_note_subset(useful_notes, notetree) + filtered = new_tree_from_note_subset(useful_notes, tree) return filtered -def keyword_filter(notetree: Tree, keywords: List[str]): +def keyword_filter(tree: Tree, keywords: List[str]): if len(keywords) > 1: prompt = "The note is related to all of the following keywords: " + ",".join( keywords) else: prompt = "The note is related to the following keyword: " + keywords[0] - return filter_notetree_in_group(notetree, - prompt) + return filter_tree_in_group(tree, + prompt) diff --git a/evonote/search/multi_notebook.py b/evonote/search/multi_notebook.py deleted file mode 100644 index c066845..0000000 --- a/evonote/search/multi_notebook.py +++ /dev/null @@ -1,18 +0,0 @@ -from typing import List - -from evonote.notetree import Tree -from evonote.search.fine_searcher import filter_notetree_in_group - - -def search_related_notetree_to_store(content_to_store, bookshelf: Tree) -> List[ - Tree]: - criteria_prompt = ("Whether the note describes a notetree " - "that is suitable for storing the following content:") - criteria_prompt += f"\n{content_to_store}" - sub_bookshelf = filter_notetree_in_group(bookshelf, criteria_prompt) - res = [] - for note in sub_bookshelf.children: - if note.resource.has_type("notetree"): - notetree = note.resource.get_resource_by_type("notetree") - res.append(notetree) - return res diff --git a/evonote/search/multi_tree.py b/evonote/search/multi_tree.py new file mode 100644 index 0000000..1e4244f --- /dev/null +++ b/evonote/search/multi_tree.py @@ -0,0 +1,18 @@ +from typing import List + +from evonote.mindtree import Tree +from evonote.search.fine_searcher import filter_tree_in_group + + +def search_related_tree_to_store(content_to_store, bookshelf: Tree) -> List[ + Tree]: + criteria_prompt = ("Whether the note describes a tree " + "that is suitable for storing the following content:") + criteria_prompt += f"\n{content_to_store}" + sub_bookshelf = filter_tree_in_group(bookshelf, criteria_prompt) + res = [] + for note in sub_bookshelf.children: + if note.resource.has_type("tree"): + tree = note.resource.get_resource_by_type("tree") + res.append(tree) + return res diff --git a/evonote/search/question_answer.py b/evonote/search/question_answer.py index db79ba7..17ed9a6 100644 --- a/evonote/search/question_answer.py +++ b/evonote/search/question_answer.py @@ -1,8 +1,8 @@ from typing import List from evonote.model.chat import Chat -from evonote.notetree import Tree -from evonote.search.fine_searcher import filter_notetree_in_group +from evonote.mindtree import Tree +from evonote.search.fine_searcher import filter_tree_in_group from evonote.utils import robust_json_parse, multi_attempts @@ -20,10 +20,10 @@ def __init__(self, objective, parent=None): @multi_attempts -def single_notetree_qa_agent(question: str, knowledge_base: Tree): +def single_tree_qa_agent(question: str, knowledge_base: Tree): """ :param question: The question - :param knowledge_base: The notetree to search + :param knowledge_base: The tree to search :return: The answer """ working_memory = Tree("Working Tree") @@ -136,19 +136,19 @@ def imagine_answer(query: str, n_fragments=3): return res -def search(query: str, notetree: Tree): +def search(query: str, tree: Tree): imagined_answer = imagine_answer(query)["fragments"] - sub_notetree = notetree.get_sub_notetree_by_similarity(imagined_answer, top_k=10) - sub_notetree = filter_notetree_in_group(sub_notetree, + sub_tree = tree.get_sub_tree_by_similarity(imagined_answer, top_k=10) + sub_tree = filter_tree_in_group(sub_tree, "The note answers the search query:" + query) - return sub_notetree + return sub_tree @multi_attempts -def answer(question: str, notetree: Tree): - sub_notetree = search(question, notetree) +def answer(question: str, tree: Tree): + sub_tree = search(question, tree) prompt = f"""Here is some items obtained from a knowledge base. The context of the items are implied by their path. -{sub_notetree.get_path_content_str_for_prompt()}""" +{sub_tree.get_path_content_str_for_prompt()}""" chat = Chat(user_message=prompt) chat.add_user_message(f"""Please analyze and give an answer to the question: {question} @@ -163,9 +163,9 @@ def answer(question: str, notetree: Tree): if __name__ == "__main__": import evonote.debug as debug - from evonote.testing.testing_trees.loader import load_sample_notetree + from evonote.testing.testing_trees.loader import load_sample_tree - dingzhen_world = load_sample_notetree("dingzhen_world") + dingzhen_world = load_sample_tree("dingzhen_world") # question = "Who is the pet of the president of the republic of Ganzi?" question = "What is the relation between Dingzhen and Zhenzhu the horse?" - single_notetree_qa_agent(question, dingzhen_world) + single_tree_qa_agent(question, dingzhen_world) diff --git a/evonote/test/notetree/test_notebook_basic.py b/evonote/test/notetree/test_notebook_basic.py index ba948cb..8aa7517 100644 --- a/evonote/test/notetree/test_notebook_basic.py +++ b/evonote/test/notetree/test_notebook_basic.py @@ -1,23 +1,23 @@ -from evonote.notetree import Tree -from evonote.testing.testing_trees.loader import load_sample_notetree +from evonote.mindtree import Tree +from evonote.testing.testing_trees.loader import load_sample_tree def test_adding_and_parent(): - notetree = Tree("test") - note1 = notetree.get_new_note_by_path(["a", "b", "c"]).be("test1") - note2 = notetree.add_note_by_path(["a", "b", "d"], "test2") - note3 = notetree.get_note_by_path(["a", "b"]).be("test3") + tree = Tree("test") + note1 = tree.get_new_note_by_path(["a", "b", "c"]).be("test1") + note2 = tree.add_note_by_path(["a", "b", "d"], "test2") + note3 = tree.get_note_by_path(["a", "b"]).be("test3") assert note1.parent().content == "test3" == note3.content == note2.parent().content def test_adding_twice(): - notetree = Tree("test") - notetree.get_new_note_by_path(["a", "b", "c"]).be("test1") - notetree.add_note_by_path(["a", "b", "c"], "test2") - assert notetree.get_note_by_path(["a", "b", "c"]).content == "test2" + tree = Tree("test") + tree.get_new_note_by_path(["a", "b", "c"]).be("test1") + tree.add_note_by_path(["a", "b", "c"], "test2") + assert tree.get_note_by_path(["a", "b", "c"]).content == "test2" -def test_notetree_copy(): - notetree = load_sample_notetree("dingzhen_world.json") - notetree2 = notetree.duplicate_notetree_by_note_mapping(lambda note, new_notetree: note) - assert notetree2.get_dict_for_prompt() == notetree.get_dict_for_prompt() \ No newline at end of file +def test_tree_copy(): + tree = load_sample_tree("dingzhen_world.json") + tree2 = tree.duplicate_tree_by_note_mapping(lambda note, new_tree: note) + assert tree2.get_dict_for_prompt() == tree.get_dict_for_prompt() \ No newline at end of file diff --git a/evonote/testing/testing_modules/v_lab/beaker.py b/evonote/testing/testing_modules/v_lab/beaker.py index 192b723..71eec85 100644 --- a/evonote/testing/testing_modules/v_lab/beaker.py +++ b/evonote/testing/testing_modules/v_lab/beaker.py @@ -1,4 +1,4 @@ -from doc_in_py.decorator import example +from docinpy.decorator import example class Beaker: diff --git a/evonote/testing/testing_modules/v_lab/operation.py b/evonote/testing/testing_modules/v_lab/operation.py index 24ca8bc..a19210d 100644 --- a/evonote/testing/testing_modules/v_lab/operation.py +++ b/evonote/testing/testing_modules/v_lab/operation.py @@ -1,4 +1,4 @@ -from doc_in_py.decorator import example, todo +from docinpy.decorator import example, todo from evonote.testing.testing_modules.v_lab.beaker import Beaker """ diff --git a/evonote/testing/testing_trees/loader.py b/evonote/testing/testing_trees/loader.py index 8eee96a..a921564 100644 --- a/evonote/testing/testing_trees/loader.py +++ b/evonote/testing/testing_trees/loader.py @@ -1,22 +1,22 @@ import os from evonote.data_cleaning.document import Document -from evonote.notetree import Tree -from evonote.transform.build_from_sections import notetree_from_doc +from evonote.mindtree import Tree +from evonote.transform.build_from_sections import mindtree_from_doc curr_dir = os.path.dirname(os.path.abspath(__file__)) -def load_sample_notetree(path: str) -> Tree: +def load_sample_tree(path: str) -> Tree: """ Args: path: The relative path to the json file. Returns: - The notetree loaded from the json file. + The tree loaded from the json file. """ if not path.endswith(".json"): path += ".json" doc = Document.from_json(os.path.join(curr_dir, path)) - notetree = notetree_from_doc(doc, {'title': doc.title}) - return notetree + tree = mindtree_from_doc(doc, {'title': doc.title}) + return tree diff --git a/evonote/transform/build_from_sections.py b/evonote/transform/build_from_sections.py index a08fb7d..e08c346 100644 --- a/evonote/transform/build_from_sections.py +++ b/evonote/transform/build_from_sections.py @@ -6,14 +6,14 @@ from evonote.data_cleaning.document import Document from evonote.file_helper.cache_manage import save_cache, cached_function from evonote.model.chat import Chat -from evonote.notetree import Note -from evonote.notetree import Tree +from evonote.mindtree import Note +from evonote.mindtree import Tree -def notetree_from_doc(doc: Document, meta) -> Tree: - notetree = Tree(meta["title"]) - build_from_sections(doc, notetree.root) - return notetree +def mindtree_from_doc(doc: Document, meta) -> Tree: + mindtree = Tree(meta["title"]) + build_from_sections(doc, mindtree.root) + return mindtree def build_from_sections(doc: Document, root: Note): @@ -22,17 +22,17 @@ def build_from_sections(doc: Document, root: Note): build_from_sections(section, root.s(section.title)) -def move_original_content_to_resource(note, notetree): - new_note = Note(notetree) +def move_original_content_to_resource(note, mindtree): + new_note = Note(mindtree) if len(note.content) > 0: new_note.resource.add_text(note.content, "original_content") return new_note -def digest_all_descendants(notetree: Tree) -> Tree: - notetree = notetree.duplicate_notetree_by_note_mapping( +def digest_all_descendants(mindtree: Tree) -> Tree: + mindtree = mindtree.duplicate_tree_by_note_mapping( move_original_content_to_resource) - all_notes = notetree.get_note_list() + all_notes = mindtree.get_note_list() contents = [note.resource.get_resource_by_type("text") for note in all_notes] non_empty_contents = [] non_empty_notes = [] @@ -51,7 +51,7 @@ def digest_all_descendants(notetree: Tree) -> Tree: print("digest received ", finished, "/", len(all_notes)) save_cache() save_cache() - return notetree + return mindtree @cached_function("digest_content") def digest_content(content): diff --git a/evonote/transform/learn_by_question.py b/evonote/transform/learn_by_question.py index 7455234..c5a3c6d 100644 --- a/evonote/transform/learn_by_question.py +++ b/evonote/transform/learn_by_question.py @@ -1,5 +1,5 @@ -from evonote.notetree import Tree +from evonote.mindtree import Tree -def sub_notetree_from_question(question: str, notetree: Tree): +def sub_tree_from_question(question: str, tree: Tree): pass diff --git a/evonote/transform/module_to_notetree.py b/evonote/transform/module_to_tree.py similarity index 78% rename from evonote/transform/module_to_notetree.py rename to evonote/transform/module_to_tree.py index b825af6..d5b7709 100644 --- a/evonote/transform/module_to_notetree.py +++ b/evonote/transform/module_to_tree.py @@ -3,24 +3,24 @@ import inspect import json -from doc_in_py.core import get_module_members -from doc_in_py import Struct -from evonote.notetree import Note -from evonote.notetree import Tree -from doc_in_py.docs_parser import \ +from docinpy.core import get_module_members +from docinpy import Struct +from evonote.mindtree import Note +from evonote.mindtree import Tree +from docinpy.docs_parser import \ parse_rst_docstring, \ parse_google_docstring, Doc_parser """ -This modules is for extract the information from python modules and build a notetree for it. +This modules is for extract the information from python modules and build a tree for it. -## Get notetree for module +## Get tree for module """ -def get_notetree_for_module(module, docs_parser_type="rst"): +def get_tree_for_module(module, docs_parser_type="rst"): if docs_parser_type == "rst": docs_parser = parse_rst_docstring elif docs_parser_type == "google": @@ -28,15 +28,15 @@ def get_notetree_for_module(module, docs_parser_type="rst"): else: raise ValueError("docs_parser_type should be pycharm or vscode") module_name = module.__name__ - notetree = Tree( + tree = Tree( "Tree of module: " + module_name) module_struct = get_module_members(module) - build_notetree_for_struct(module_struct, notetree.root, docs_parser) - return notetree + build_tree_for_struct(module_struct, tree.root, docs_parser) + return tree -def build_notetree_for_struct(curr_struct: Struct, root_note: Note, - docs_parser: Doc_parser): +def build_tree_for_struct(curr_struct: Struct, root_note: Note, + docs_parser: Doc_parser): """ :param curr_struct: The struct to be added to the child of the root_note :param root_note: The root note to be filled with children from curr_struct @@ -55,17 +55,17 @@ def build_notetree_for_struct(curr_struct: Struct, root_note: Note, case "function": process_function_struct(child_struct, curr_note, docs_parser) case "module": - build_notetree_for_struct(child_struct, curr_note, docs_parser) + build_tree_for_struct(child_struct, curr_note, docs_parser) case "class": - build_notetree_for_struct(child_struct, curr_note, docs_parser) + build_tree_for_struct(child_struct, curr_note, docs_parser) case "comment": curr_note.be(curr_note.content + "\n" + child_struct.obj) case "section": - build_notetree_for_struct(child_struct, curr_note, docs_parser) + build_tree_for_struct(child_struct, curr_note, docs_parser) case "todo": - build_notetree_for_struct(child_struct, curr_note, docs_parser) + build_tree_for_struct(child_struct, curr_note, docs_parser) case "example": - build_notetree_for_struct(child_struct, curr_note, docs_parser) + build_tree_for_struct(child_struct, curr_note, docs_parser) @@ -121,5 +121,5 @@ def get_docs_in_prompt(doc_tuple): if __name__ == "__main__": from evonote.testing.testing_modules import v_lab - notetree = get_notetree_for_module(v_lab) - notetree.show_notetree_gui() + tree = get_tree_for_module(v_lab) + tree.show_tree_gui() diff --git a/evonote/transform/note_putting.py b/evonote/transform/note_putting.py index 8335fb1..633eb94 100644 --- a/evonote/transform/note_putting.py +++ b/evonote/transform/note_putting.py @@ -1,9 +1,9 @@ from typing import List -from evonote.file_helper.cache_manage import cache_manager, cached_function +from evonote.file_helper.cache_manage import cached_function from evonote.model.chat import Chat -from evonote.notetree import Note -from evonote.notetree import Tree +from evonote.mindtree import Note +from evonote.mindtree import Tree from evonote.utils import robust_json_parse system_message = "Reply everything concisely without explaination as if you are a computer program." @@ -25,25 +25,25 @@ def generate_possible_keywords(content: str, context: str): return res -def search_similar_paths(keywords, notetree: Tree): - notes = notetree.get_notes_by_similarity(keywords, top_k=5) - similar_paths = [notetree.get_note_path(note) for note in notes] +def search_similar_paths(keywords, tree: Tree): + notes = tree.get_notes_by_similarity(keywords, top_k=5) + similar_paths = [tree.get_note_path(note) for note in notes] return similar_paths def conceive_path(content: str, context: str, similar_paths: List[List[str]], - notetree: Tree): - prompt = "You are managing a notetree." - prompt += "Here is a description of the notetree:" + notetree.topic + "\n\n" + tree: Tree): + prompt = "You are managing a tree." + prompt += "Here is a description of the tree:" + tree.topic + "\n\n" prompt += "You are trying to find a path to put a new note based on its content and context." prompt += f"\nContent: {content}" if len(context) > 0: prompt += f"\nContext: {context}" chat = Chat(user_message=prompt, system_message=system_message) path_prompt = [] - if notetree.rule_of_path is not None: - path_prompt.append("The notetree has a rule of path:") - path_prompt.append(notetree.rule_of_path) + if tree.rule_of_path is not None: + path_prompt.append("The tree has a rule of path:") + path_prompt.append(tree.rule_of_path) if len(similar_paths) > 0: path_prompt.append("Here are some related paths to put the note.") for i, path in enumerate(similar_paths): @@ -62,8 +62,8 @@ def conceive_path(content: str, context: str, similar_paths: List[List[str]], return res -def put_content_to_notetree_1(content: str, context: str, path_to_put, - notetree: Tree): +def put_content_to_tree_1(content: str, context: str, path_to_put, + tree: Tree): chat = Chat(system_message=system_message) prompt = "You are managing a database of notes." @@ -75,13 +75,13 @@ def put_content_to_notetree_1(content: str, context: str, path_to_put, prompt_adding = "You want to add the above note to the following path." prompt_adding += f"\nCurrent Path: {path_to_put.join('/')}" - note_in_path = notetree.get_note_by_path(path_to_put) + note_in_path = tree.get_note_by_path(path_to_put) if len(note_in_path.content) > 0: prompt_adding += f"\nContent in current path: {note_in_path.content}" # Also show the content in parent path if it is not empty - note_in_parent_path = notetree.get_note_by_path(path_to_put[:-1]) + note_in_parent_path = tree.get_note_by_path(path_to_put[:-1]) if len(note_in_parent_path.content) > 0: prompt_adding += f"\nParent path: {path_to_put[:-1].join('/')}" prompt_adding += f"\nContent in parent path: {note_in_parent_path.content}" @@ -97,14 +97,14 @@ def put_content_to_notetree_1(content: str, context: str, path_to_put, # TODO not finished -def put_content_to_notetree(content: str, context: str, conceived_path, - notetree: Tree): +def put_content_to_tree(content: str, context: str, conceived_path, + tree: Tree): chat = Chat(system_message=system_message) prompt_adding = "You are managing a database of notes." prompt_adding += "\nYou want to add the a note to the following path." prompt_adding += f"\nCurrent Path: {'/'.join(conceived_path)}" - note_in_path = notetree.get_note_by_path(conceived_path) + note_in_path = tree.get_note_by_path(conceived_path) if note_in_path is not None and len(note_in_path.content) > 0: prompt_adding += f"\nContent in current path: {note_in_path.content}" @@ -131,22 +131,22 @@ def put_content_to_notetree(content: str, context: str, conceived_path, filename = res["title"] new_content = res["new_content"] path_for_new_note = conceived_path + [filename] - new_note = Note(notetree) + new_note = Note(tree) new_note.content = new_content print(filename, new_content, path_for_new_note) - notetree.add_note_by_path(path_for_new_note, new_note) + tree.add_note_by_path(path_for_new_note, new_note) -def add_content_to_notetree(content: str, context: str, notetree: Tree): +def add_content_to_tree(content: str, context: str, tree: Tree): # step 1: generate possible keywords # step 2: search related paths / notes # step 3: decide a path to put content keywords = generate_possible_keywords(content, context) - similar_paths = search_similar_paths(keywords, notetree) - conceived_path = conceive_path(content, context, similar_paths, notetree) + similar_paths = search_similar_paths(keywords, tree) + conceived_path = conceive_path(content, context, similar_paths, tree) print(conceived_path) - put_content_to_notetree(content, context, conceived_path, notetree) + put_content_to_tree(content, context, conceived_path, tree) if __name__ == "__main__": diff --git a/playground/analyze_project.py b/playground/analyze_project.py index cd68c43..289b743 100644 --- a/playground/analyze_project.py +++ b/playground/analyze_project.py @@ -1,6 +1,6 @@ -from evonote.notetree.analysis import analyze_notetree_sparsity +from evonote.mindtree.analysis import analyze_tree_sparsity import evonote -from evonote.transform.module_to_notetree import get_notetree_for_module +from evonote.transform.module_to_tree import get_tree_for_module -notetree = get_notetree_for_module(evonote) -analyze_notetree_sparsity(notetree) \ No newline at end of file +tree = get_tree_for_module(evonote) +analyze_tree_sparsity(tree) \ No newline at end of file diff --git a/playground/debug.py b/playground/debug.py index 4a36510..8d12a3c 100644 --- a/playground/debug.py +++ b/playground/debug.py @@ -1,6 +1,6 @@ import evonote.debug as debug from evonote.model.chat import Chat -from evonote.notetree import Tree +from evonote.mindtree import Tree def some_function(): @@ -13,21 +13,21 @@ def some_function(): with debug.display_chats(): some_function() -def example_notetree(): - notetree = Tree("notetree for testing") - notetree.get_new_note_by_path(["People", "Mike"]).be("Mike lives in Los Santos") - notetree.get_new_note_by_path(["Fruit", "Apple"]).be("Apple is a fruit") - return notetree +def example_tree(): + tree = Tree("tree for testing") + tree.get_new_note_by_path(["People", "Mike"]).be("Mike lives in Los Santos") + tree.get_new_note_by_path(["Fruit", "Apple"]).be("Apple is a fruit") + return tree # <- Set a break point here -notetree = example_notetree() -notetree.show_notetree_gui() +tree = example_tree() +tree.show_tree_gui() # <- Set a break point here with debug.display_embedding_search(): with debug.display_chats(): with debug.refresh_cache(): - sub_notetree = notetree.get_sub_notetree_by_similarity( + sub_tree = tree.get_sub_tree_by_similarity( ["Franklin lives in Los Santos"], top_k=1) - sub_notetree.show_notetree_gui() + sub_tree.show_tree_gui() diff --git a/playground/note_putting.py b/playground/note_putting.py index 4e6e1b5..ab50059 100644 --- a/playground/note_putting.py +++ b/playground/note_putting.py @@ -1,16 +1,16 @@ -from evonote.notetree import Note -from evonote.notetree import Tree -from evonote.transform.note_putting import add_content_to_notetree +from evonote.mindtree import Note +from evonote.mindtree import Tree +from evonote.transform.note_putting import add_content_to_tree -memory_notetree = Tree("memory of things", +memory_tree = Tree("memory of things", rule_of_path="Example: \"Bob's birthday is in October\"" " is stored in path /People/Bob/birthday ") -sample_note = Note(memory_notetree).be("Charles's birthday is in October") -memory_notetree.add_note_by_path(["People", "Charles", "birthday"], sample_note) +sample_note = Note(memory_tree).be("Charles's birthday is in October") +memory_tree.add_note_by_path(["People", "Charles", "birthday"], sample_note) -add_content_to_notetree("Alice died in April", "", memory_notetree) -add_content_to_notetree("Canada is in America", "", memory_notetree) +add_content_to_tree("Alice died in April", "", memory_tree) +add_content_to_tree("Canada is in America", "", memory_tree) -memory_notetree.show_notetree_gui() +memory_tree.show_tree_gui() diff --git a/playground/notebook_to_paragraph.py b/playground/notebook_to_paragraph.py index c8643ca..f226e38 100644 --- a/playground/notebook_to_paragraph.py +++ b/playground/notebook_to_paragraph.py @@ -1,20 +1,20 @@ from evonote import debug from evonote.transform.build_from_sections import digest_all_descendants -from evonote.transform.notetree_to_paragraph import notetree_to_paragraph -from evonote.notetree import Tree +from evonote.transform.tree_to_paragraph import tree_to_paragraph +from evonote.mindtree import Tree with debug.display_chats(): - notetree = Tree.load("AI4Science.enb") + tree = Tree.load("AI4Science.enb") keyword = "quantum computing" - notetree = notetree.get_sub_notetree_by_similarity([keyword], top_k=6) - res = notetree_to_paragraph(notetree, + 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 notetree + # Refactor the tree - new_notetree = Tree(keyword) - note = new_notetree.get_new_note_by_path([keyword]) + new_tree = Tree(keyword) + note = new_tree.get_new_note_by_path([keyword]) note.be(res) - new_notetree = digest_all_descendants(new_notetree) - new_notetree.show_notetree_gui() + new_tree = digest_all_descendants(new_tree) + new_tree.show_tree_gui() diff --git a/playground/persistence.py b/playground/persistence.py index 43a6b6d..5f08851 100644 --- a/playground/persistence.py +++ b/playground/persistence.py @@ -1,5 +1,5 @@ -from evonote.notetree import Tree +from evonote.mindtree import Tree -notetree = Tree.load("AI4Science.enb") +tree = Tree.load("AI4Science.enb") -notetree.show_notetree_gui() \ No newline at end of file +tree.show_tree_gui() \ No newline at end of file diff --git a/playground/search_in_mindtree.py b/playground/search_in_mindtree.py new file mode 100644 index 0000000..b57266c --- /dev/null +++ b/playground/search_in_mindtree.py @@ -0,0 +1,9 @@ +from evonote.mindtree import Tree + +tree = Tree.load("AI4Science.enb") + +keyword = "quantum computing" + +tree = tree.get_sub_tree_by_similarity([keyword], top_k=10) + +tree.show_tree_gui() \ No newline at end of file diff --git a/playground/search_in_notebook.py b/playground/search_in_notebook.py deleted file mode 100644 index 3baed03..0000000 --- a/playground/search_in_notebook.py +++ /dev/null @@ -1,9 +0,0 @@ -from evonote.notetree import Tree - -notetree = Tree.load("AI4Science.enb") - -keyword = "quantum computing" - -notetree = notetree.get_sub_notetree_by_similarity([keyword], top_k=10) - -notetree.show_notetree_gui() \ No newline at end of file diff --git a/playground/understanding_test.py b/playground/understanding_test.py index efb695a..c6c8ec6 100644 --- a/playground/understanding_test.py +++ b/playground/understanding_test.py @@ -1,6 +1,6 @@ from evonote.file_helper.cache_manage import save_used_cache, save_cache from evonote.transform.build_from_sections import digest_all_descendants, \ - notetree_from_doc + mindtree_from_doc from evonote.data_cleaning.html_converter import process_html_into_standard from evonote.testing.sample_html import sample_html @@ -8,18 +8,18 @@ doc, meta = process_html_into_standard(sample_html) -paper_notetree = notetree_from_doc(doc, meta) +paper_tree = mindtree_from_doc(doc, meta) -digest_notetree = digest_all_descendants(paper_notetree) +digest_tree = digest_all_descendants(paper_tree) -# Try removing comments to show the notetree before digesting +# Try removing comments to show the tree before digesting -# paper_notetree.show_notetree_gui() +# paper_tree.show_tree_gui() -digest_notetree.show_notetree_gui() +digest_tree.show_tree_gui() save_used_cache() -# Try removing comments to save the notetree +# Try removing comments to save the tree -# digest_notetree.save("AI4Science.enb") \ No newline at end of file +# digest_tree.save("AI4Science.enb") \ No newline at end of file diff --git a/playground/v_lab_search.py b/playground/v_lab_search.py index 395d87c..dd0a664 100644 --- a/playground/v_lab_search.py +++ b/playground/v_lab_search.py @@ -1,11 +1,11 @@ -from evonote.transform.module_to_notetree import get_notetree_for_module +from evonote.transform.module_to_tree import get_tree_for_module from evonote.debug import display_chats, display_embedding_search from evonote.search.code_searcher import search_function from evonote.testing.testing_modules import v_lab -notetree = get_notetree_for_module(v_lab) +tree = get_tree_for_module(v_lab) with display_embedding_search(): with display_chats(): - notetree = search_function("Add water", notetree) - notetree.show_notetree_gui() + tree = search_function("Add water", tree) + tree.show_tree_gui() diff --git a/playground/visualize_paper.py b/playground/visualize_paper.py index 81dbb4e..91c83d1 100644 --- a/playground/visualize_paper.py +++ b/playground/visualize_paper.py @@ -1,7 +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, \ - notetree_from_doc + mindtree_from_doc from evonote.data_cleaning.latex_converter import process_latex_into_standard @@ -9,18 +9,18 @@ doc, meta = process_latex_into_standard(tex) -paper_notetree = notetree_from_doc(doc, meta) +paper_tree = mindtree_from_doc(doc, meta) -digest_notetree = digest_all_descendants(paper_notetree) +digest_tree = digest_all_descendants(paper_tree) -# Try removing comments to show the notetree before digesting +# Try removing comments to show the tree before digesting -# paper_notetree.show_notetree_gui() +# paper_tree.show_tree_gui() -digest_notetree.show_notetree_gui() +digest_tree.show_tree_gui() save_used_cache() -# Try removing comments to save the notetree +# Try removing comments to save the tree -digest_notetree.save("AI4Science.enb") \ No newline at end of file +digest_tree.save("AI4Science.enb") \ No newline at end of file diff --git a/playground/visualize_the_project.py b/playground/visualize_the_project.py index 0fc7c09..fc651b5 100644 --- a/playground/visualize_the_project.py +++ b/playground/visualize_the_project.py @@ -1,5 +1,5 @@ import evonote -from evonote.transform.module_to_notetree import get_notetree_for_module +from evonote.transform.module_to_tree import get_tree_for_module -notetree = get_notetree_for_module(evonote) -notetree.show_notetree_gui() \ No newline at end of file +tree = get_tree_for_module(evonote) +tree.show_tree_gui() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 493e5fc..e6c3f5b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,4 +29,4 @@ dev = [ ] [tool.setuptools] -packages = ["evonote", "doc_in_py"] \ No newline at end of file +packages = ["evonote", "docinpy"] \ No newline at end of file