Skip to content

DhanushPillay/Veritas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Veritas - AI Chatbot

Veritas is a ChatGPT-style assistant powered by Groq LLaMA 4 with streaming responses, conversation history, and optional web-search augmentation.

Features

  • Real-time SSE streaming responses
  • Conversation memory with CRUD endpoints
  • Optional web search (DuckDuckGo) when the model requests [SEARCH: ...]
  • Markdown + code highlighting in chat
  • Message editing, regeneration, export, and responsive UI
  • Persistent storage with Supabase when configured, with automatic in-memory fallback

Project Structure

index.html
backend/
	app.py
	config.py
	database.py
	web_search.py
	services/chat_service.py
frontend/
	css/styles.css
	js/app.js

Quick Start

1. Prerequisites

  • Python 3.12+ recommended
  • A Groq API key

Notes:

  • Python 3.14 can run the app in memory mode, but Supabase dependency chains may require C++ build tools on Windows.
  • For easiest full install (including Supabase), use Python 3.12.

2. Create and activate virtual environment

python -m venv .venv
& ".venv/Scripts/Activate.ps1"

3. Install dependencies

python -m pip install -r backend/requirements.txt

If Supabase-related wheels fail on Python 3.14, you can still run in memory mode with:

python -m pip install flask flask-cors groq python-dotenv requests flask-limiter

4. Configure environment

Create backend/.env with at least:

GROQ_API_KEY=your_groq_api_key

Optional values:

# Server
HOST=127.0.0.1
PORT=5000
FLASK_DEBUG=True
LOG_LEVEL=INFO

# Security
API_AUTH_TOKEN=
CORS_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
MAX_MESSAGE_LENGTH=10000
MAX_QUERY_LENGTH=512
MAX_TITLE_LENGTH=120
MAX_CONTENT_LENGTH_BYTES=1048576
RATE_LIMIT_DEFAULT=200 per day;50 per hour
RATE_LIMIT_CHAT=20 per minute
RATE_LIMIT_SEARCH=30 per minute

# Optional Supabase
SUPABASE_URL=
SUPABASE_KEY=

5. Run

python backend/app.py

Open:

API Endpoints

Core

  • POST /api/chat
    • Body: { "message": "...", "conversation_id": "...", "stream": true|false }
  • POST /api/search
    • Body: { "query": "..." }
  • POST /api/research
    • Body: { "question": "...", "depth": "quick|deep", "stream": true|false }
    • Returns: plan, retrieval rounds, synthesis report, sources, and stats

Conversations

  • GET /api/conversations
  • GET /api/conversations/<id>
  • PUT /api/conversations/<id>
  • DELETE /api/conversations/<id>
  • DELETE /api/conversations

Keyboard Shortcuts

Shortcut Action
Enter Send message
Shift + Enter New line
Ctrl + N New chat
Esc Stop generation
Ctrl + Shift + C Copy latest assistant reply

Deep Research Mode (How To Build It)

Your app currently supports a single-hop search flow:

  1. Model replies with [SEARCH: query]
  2. Backend fetches results
  3. Model writes final answer

To make it true deep research, implement a multi-step research loop.

Recommended architecture

  1. Add a planner phase.
  • Generate a research plan with sub-questions (not final answer yet).
  1. Add iterative retrieval.
  • Execute multiple search rounds per sub-question.
  • Keep a research_state object: queries used, sources found, confidence, unresolved questions.
  1. Add source quality scoring.
  • Score by recency, domain trust, cross-source agreement, and specificity.
  • Prefer primary sources over summaries.
  1. Add evidence synthesis.
  • Build answer from claims + citations, not from a single model pass.
  • Keep quote snippets and URL metadata in memory while generating.
  1. Add contradiction checks.
  • If high-impact claims disagree, run reconciliation queries before final output.
  1. Add explicit uncertainty.
  • Return confidence per section and list what is still unknown.

Minimal implementation plan in this codebase

  1. Create backend/services/research_service.py.
  • Method: run_deep_research(question, max_rounds=4)
  • Output structure:
{
	"summary": "...",
	"findings": [{"claim": "...", "sources": ["..."]}],
	"gaps": ["..."],
	"confidence": "high|medium|low",
	"sources": [{"title": "...", "url": "...", "snippet": "..."}]
}
  1. Add a new endpoint in backend/app.py.
  • POST /api/research
  • Body: { "question": "...", "depth": "quick|deep" }
  1. Update backend/services/chat_service.py.
  • Route complex prompts to research mode based on intent.
  • Return progressive events for each research round during streaming.
  1. Improve backend/web_search.py.
  • Add deduplication, retries, domain filtering, and result caching.
  1. Update frontend in frontend/js/app.js.
  • Show research timeline UI: planning, retrieval rounds, synthesis, final report.

Prompting pattern for deep research

Use a strict output contract at each stage:

  • Stage 1 (Plan): return only JSON plan and queries.
  • Stage 2 (Evidence): return normalized evidence records.
  • Stage 3 (Synthesis): return claims with cited sources.
  • Stage 4 (Audit): return uncertainty and missing evidence.

This separation reduces hallucination and makes behavior testable.

Security Notes

  • Configure API_AUTH_TOKEN to enforce authenticated API calls.
  • Set CORS_ORIGINS to your frontend origin(s) in production.
  • Current rate limits use in-memory storage by default; use Redis for production-scale limiter storage.

Tech Stack

  • Backend: Flask, Groq SDK, Flask-CORS, Flask-Limiter
  • Frontend: Vanilla JS, CSS, Marked.js, Highlight.js
  • Optional persistence: Supabase

License

MIT License

Developed by Dhanush Pillay

About

The Deepfake & Misinformation Defense Grid

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors