improve context and several fixes
This commit is contained in:
parent
4a5d47d934
commit
7f79f8224f
5 changed files with 25 additions and 30 deletions
|
|
@ -180,11 +180,15 @@ class ObjectModel(BaseModel):
|
||||||
f"Failed to delete {self.__class__.table_name}"
|
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:
|
if not relationship or not target_id or not self.id:
|
||||||
raise InvalidInputError("Relationship and target ID must be provided")
|
raise InvalidInputError("Relationship and target ID must be provided")
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
logger.error(f"Error creating relationship: {str(e)}")
|
logger.error(f"Error creating relationship: {str(e)}")
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
|
|
||||||
|
|
@ -33,16 +33,12 @@ class Notebook(ObjectModel):
|
||||||
def sources(self) -> List["Source"]:
|
def sources(self) -> List["Source"]:
|
||||||
try:
|
try:
|
||||||
srcs = repo_query(f"""
|
srcs = repo_query(f"""
|
||||||
select * OMIT full_text from (
|
select * omit source.full_text from (
|
||||||
select
|
select in as source from reference where out={self.id}
|
||||||
<- source as source
|
fetch source
|
||||||
from reference
|
) order by source.updated desc
|
||||||
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:
|
except Exception as e:
|
||||||
logger.error(f"Error fetching sources for notebook {self.id}: {str(e)}")
|
logger.error(f"Error fetching sources for notebook {self.id}: {str(e)}")
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
|
@ -52,16 +48,12 @@ class Notebook(ObjectModel):
|
||||||
def notes(self) -> List["Note"]:
|
def notes(self) -> List["Note"]:
|
||||||
try:
|
try:
|
||||||
srcs = repo_query(f"""
|
srcs = repo_query(f"""
|
||||||
select * OMIT content from (
|
select * omit note.content, note.embedding from (
|
||||||
select
|
select in as note from artifact where out={self.id}
|
||||||
<- note as note
|
fetch note
|
||||||
from artifact
|
) order by note.updated desc
|
||||||
where out={self.id}
|
|
||||||
fetch note
|
|
||||||
)
|
|
||||||
order by 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:
|
except Exception as e:
|
||||||
logger.error(f"Error fetching notes for notebook {self.id}: {str(e)}")
|
logger.error(f"Error fetching notes for notebook {self.id}: {str(e)}")
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,12 @@ def build_context(notebook_id):
|
||||||
if "not in" in status:
|
if "not in" in status:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
item: Union[Note, Source] = ObjectModel.get(id)
|
try:
|
||||||
|
item: Union[Note, Source] = ObjectModel.get(id)
|
||||||
if not item:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
if "summary" in status:
|
|
||||||
|
if "insights" in status:
|
||||||
st.session_state[notebook_id]["context"][item_type] += [
|
st.session_state[notebook_id]["context"][item_type] += [
|
||||||
item.get_context(context_size="short")
|
item.get_context(context_size="short")
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
source_context_icons = [
|
source_context_icons = [
|
||||||
"⛔ not in context",
|
"⛔ not in context",
|
||||||
"🟡 summary",
|
"🟡 insights",
|
||||||
"🟢 full content",
|
"🟢 full content",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from humanize import naturaltime
|
||||||
|
|
||||||
from open_notebook.domain.models import model_manager
|
from open_notebook.domain.models import model_manager
|
||||||
from open_notebook.domain.notebook import Note
|
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 open_notebook.utils import surreal_clean
|
||||||
from pages.components import note_panel
|
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):
|
def make_note_from_chat(content, notebook_id=None):
|
||||||
# todo: make this more efficient
|
# todo: make this more efficient
|
||||||
patterns = [
|
prompt = "Based on the Note below, please provide a Title for this content, with max 15 words"
|
||||||
"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))
|
||||||
]
|
|
||||||
output = pattern_graph.invoke(dict(content_stack=[content], patterns=patterns))
|
|
||||||
title = surreal_clean(output["output"])
|
title = surreal_clean(output["output"])
|
||||||
|
|
||||||
note = Note(
|
note = Note(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue