Skip to content

SentorLabs/openchat

Repository files navigation

OpenChat

The open-source AI chat that shows its work.

Every answer. Cited sources. Your model. Your data. Your rules.

License Version Node CI Stars

If OpenChat is useful to you, a ⭐ on the repo helps others find it — thank you! We're open to new ideas, feature requests, and bug reports — open an issue and it will be handled accordingly.

Quick Start · Features · Deploy · Contributing


Tired of AI that confidently makes things up? OpenChat grounds every response in real, verifiable sources — and you own everything: the model, the data, the deployment.


How it works

OpenChat workflow


Screenshots

Overview
Overview
Chat — cited sources
Chat
Settings
Settings

Why OpenChat?

Most AI chat tools give you a great experience — until they change it. You have no say in the model, the personality, or where your conversations go.

OpenChat flips that:

OpenChat Typical SaaS AI
Pick your model ✅ Any provider ❌ Locked in
Own your data ✅ Your database ❌ Their servers
Cited sources ✅ Every response ❌ Rarely
Self-hostable ✅ Docker / Cloud ❌ Subscription
Customise personality ✅ Full control ❌ Fixed prompts

Features

  • Multi-provider LLM — Groq, OpenAI, Anthropic, Google Gemini, Ollama — swap with one env var, zero code changes
  • Cited sources — every AI response includes a collapsible sources banner; no unverified claims
  • Persistent sessions — full chat history in PostgreSQL, MySQL, or SQLite; survives restarts
  • Real-time streaming — responses stream live with a typing cursor indicator
  • Settings UI — change provider, model, API key, and database from the browser — no restart needed
  • Configurable personality — tune the AI's tone, focus, and rules via LLM_SYSTEM_PROMPT
  • Dark-mode UI — clean, minimal interface built with Next.js 16 and Tailwind CSS v4
  • Production-ready — Docker, Cloud Foundry, GCP, AWS, and Azure deployment guides included

Quick Start

Option A — No API key, no database, one command

Runs OpenChat with Gemma 3 4B via Ollama and SQLite. Nothing to sign up for.

Requirements: Node.js ≥ 20, npm, curl

git clone https://github.com/SentorLabs/openchat.git
cd openchat
./start.sh

The script will:

  • Install Ollama if not present
  • Pull the Gemma 3 4B model (~3 GB, one-time)
  • Write a .env.local with SQLite + Ollama config
  • Start OpenChat at http://localhost:3000

Option B — Bring your own model & database

Swap in any provider or database via .env.local or the Settings UI.

1. Clone and install

git clone https://github.com/SentorLabs/openchat.git
cd openchat
npm install

2. Configure environment

cp .env.example .env.local
LLM_PROVIDER=groq                        # groq | openai | anthropic | gemini | ollama
LLM_MODEL=llama-3.3-70b-versatile
LLM_API_KEY=your_api_key_here
DATABASE_URL=postgresql://postgres:password@localhost:5432/openchat

3. Run

createdb openchat   # auto-creates tables on first run
npm run dev

Open http://localhost:3000. That's it.


LLM Providers

Provider LLM_PROVIDER Example model Free tier
Groq groq llama-3.3-70b-versatile ✅ Yes
OpenAI openai gpt-4o ❌ No
Anthropic anthropic claude-opus-4-6 ❌ No
Google Gemini gemini gemini-2.0-flash ✅ Yes
Ollama (local) ollama llama3.2 ✅ Free

Customising the AI Personality

# Coding assistant
LLM_SYSTEM_PROMPT="You are a senior software engineer. Answer only technical questions with code examples."

# Strict research analyst
LLM_SYSTEM_PROMPT="You are a research analyst. Always cite primary sources. Never state unverified facts."

# Customer support agent
LLM_SYSTEM_PROMPT="You are a support agent for Acme Corp. Only answer questions about our product."

No redeploy needed — update the env var and restart.


Deployment

Docker
docker build -t openchat .
docker run -p 3000:3000 \
  -e LLM_PROVIDER=groq \
  -e LLM_MODEL=llama-3.3-70b-versatile \
  -e LLM_API_KEY=your_key \
  -e DATABASE_URL=postgresql://... \
  openchat
SAP BTP Cloud Foundry

See DEPLOY.md for the full guide.

cf push -f deploy-postgres.yml
cf create-user-provided-service openchat-db -p '{"uri":"postgresql://..."}'
cf push -f manifest.yml
cf add-network-policy openchat --destination-app postgres-db --port 5432 --protocol tcp
cf set-env openchat LLM_PROVIDER groq
cf restage openchat
GCP / AWS / Azure

See DEPLOY.md for Cloud Run, App Runner, and Container Apps guides.


Project Structure

src/
├── app/
│   ├── api/
│   │   ├── chat/route.ts          # Streaming chat endpoint
│   │   ├── sessions/route.ts      # List & create sessions
│   │   └── sessions/[id]/
│   │       ├── route.ts           # Delete session
│   │       └── messages/route.ts  # Load session messages
│   ├── about/page.tsx
│   ├── releases/page.tsx
│   ├── page.tsx                   # Main chat UI
│   └── globals.css
├── components/
│   ├── Nav.tsx                    # Top navigation bar
│   ├── Sidebar.tsx                # Session list panel
│   └── SourcesBanner.tsx          # Collapsible sources banner
└── lib/
    ├── db.ts                      # Multi-database adapter (PG / MySQL / SQLite)
    ├── llm.ts                     # Unified multi-provider LLM adapter
    ├── sources.ts                 # Parse & strip [SOURCES] blocks
    └── types.ts                   # Shared TypeScript interfaces

Tech Stack

Layer Technology
Framework Next.js 16 (App Router)
Language TypeScript 5
Styling Tailwind CSS v4
Database PostgreSQL · MySQL · SQLite
LLM providers Groq · OpenAI · Anthropic · Gemini · Ollama
Runtime Node.js ≥ 20

Contributing

OpenChat is built for the community. If you run your own AI assistant, you know what's missing — and PRs are welcome.

Good first contributions

  • New LLM providers — Mistral, Cohere, Together AI
  • UI improvements — markdown rendering, code highlighting
  • Export features — download chat history as PDF or Markdown
  • Auth support — multi-user mode with authentication
  • Docker Compose — ready-to-run compose file with Postgres

How to contribute

git checkout -b feat/your-feature
# make your changes
npm run test && npm run build
# open a pull request

Reporting issues

Open an issue with: steps to reproduce · expected vs actual · your LLM_PROVIDER · Node.js version.


Database Schema

View schema (auto-created on first run)
CREATE TABLE sessions (
  id         UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  title      TEXT NOT NULL DEFAULT 'New Chat',
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE TABLE messages (
  id         UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  session_id UUID NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
  role       TEXT NOT NULL CHECK (role IN ('user','assistant')),
  content    TEXT NOT NULL,
  sources    JSONB,
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

License

Apache 2.0 — free to use, modify, and distribute, including for commercial use. See LICENSE.


Take control of your AI experience.

About

A self-hostable, multi-provider AI chat interface for fact-grounded research. Every answer is sourced. Every session persists. You own the data.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors