In this video, we dive into the #on_chat_resume decorator in #Chainlit — showing you exactly how to resume previous chats right where you left off. Along the way, we’ll set up #authentication, enable data #persistence, and connect to PostgreSQL with SQLAlchemy.
🔑 What we cover in this tutorial:
1. How the @on_chat_resume decorator works in Chainlit
2. Enabling authentication + showing a login form after login
3. Setting up data persistence with the SQLAlchemy data layer
4. Installing PostgreSQL locally (Windows/Linux)
5. Creating a database, connecting it, and resuming chat sessions
Full practical demo so you can follow along easily
💡 Whether you’re building an LLM app, chatbot, or enterprise AI tool — this will help you create secure, persistent chat experiences with Chainlit.
📌 Timestamps (Chapters)
00:00 Intro
01:30 Authentication
03:51 Data Persistence
14:10 on_chat_resume
Database Schema:
CREATE TABLE users (
"id" UUID PRIMARY KEY,
"identifier" TEXT NOT NULL UNIQUE,
"metadata" JSONB NOT NULL,
"createdAt" TEXT
);
CREATE TABLE IF NOT EXISTS threads (
"id" UUID PRIMARY KEY,
"createdAt" TEXT,
"name" TEXT,
"userId" UUID,
"userIdentifier" TEXT,
"tags" TEXT[],
"metadata" JSONB,
FOREIGN KEY ("userId") REFERENCES users("id") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS steps (
"id" UUID PRIMARY KEY,
"name" TEXT NOT NULL,
"type" TEXT NOT NULL,
"threadId" UUID NOT NULL,
"parentId" UUID,
"streaming" BOOLEAN NOT NULL,
"waitForAnswer" BOOLEAN,
"isError" BOOLEAN,
"defaultOpen" BOOLEAN,
"metadata" JSONB,
"tags" TEXT[],
"input" TEXT,
"output" TEXT,
"createdAt" TEXT,
"command" TEXT,
"start" TEXT,
"end" TEXT,
"generation" JSONB,
"showInput" TEXT,
"language" TEXT,
"indent" INT,
FOREIGN KEY ("threadId") REFERENCES threads("id") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS elements (
"id" UUID PRIMARY KEY,
"threadId" UUID,
"type" TEXT,
"url" TEXT,
"chainlitKey" TEXT,
"name" TEXT NOT NULL,
"display" TEXT,
"objectKey" TEXT,
"size" TEXT,
"page" INT,
"language" TEXT,
"forId" UUID,
"mime" TEXT,
"props" JSONB,
FOREIGN KEY ("threadId") REFERENCES threads("id") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS feedbacks (
"id" UUID PRIMARY KEY,
"forId" UUID NOT NULL,
"threadId" UUID NOT NULL,
"value" INT NOT NULL,
"comment" TEXT,
FOREIGN KEY ("threadId") REFERENCES threads("id") ON DELETE CASCADE
);
------------------------------------------------------------------
How to Setup PostgresSql in Linux:
Update packages
sudo apt update
Install PostgreSQL
sudo apt install postgresql postgresql-contrib -y
PostgreSQL will start automatically every time your system boots
sudo systemctl enable postgresql
Test
psql --version
sudo systemctl status postgresql
Should say active (exited) or active (running).
If it’s not active, try:
sudo systemctl start postgresql
---------------------------------------------------------------
Switch to postgres user
sudo -i -u postgres
Enter PostgreSQL shell
psql
Create user "admin" with password "admin"
CREATE USER admin WITH PASSWORD 'admin';
#Create database "my_chainlit_db" owned by admin
CREATE DATABASE my_chainlit_db OWNER admin;
Give privileges
GRANT ALL PRIVILEGES ON DATABASE my_chainlit_db TO admin;
Exit
\q
exit
Test
psql -U admin -d my_chainlit_db -h localhost -W
\conninfo
Source Code:
https://github.com/Alihamza-786/Chainlit
Previous Classes:
• Chainlit Beginner to Advanced | Master AI ...
#onChatResume #chainlit #howToResumePreviousChatChainlit #howToResumePreviousChatInChainlit #howToResumePreviousChatsInChainlit #dataPersistence #enableAuthentication #chainlitTutorial #chainlitOnChatResume
Информация по комментариям в разработке