File uploads and a starter "chat with my notes" feature
The feature that turns a chatbot into a personal assistant: "chat with my notes". This lesson is the smallest possible step toward RAG (Module 7 and 9).
The chatbot is a friend who can read whatever you hand them. Today we hand them a single note. In Module 9, we hand them a whole library.
For a small file, we can just paste its text into the prompt. This is the simplest possible "ask my document" feature. We will replace it with proper retrieval in Module 9.
Add a sidebar uploader:
uploaded = st.sidebar.file_uploader("Upload a .txt or .md note", type=["txt", "md"])
note_text = uploaded.read().decode("utf-8") if uploaded else ""
# Inject note into system context
if note_text:
system_with_note = SYSTEM + f"\n\nUser's note:\n{note_text[:8000]}"
st.session_state.messages[0] = {"role": "system", "content": system_with_note}
Now every reply is informed by the note. For PDFs, large files, or many files, jump to Module 9 (RAG).
Quick recall
3 prompts · think before you flip
Prompt 1 of 3
Why is "paste the whole file" only a small-file solution?
Quiz time
1 question · tap an answer to check it
1. The simplest "chat with my doc" pattern is
Finished lesson 6.5?
Mark complete to update your module progress and unlock the streak.