SelfGPT is a private, production‑ready LangChain + LangSmith chat application. It ships a Next.js UI with a FastAPI backend, supports multiple LLM providers, PDF‑based RAG, and optional live web search via Google Custom Search. LangSmith tracing is built in for observability when enabled.
Frontend
- Next.js 16 (App Router)
- React 19
- TypeScript
- Tailwind CSS
- Radix UI components
Backend
- FastAPI (Python)
- Requests (provider HTTP calls)
- FAISS + SentenceTransformers (RAG)
- LangChain (community loaders/splitters for PDF ingestion)
- LangSmith (tracing + observability)
- Google Custom Search API (web search)
LLM Providers (OpenAI‑compatible or native)
- Groq
- OpenAI
- DeepSeek
- xAI Grok
- Anthropic
- Gemini
- Mistral
LangChain & LangSmith
- LangChain powers PDF loading, chunking, embeddings, and retrieval for RAG.
- LangSmith provides end‑to‑end tracing for RAG and LLM calls when enabled via environment variables.
- Multi‑provider LLM support with model selection
- PDF upload + retrieval‑augmented generation (RAG)
- Optional web search integration (Google CSE)
- Persistent chat history (SQLite)
- Streaming‑style typewriter responses
- Responsive UI (desktop + mobile)
- Security controls: API key auth, rate limiting, upload limits
- LangSmith observability (optional, secure, key‑gated)
app/ # Next.js app (UI)
components/ # UI components
context/ # React contexts (chat, settings, auth)
server.py # FastAPI backend
rag_engine.py # RAG pipeline (FAISS + embeddings)
storage.py # SQLite chat persistence
requirements.txt # Python deps
package.json # JS deps
npm installpython3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txtNote: LangSmith currently does not publish wheels for Python 3.14. If you want tracing enabled, use Python 3.12 or 3.11 for the backend venv.
Create .env in the project root.
GROQ_API_KEY=...
# or
OPENAI_API_KEY=...
# or
DEEPSEEK_API_KEY=...
# or
XAI_API_KEY=...
# or
ANTHROPIC_API_KEY=...
# or
GEMINI_API_KEY=...
# or
MISTRAL_API_KEY=...GOOGLE_API_KEY=...
GOOGLE_CSE_ID=... # cx= value from your CSELANGSMITH_TRACING=true
LANGSMITH_API_KEY=...
LANGSMITH_PROJECT=SelfGPT
LANGSMITH_ENDPOINT=https://api.smith.langchain.comDEFAULT_PROVIDER=groq
DEFAULT_MODEL=llama-3.3-70b-versatile
DEFAULT_SYSTEM_PROMPT="You are a helpful assistant."
# Security
RATE_LIMIT_PER_MIN=60
MAX_UPLOAD_MB=10
MAX_MESSAGE_LEN=6000
MAX_HISTORY_MESSAGES=24
# CORS (add your frontend origin if using a different host)
CORS_ORIGINS=http://localhost:3000
# SQLite DB path (set to a persistent disk on the backend host)
DB_PATH=/var/data/chatbot.db
# Postgres (use this instead of DB_PATH when you don't have a disk)
DATABASE_URL=postgresql://user:pass@host:5432/dbname
# RAG store path (set to a persistent disk on the backend host)
RAG_STORE_DIR=/var/data/rag_storeNEXT_PUBLIC_API_BASE_URL=http://localhost:8000
NEXT_PUBLIC_LLM_PROVIDER=groq
NEXT_PUBLIC_LLM_MODEL=llama-3.3-70b-versatile
NEXT_PUBLIC_SYSTEM_PROMPT="You are a helpful assistant."
NEXT_PUBLIC_USE_WEB=trueIf NEXT_PUBLIC_API_BASE_URL is not set, the Next.js dev server will proxy /api/* to the FastAPI backend at http://localhost:8000.
npm run dev:fullThis starts:
- FastAPI on
http://localhost:8000 - Next.js on
http://localhost:3000 - live : https://self-gpt-iota.vercel.app
- Rate limiting: per‑IP, per minute.
- Upload limits: defaults to 10MB per file.
- Thread ID sanitization: prevents path traversal.
- Safe FAISS loading: no dangerous deserialization.
- LangSmith is opt‑in: tracing only occurs when
LANGSMITH_TRACING=trueand a valid key is set.
GET /api/config– app + provider configGET /api/models?provider=...– list modelsPOST /api/chat– send messagePOST /api/upload– upload PDFsGET /api/threads– list threadsGET /api/threads/{thread_id}– messagesGET /api/docs/{thread_id}– document metadata
- Hydration warning: If you see
vsc-initializedin a hydration error, a browser extension is injecting DOM changes. Disable the extension or use Incognito.