Skip to content

RohanKatara/AI-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Customer Support Chatbot

A real-time AI-powered customer support chatbot built with Google Gemini API and FastAPI. Features streaming responses, conversation memory, smart escalation to human agents, and a modern web UI.

Features

  • Real-time Streaming — Responses appear token-by-token, just like ChatGPT
  • Knowledge Base — Answers questions from a configurable FAQ database
  • Conversation Memory — Maintains context across messages within a session
  • Smart Escalation — Detects frustrated customers and escalates to human agents
  • Modern UI — Clean interface built with Tailwind CSS and Material Design icons
  • Markdown Rendering — AI responses support bold, lists, code blocks, and more
  • Session Management — Multiple users can chat simultaneously

Tech Stack

  • Backend: Python, FastAPI, Uvicorn
  • AI: Google Gemini 2.5 Flash via google-genai SDK
  • Frontend: HTML, Tailwind CSS, Vanilla JavaScript, marked.js
  • Streaming: Server-Sent Events (SSE)

Project Structure

portfolio-chatbot/
├── server.py        # FastAPI backend with API endpoints and SSE streaming
├── chatbot.py       # Gemini API integration, streaming, and escalation logic
├── config.py        # System prompt, FAQ knowledge base, and company config
├── index.html       # Frontend UI with chat interface and sidebar
├── app.py           # Alternative Streamlit UI (legacy)
├── .env             # API key (not committed)
└── requirements.txt # Python dependencies

Setup

1. Clone the repository

git clone https://github.com/RohanKatara/AI-chatbot.git
cd AI-chatbot

2. Install dependencies

pip install -r requirements.txt

3. Add your Gemini API key

Create a .env file in the project root:

GEMINI_API_KEY=your_api_key_here

Get your API key from Google AI Studio.

4. Run the server

uvicorn server:app --host 0.0.0.0 --port 8000

5. Open in browser

Visit http://localhost:8000

How It Works

  1. User sends a message from the browser
  2. FastAPI receives the request and forwards it to the Gemini API
  3. Gemini generates a response using the system prompt + FAQ knowledge base + conversation history
  4. Response is streamed back token-by-token via Server-Sent Events (SSE)
  5. Frontend renders each chunk in real-time with Markdown support
  6. If escalation triggers are detected (e.g., "speak to a human"), the chat is escalated

Customization

To adapt this chatbot for a different business:

  1. config.py — Update COMPANY_NAME, COMPANY_DESCRIPTION, and FAQ_DATA
  2. config.py — Modify the SYSTEM_PROMPT for different tone/rules
  3. index.html — Change branding, colors, and layout
  4. .env — Use your own Gemini API key

API Endpoints

  • GET / — Serves the chat UI
  • POST /api/chat — Send a message, receive streaming AI response
  • POST /api/new-session — Create a new chat session
  • GET /api/faq — Get the FAQ knowledge base
  • GET /api/status — Get AI agent status
  • GET /api/escalation — Get escalation rules and triggers
  • GET /api/memory/{session_id} — Get conversation history

License

MIT

About

Python-based AI chatbot with Flask backend

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors