Skip to content
imran6932Public

About

Freetalk Chatbot AI

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

24 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FreeTalk β€” AI Companion Chatbot with Admin Dashboard

A full-stack conversational AI application built with React, FastAPI, Groq API, and Redis. Includes a companion chatbot frontend and an admin dashboard to view all user conversations and metadata.


πŸš€ Live Demo

🎯 Features

User App (Frontend)

  • πŸ’¬ Real-time chat with Groq API-powered LLM
  • 🌍 Multi-language support β€” Hindi, English, Hinglish
  • πŸ‘₯ Dynamic companion persona β€” Priya (for male users) / Imran (for female users)
  • πŸ“± Device detection β€” tracks device name per user
  • πŸ’Ύ Full chat history β€” stored in Redis, persists across sessions
  • 🧠 Configurable AI model β€” model specified via .env (default: Groq's open-source 120B)
  • 🎨 Beautiful dark UI β€” rose/purple accent theme

Admin Dashboard (Separate App)

  • πŸ›‘οΈ Secure login β€” HTTP Basic Auth with credentials from .env
  • πŸ‘₯ User management β€” browse all users with metadata
  • πŸ’¬ Full chat history β€” view complete conversation for any user
  • πŸ“Š User metadata β€” device name, gender, message count, first/last seen timestamps
  • πŸ” Search & filter β€” find users by ID, device, or gender

πŸ“‹ Project Structure

freetalk-v2/
β”œβ”€β”€ backend/                 # FastAPI server
β”‚   β”œβ”€β”€ main.py             # Core API + admin routes
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── .env.example
β”œβ”€β”€ frontend/               # User chat app (React + Vite)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx         # Main app logic
β”‚   β”‚   β”œβ”€β”€ components/     # Chat, header, input, welcome
β”‚   β”‚   β”œβ”€β”€ utils/api.js    # API client
β”‚   β”‚   └── App.css         # Dark theme styles
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.js
└── admin/                  # Admin dashboard (React + Vite)
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ App.jsx         # Auth + dashboard router
    β”‚   β”œβ”€β”€ Login.jsx       # Login page
    β”‚   β”œβ”€β”€ Dashboard.jsx   # Main admin UI
    β”‚   β”œβ”€β”€ UserList.jsx    # User list sidebar
    β”‚   β”œβ”€β”€ ChatView.jsx    # Chat history viewer
    β”‚   β”œβ”€β”€ admin.css
    β”‚   └── main.jsx
    β”œβ”€β”€ index.html
    β”œβ”€β”€ package.json
    └── vite.config.js

πŸš€ Setup

Prerequisites

  • Groq API key (get one from console.groq.com)
  • Redis running on localhost:6379
  • Node.js 16+ and Python 3.8+

Step 1: Backend Setup

cd backend

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# Install dependencies
pip install -r requirements.txt

# Copy and edit .env
cp .env.example .env
# Set ADMIN_USERNAME, ADMIN_PASSWORD, GROQ_API_KEY, and GROQ_DEFAULT_MODEL

# Run server
uvicorn main:app --reload --port 8000

Backend will be live at: http://localhost:8000

Step 2: Frontend Setup (User App)

cd frontend

# Install dependencies
npm install

# Run dev server
npm run dev

Frontend will be live at: http://localhost:5173

Step 3: Admin Dashboard Setup

cd admin

# Install dependencies
npm install

# Run dev server (runs on port 5174)
npm run dev

Admin dashboard will be live at: http://localhost:5174


πŸ”§ Configuration

Backend (.env)

REDIS_HOST=localhost
REDIS_PORT=6379
ADMIN_USERNAME=admin
ADMIN_PASSWORD=your_strong_password_here
GROQ_API_BASE_URL=https://api.groq.com/openai
GROQ_API_KEY=your_groq_api_key_here
GROQ_DEFAULT_MODEL=openai/gpt-oss-120b
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5174

Environment Variables

  • REDIS_HOST β€” Redis hostname (default: localhost)
  • REDIS_PORT β€” Redis port (default: 6379)
  • ADMIN_USERNAME β€” Admin login username
  • ADMIN_PASSWORD β€” Admin login password
  • GROQ_API_BASE_URL β€” Groq API base URL (default: https://api.groq.com/openai)
  • GROQ_API_KEY β€” Your Groq API key (required)
  • GROQ_DEFAULT_MODEL β€” Model to use for chat (default: openai/gpt-oss-120b)
  • ALLOWED_ORIGINS β€” Comma-separated CORS origins

πŸ’¬ How It Works

User Flow

  1. First visit β€” User generates unique ID (stored in localStorage)
  2. Send message β€” App detects device name automatically
  3. Gender detection β€” API extracts gender from first messages
  4. Persona assignment:
    • Male user β†’ Companion name shows as "Priya"
    • Female user β†’ Companion name shows as "Imran"
    • Other β†’ Shows "FreeTalk"
  5. Full history stored β€” All messages saved in Redis with 30-day TTL
  6. Clear chat β€” Removes local data + generates new user ID (no API call)

Admin Flow

  1. Login β€” HTTP Basic Auth with credentials from .env
  2. See all users β€” Lists users with metadata (device, gender, message count)
  3. View history β€” Click any user to see full chat conversation
  4. Filter/search β€” Search by user ID, device name, or gender

πŸ“‘ API Endpoints

Chat Endpoints

  • POST /chat/{user_id} β€” Send message (with device_name in body)
  • GET /history/{user_id} β€” Fetch chat history
  • DELETE /history/{user_id} β€” Clear history (API kept, but frontend doesn't call it)
  • GET /models β€” List available models

Admin Endpoints (HTTP Basic Auth)

  • GET /admin/users β€” List all users with metadata
  • GET /admin/users/{user_id}/history β€” Get full chat history for a user

Health

  • GET /health β€” Check API, Redis, and Groq connectivity

πŸ—„οΈ Redis Key Structure

chat:history:{user_id}     β†’ [messages...]              (TTL: 30 days)
chat:meta:{user_id}        β†’ {device_name, first_seen, last_seen, ...}
gender:{user_id}           β†’ "male" | "female" | "other"
freetalk:users             β†’ Set of all user_ids

🎨 Styling

Both apps use a dark theme with rose/purple accents:

Color Variables:

  • Background: #0f0f13
  • Surface: #1a1a24
  • Accent (Priya): #c2678a (rose)
  • Accent (Arjun): #7c6af7 (purple)
  • Text: #e8e8f0

Fully responsive β€” works on desktop, tablet, mobile.


🧠 Models

Backend uses Groq API models. The model is configured via GROQ_DEFAULT_MODEL in .env:

Recommended models:

  • openai/gpt-oss-120b β€” Powerful open-source model (default)
  • mixtral-8x7b-32768 β€” Fast and efficient
  • llama2-70b-4096 β€” High quality responses

View all available Groq models at console.groq.com.


πŸ” Security

  • Admin login β€” HTTP Basic Auth (use HTTPS in production!)
  • User IDs β€” Random, non-sequential
  • No passwords stored β€” Credentials in .env only
  • Conversation privacy β€” Full history in Redis, admin-only access

For production:

  • Use HTTPS/TLS
  • Add rate limiting
  • Implement JWT or OAuth for admin
  • Use environment variables from a secrets manager

πŸ›‘ Clear Chat Behavior

When user clicks "Clear":

  1. βœ… Removes all localStorage data
  2. βœ… Generates new user ID
  3. βœ… Does NOT call delete API (history remains in Redis for admin)
  4. βœ… Starts fresh conversation

πŸ“Š Admin Dashboard Features

User List

  • Sort by last seen (most recent first)
  • See device type (iPhone, Android, Windows PC, Mac, etc.)
  • Message count per user
  • First and last seen timestamps
  • Gender indicator

Chat View

  • Full conversation history
  • Timestamps for each message (if available)
  • User vs bot messages clearly marked
  • User metadata (device, gender, first/last seen)

🚨 Troubleshooting

Groq API not responding

  • Verify GROQ_API_KEY is set correctly in .env
  • Check your Groq API key has not expired on console.groq.com
  • Ensure GROQ_DEFAULT_MODEL exists and is available in your Groq account
  • Check backend logs for connectivity errors

Redis connection failed

# Check Redis is running
redis-cli ping
# Should return: PONG

# If not installed:
sudo systemctl start redis  # Linux
brew services start redis   # macOS

Admin login fails

  • Verify ADMIN_USERNAME and ADMIN_PASSWORD in .env
  • Check backend is running on port 8000
  • Clear browser auth cache (open dev tools β†’ Network tab)

Frontend can't connect to backend

  • Check backend runs on http://localhost:8000
  • Verify CORS is enabled (should be by default)
  • Check .env in frontend/admin for correct VITE_API_URL

πŸ“ Notes

  • Chat history is never deleted from Redis, only when admin explicitly uses DELETE API
  • User IDs are persistent β€” same ID = same user across sessions
  • Model is set via GROQ_DEFAULT_MODEL in .env at startup (not dynamically changeable)
  • Admin dashboard is separate app on port 5174 to keep concerns clean
  • Previously used Ollama for local model inference, but switched to Groq API for better performance and reliability

πŸŽ“ Learning Outcomes

This project demonstrates:

  • Full-stack development (React + FastAPI)
  • Real-time streaming (SSE)
  • Multi-language NLP prompt engineering
  • Redis for session management
  • Admin authentication and authorization
  • Responsive UI design

πŸ“„ License

MIT β€” Free to use and modify.


Built with ❀️ using React, FastAPI, Groq API, and Redis


About

Freetalk Chatbot AI

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages