enh: reference note in chat

This commit is contained in:
Timothy Jaeryang Baek
2025-07-09 01:17:25 +04:00
parent f2ee99d760
commit d5f9bbc7a7
8 changed files with 105 additions and 24 deletions

View File

@@ -18,6 +18,7 @@ from open_webui.retrieval.vector.factory import VECTOR_DB_CLIENT
from open_webui.models.users import UserModel
from open_webui.models.files import Files
from open_webui.models.notes import Notes
from open_webui.retrieval.vector.main import GetResult
@@ -470,7 +471,15 @@ def get_sources_from_files(
"documents": [[doc.get("content") for doc in file.get("docs")]],
"metadatas": [[doc.get("metadata") for doc in file.get("docs")]],
}
elif file.get("context") == "full":
elif file.get("type") == "note":
# Note Attached
note = Notes.get_note_by_id(file.get("id"))
query_result = {
"documents": [[note.data.get("content", {}).get("md", "")]],
"metadatas": [[{"file_id": note.id, "name": note.title}]],
}
elif file.get("context") == "full" and file.get("type") == "file":
# Manual Full Mode Toggle
query_result = {
"documents": [[file.get("file").get("data", {}).get("content")]],

View File

@@ -51,7 +51,14 @@ async def get_notes(request: Request, user=Depends(get_verified_user)):
return notes
@router.get("/list", response_model=list[NoteUserResponse])
class NoteTitleIdResponse(BaseModel):
id: str
title: str
updated_at: int
created_at: int
@router.get("/list", response_model=list[NoteTitleIdResponse])
async def get_note_list(request: Request, user=Depends(get_verified_user)):
if user.role != "admin" and not has_permission(
@@ -63,12 +70,7 @@ async def get_note_list(request: Request, user=Depends(get_verified_user)):
)
notes = [
NoteUserResponse(
**{
**note.model_dump(),
"user": UserResponse(**Users.get_user_by_id(note.user_id).model_dump()),
}
)
NoteTitleIdResponse(**note.model_dump())
for note in Notes.get_notes_by_user_id(user.id, "read")
]