open-notebook/pages/stream_app/note.py
Luis Novo b7e656a319
Version 1 (#160)
New front-end
Launch Chat API
Manage Sources
Enable re-embedding of all contents
Sources can be added without a notebook now
Improved settings
Enable model selector on all chats
Background processing for better experience
Dark mode
Improved Notes

Improved Docs: 
- Remove all Streamlit references from documentation
- Update deployment guides with React frontend setup
- Fix Docker environment variables format (SURREAL_URL, SURREAL_PASSWORD)
- Update docker image tag from :latest to :v1-latest
- Change navigation references (Settings → Models to just Models)
- Update development setup to include frontend npm commands
- Add MIGRATION.md guide for users upgrading from Streamlit
- Update quick-start guide with correct environment variables
- Add port 5055 documentation for API access
- Update project structure to reflect frontend/ directory
- Remove outdated source-chat documentation files
2025-10-18 12:46:22 -03:00

87 lines
2.6 KiB
Python

from typing import Optional
import streamlit as st
from humanize import naturaltime
from api.models_service import models_service
from api.notes_service import notes_service
from open_notebook.domain.notebook import Note
from pages.components import note_panel
from .consts import note_context_icons
@st.dialog("Write a Note", width="large")
def add_note(notebook_id):
default_models = models_service.get_default_models()
if not default_models.default_embedding_model:
st.warning(
"Since there is no embedding model selected, your note will be saved but not searchable."
)
note_title = st.text_input("Title")
note_content = st.text_area("Content")
if st.button("Save", key="add_note"):
notes_service.create_note(
content=note_content,
title=note_title,
note_type="human",
notebook_id=notebook_id
)
st.rerun()
@st.dialog("Add a Note", width="large")
def note_panel_dialog(note: Optional[Note] = None, notebook_id=None):
if not note:
raise ValueError("Note is required")
note_panel(note_id=note.id, notebook_id=notebook_id)
def make_note_from_chat(content, notebook_id=None):
# Title will be auto-generated by the API for AI notes
notes_service.create_note(
content=content,
title=None, # Let API generate it
note_type="ai",
notebook_id=notebook_id
)
st.rerun()
def note_card(note, notebook_id):
if note.note_type == "human":
icon = "🤵"
else:
icon = "🤖"
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=note_context_icons,
index=1,
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_dialog(notebook_id=notebook_id, note=note)
st.session_state[notebook_id]["context_config"][note.id] = context_state
def note_list_item(note_id, score=None):
note = notes_service.get_note(note_id)
if note.note_type == "human":
icon = "🤵"
else:
icon = "🤖"
with st.expander(
f"{icon} [{score:.2f}] **{note.title}** {naturaltime(note.updated) if note.updated else 'N/A'}"
):
st.write(note.content)
if st.button("Edit Note", icon="📝", key=f"x_edit_note_{note.id}"):
note_panel_dialog(note=note)