cleanup the card UI and automate note title
This commit is contained in:
parent
8a5803a21a
commit
02c168615c
3 changed files with 56 additions and 48 deletions
|
|
@ -4,6 +4,7 @@ from langchain_core.runnables import RunnableConfig
|
|||
from open_notebook.domain import Note, Source
|
||||
from open_notebook.graphs.chat import graph as chat_graph
|
||||
from open_notebook.utils import token_count
|
||||
from stream_app.note import make_note_from_chat
|
||||
|
||||
|
||||
# todo: build a smarter, more robust context manager function
|
||||
|
|
@ -75,15 +76,8 @@ def chat_sidebar(session_id):
|
|||
st.write(msg.content)
|
||||
if msg.type == "ai":
|
||||
if st.button("💾 New Note", key=f"render_save_{msg.id}"):
|
||||
title = "New Note"
|
||||
content = msg.content
|
||||
note = Note(
|
||||
title=title,
|
||||
content=content,
|
||||
note_type="ai",
|
||||
)
|
||||
note.save()
|
||||
note.add_to_notebook(
|
||||
st.session_state[session_id]["notebook"].id
|
||||
make_note_from_chat(
|
||||
content=msg.content,
|
||||
notebook_id=st.session_state[session_id]["notebook"].id,
|
||||
)
|
||||
st.rerun()
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ from loguru import logger
|
|||
from streamlit_monaco import st_monaco # type: ignore
|
||||
|
||||
from open_notebook.domain import Note
|
||||
from open_notebook.graphs.multipattern import graph as pattern_graph
|
||||
from open_notebook.utils import surreal_clean
|
||||
|
||||
from .consts import context_icons
|
||||
|
||||
|
|
@ -36,7 +38,7 @@ def note_panel(session_id=None, note_id=None):
|
|||
note.content = st_monaco(
|
||||
value=note.content, height="600px", language="markdown"
|
||||
)
|
||||
if st.button("Save", key=f"edit_note_{note_id}"):
|
||||
if st.button("Save", key=f"pn_edit_note_{note_id}"):
|
||||
logger.debug("Editing note")
|
||||
note.save()
|
||||
if not note.id:
|
||||
|
|
@ -48,27 +50,47 @@ def note_panel(session_id=None, note_id=None):
|
|||
st.rerun()
|
||||
|
||||
|
||||
def make_note_from_chat(content, notebook_id=None):
|
||||
# todo: make this more efficient
|
||||
transformations = [
|
||||
"Based on the Note below, please provide a Title for this content, with max 15 words"
|
||||
]
|
||||
output = pattern_graph.invoke(
|
||||
dict(content_stack=[content], transformations=transformations)
|
||||
)
|
||||
title = surreal_clean(output["output"])
|
||||
|
||||
note = Note(
|
||||
title=title,
|
||||
content=content,
|
||||
note_type="ai",
|
||||
)
|
||||
note.save()
|
||||
if notebook_id:
|
||||
note.add_to_notebook(notebook_id)
|
||||
|
||||
st.rerun()
|
||||
|
||||
|
||||
def note_card(session_id, note):
|
||||
if note.note_type == "human":
|
||||
icon = "🤵"
|
||||
else:
|
||||
icon = "🤖"
|
||||
|
||||
context_state = st.selectbox(
|
||||
"Context",
|
||||
label_visibility="collapsed",
|
||||
options=context_icons,
|
||||
index=0,
|
||||
key=f"note_{note.id}",
|
||||
)
|
||||
with st.expander(f"{icon} **{note.title}** {naturaltime(note.updated)}"):
|
||||
st.write(note.content)
|
||||
with st.popover("Actions"):
|
||||
if st.button("Edit Note", icon="📝", key=f"edit_note_{note.id}"):
|
||||
note_panel(session_id, note.id)
|
||||
if st.button("Delete", icon="🗑️", key=f"delete_options_{note.id}"):
|
||||
note.delete()
|
||||
st.rerun()
|
||||
with st.container(border=True):
|
||||
st.markdown((f"{icon} **{note.title if note.title else 'No Title'}**"))
|
||||
context_state = st.selectbox(
|
||||
"Context",
|
||||
label_visibility="collapsed",
|
||||
options=context_icons,
|
||||
index=0,
|
||||
key=f"note_{note.id}",
|
||||
)
|
||||
st.caption(f"Updated: {naturaltime(note.updated)}")
|
||||
|
||||
if st.button("Expand", icon="📝", key=f"edit_note_{note.id}"):
|
||||
note_panel(session_id, note.id)
|
||||
|
||||
st.session_state[session_id]["context_config"][note.id] = context_state
|
||||
|
||||
|
|
|
|||
|
|
@ -139,32 +139,24 @@ def add_source(session_id):
|
|||
|
||||
|
||||
def source_card(session_id, source):
|
||||
# todo: more descriptive icons
|
||||
icon = "🔗"
|
||||
context_state = st.selectbox(
|
||||
"Context",
|
||||
label_visibility="collapsed",
|
||||
options=context_icons,
|
||||
index=0,
|
||||
key=f"source_{source.id}",
|
||||
)
|
||||
with st.expander(f"**{source.title}**"):
|
||||
st.markdown(f"{icon} Updated: {naturaltime(source.updated)}")
|
||||
st.markdown("**" + ", ".join(source.topics) + "**")
|
||||
for insight in source.insights:
|
||||
st.write(insight.insight_type)
|
||||
st.write(insight.content)
|
||||
|
||||
if st.button("Edit Source", icon="📝", key=source.id):
|
||||
with st.container(border=True):
|
||||
st.markdown((f"{icon} **{source.title if source.title else 'No Title'}**"))
|
||||
context_state = st.selectbox(
|
||||
"Context",
|
||||
label_visibility="collapsed",
|
||||
options=context_icons,
|
||||
index=0,
|
||||
key=f"source_{source.id}",
|
||||
)
|
||||
st.caption(
|
||||
f"Updated: {naturaltime(source.updated)}, **{len(source.insights)}** insights"
|
||||
)
|
||||
if st.button("Expand", icon="📝", key=source.id):
|
||||
source_panel(source.id)
|
||||
|
||||
# with st.popover("Actions"):
|
||||
# if st.button("Edit Source", icon="📝", key=source.id):
|
||||
# result = source_panel(source.id)
|
||||
# st.write(result)
|
||||
# if st.button("Delete", icon="🗑️", key=f"delete_options_{source.id}"):
|
||||
# source.delete()
|
||||
# st.rerun()
|
||||
|
||||
st.session_state[session_id]["context_config"][source.id] = context_state
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue