diff --git a/open_notebook/domain/base.py b/open_notebook/domain/base.py index b280a8d..ce0e496 100644 --- a/open_notebook/domain/base.py +++ b/open_notebook/domain/base.py @@ -180,11 +180,15 @@ class ObjectModel(BaseModel): f"Failed to delete {self.__class__.table_name}" ) - def relate(self, relationship: str, target_id: str) -> Any: + def relate( + self, relationship: str, target_id: str, data: Optional[Dict] = {} + ) -> Any: if not relationship or not target_id or not self.id: raise InvalidInputError("Relationship and target ID must be provided") try: - return repo_relate(self.id, relationship, target_id) + return repo_relate( + source=self.id, relationship=relationship, target=target_id, data=data + ) except Exception as e: logger.error(f"Error creating relationship: {str(e)}") logger.exception(e) diff --git a/open_notebook/domain/notebook.py b/open_notebook/domain/notebook.py index a3e464b..b2a8833 100644 --- a/open_notebook/domain/notebook.py +++ b/open_notebook/domain/notebook.py @@ -33,16 +33,12 @@ class Notebook(ObjectModel): def sources(self) -> List["Source"]: try: srcs = repo_query(f""" - select * OMIT full_text from ( - select - <- source as source - from reference - where out={self.id} - fetch source - ) - order by source.updated desc + select * omit source.full_text from ( + select in as source from reference where out={self.id} + fetch source + ) order by source.updated desc """) - return [Source(**src["source"][0]) for src in srcs] if srcs else [] + return [Source(**src["source"]) for src in srcs] if srcs else [] except Exception as e: logger.error(f"Error fetching sources for notebook {self.id}: {str(e)}") logger.exception(e) @@ -52,16 +48,12 @@ class Notebook(ObjectModel): def notes(self) -> List["Note"]: try: srcs = repo_query(f""" - select * OMIT content from ( - select - <- note as note - from artifact - where out={self.id} - fetch note - ) - order by updated desc + select * omit note.content, note.embedding from ( + select in as note from artifact where out={self.id} + fetch note + ) order by note.updated desc """) - return [Note(**src["note"][0]) for src in srcs] if srcs else [] + return [Note(**src["note"]) for src in srcs] if srcs else [] except Exception as e: logger.error(f"Error fetching notes for notebook {self.id}: {str(e)}") logger.exception(e) diff --git a/pages/stream_app/chat.py b/pages/stream_app/chat.py index 0671c85..ecf2f7a 100644 --- a/pages/stream_app/chat.py +++ b/pages/stream_app/chat.py @@ -32,11 +32,12 @@ def build_context(notebook_id): if "not in" in status: continue - item: Union[Note, Source] = ObjectModel.get(id) - - if not item: + try: + item: Union[Note, Source] = ObjectModel.get(id) + except Exception: continue - if "summary" in status: + + if "insights" in status: st.session_state[notebook_id]["context"][item_type] += [ item.get_context(context_size="short") ] diff --git a/pages/stream_app/consts.py b/pages/stream_app/consts.py index 60aadb0..fa28be4 100644 --- a/pages/stream_app/consts.py +++ b/pages/stream_app/consts.py @@ -1,6 +1,6 @@ source_context_icons = [ "⛔ not in context", - "🟡 summary", + "🟡 insights", "🟢 full content", ] diff --git a/pages/stream_app/note.py b/pages/stream_app/note.py index f64baea..4738d76 100644 --- a/pages/stream_app/note.py +++ b/pages/stream_app/note.py @@ -5,7 +5,7 @@ from humanize import naturaltime from open_notebook.domain.models import model_manager from open_notebook.domain.notebook import Note -from open_notebook.graphs.multipattern import graph as pattern_graph +from open_notebook.graphs.prompt import graph as prompt_graph from open_notebook.utils import surreal_clean from pages.components import note_panel @@ -34,10 +34,8 @@ def note_panel_dialog(note: Optional[Note] = None, notebook_id=None): def make_note_from_chat(content, notebook_id=None): # todo: make this more efficient - patterns = [ - "Based on the Note below, please provide a Title for this content, with max 15 words" - ] - output = pattern_graph.invoke(dict(content_stack=[content], patterns=patterns)) + prompt = "Based on the Note below, please provide a Title for this content, with max 15 words" + output = prompt_graph.invoke(dict(input_text=content, prompt=prompt)) title = surreal_clean(output["output"]) note = Note(