Skip to content
AshminDhunganaPublic

About

ChatForge is a lightweight, embeddable AI chatbot platform built for local and small businesses. Powered by LangChain and any OpenAI-compatible API, it delivers streaming responses, per-session memory, and a smart fallback engine — all configurable via a single `.env` file and deployable with one `<script>` tag.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

35 Commits

Folders and files

Repository files navigation


ChatForge

Plug-and-play AI chatbot platform for local and small businesses.

ChatForge is a lightweight, embeddable chatbot powered by LangChain and any OpenAI-compatible API. Drop it onto any website in minutes — no complex setup, no vendor lock-in.

Version Status Live Demo


FastAPI LangChain Python 3.10+ License: MIT OpenAI Compatible

Getting Started · Configuration · API Reference · Providers · Roadmap


Overview

ChatForge gives any business a production-ready AI chatbot with a single line of HTML. It handles conversation memory, streaming responses, session isolation, and graceful fallback — all configurable through a single .env file.


Live Demo

Try ChatForge here:

👉 https://chatforge-lxry.onrender.com


Features

Feature Description
AI Chat Works with any OpenAI-compatible API — Groq, OpenAI, Together AI, Ollama, and more
Streaming Responses Real-time token streaming for an instant, ChatGPT-style experience
Conversation Memory Retains full context within each visitor session
Quick Reply Buttons Configurable shortcut buttons for your most common customer questions
Smart Fallback Rule-based NLP engine activates automatically when no API key is configured
Rate Limiting Per-session request throttling to protect API usage and control costs
Session Isolation Each visitor receives a unique session ID — no memory bleed between users
Brand Customization Configure widget color, greeting message, and style to match your business
Embeddable Widget A single <script> tag — works on any website or platform
Privacy First Business owners supply their own API keys — ChatForge stores no data

Tech Stack

Layer Technology Purpose
Backend FastAPI + Uvicorn High-performance async API server
AI Layer LangChain + LangGraph + ChatOpenAI Unified interface for any OpenAI-compatible LLM
Streaming StreamingResponse + astream() Real-time token delivery
Memory MemorySaver In-session conversation context
Rate Limiting SlowAPI Per-session abuse prevention
Fallback Rule-based NLP engine Always-on responses without an API key
Widget Vanilla JavaScript Zero-dependency embeddable chat UI
Config .env + python-dotenv Single-file business configuration

Setup & Installation

1. Clone the repository

git clone https://github.com/AshminDhungana/ChatForge.git
cd ChatForge

2. Install dependencies

Requires Python 3.10 or higher.

pip install -r requirements.txt

3. Configure your environment

cp .env.example .env

Edit .env with your business details — see Configuration below.

4. Start the server

uvicorn backend.main:app --reload

The server runs at http://localhost:8000. Interactive API docs are available at http://localhost:8000/docs.

5. Embed the widget

Add this single line to any page's HTML:

<script
  src="http://localhost:8000/widget.js"
  data-project-id="Ashmin-Office"
  data-widget-key="your-random-secret"
></script>

The widget loads automatically — no additional setup required.


Configuration

Copy .env.example to .env and fill in your details:

Variable Required Description
BUSINESS_NAME Yes Your business name, used in chatbot responses
BUSINESS_DESCRIPTION Yes Short description of what your business does
BUSINESS_HOURS Yes Opening hours, e.g. Mon–Sat 9AM–10PM, Sun 11AM–9PM
BUSINESS_PHONE Yes Contact phone number
BUSINESS_ADDRESS Yes Physical address
BUSINESS_WEBSITE Yes Your website URL
PROJECT_ID Yes Unique identifier for this chatbot instance, e.g. ashmin-office
ALLOWED_DOMAINS Yes Comma-separated list of domains allowed to embed the widget
WIDGET_API_KEY No Secret key for widget authentication — recommended for production
QUICK_REPLIES No Comma-separated shortcut button labels shown at chat start
API_KEY No Your LLM provider API key — leave blank to use the fallback engine
API_BASE No Base URL of your LLM provider — see Supported AI Providers
MODEL No Model name to use, e.g. llama-3.1-8b-instant
WIDGET_COLOR No Hex color for the chat widget, e.g. #2563EB
GREETING_MESSAGE No First message shown to visitors when the widget opens
RATE_LIMIT No Max requests per session per minute, e.g. 20/minute (default: 20/minute)

Widget Security

ChatForge supports lightweight widget authentication without requiring a database.

Configure the following variables:

PROJECT_ID="ashmin-office"
ALLOWED_DOMAINS="ashmindhungana.com,www.dhungana_ashmin.com"
WIDGET_API_KEY="your-random-secret"

The backend validates:

  • Project ID
  • Widget API key (if configured)
  • Origin header
  • Referer header
  • Allowed domains

WIDGET_API_KEY is optional but strongly recommended for production. Requests from unauthorized websites are automatically rejected.


API Reference

Chat

POST /api/v1/chat

Request body:

{
  "message": "What are your opening hours?",
  "session_id": "uuid-per-visitor",
  "project_id": "ashmin-office",
  "widget_key": "your-random-secret"
}

Response:

{
  "reply": "We are open Mon–Sat 9AM–10PM, Sun 11AM–9PM.",
  "mode": "ai"
}

Streaming chat

POST /api/v1/chat/stream

Returns a text/event-stream. Tokens are streamed in real time to the widget.

Response modes

Mode Trigger Description
ai API key configured Full LangChain + LLM response with memory
fallback No API key Rule-based NLP keyword matching

Supported AI Providers

Any OpenAI-compatible API works out of the box. Set API_BASE in your .env:

Provider API Base URL Cost Speed
OpenAI https://api.openai.com/v1 Paid ⚡⚡⚡
Groq https://api.groq.com/openai/v1 Free tier ⚡⚡⚡⚡
Together AI https://api.together.xyz/v1 Free tier ⚡⚡⚡
OpenRouter https://openrouter.ai/api/v1 Pay per use ⚡⚡⚡
Ollama http://localhost:11434/v1 Free (local) ⚡⚡

Recommended for small businesses: Groq — free, extremely fast, and no credit card required to start.


How It Works

Streaming responses

Tokens are sent to the widget in real time using LangChain's astream() and FastAPI's StreamingResponse, rather than waiting for the full reply to complete. The result feels instant.

Conversation memory

Each visitor session gets its own LangGraph MemorySaver instance. The bot remembers earlier messages within the same chat. Memory is scoped to the session and cleared when the visitor leaves.

Session isolation

The widget generates a unique UUID per visitor on load. Two visitors chatting simultaneously never share or mix conversation history.

Quick reply buttons

Configurable shortcut buttons appear at the start of the chat. Visitors can tap them instead of typing — useful for common questions like hours, location, and contact info.

Rate limiting

Each session is limited to a configurable number of requests per minute (default: 20/minute) via slowapi. This prevents abuse and protects API usage costs. Adjust with the RATE_LIMIT variable in .env.

Fallback engine

When no API key is set, ChatForge silently switches to a lightweight rule-based engine:

Visitor sends a message
        ↓
No API key detected
        ↓
Keyword matching runs
        ↓
FAQ-style answer returned
        ↓
No match → shows business contact info

The chatbot is always online, even with no AI configuration.


Requirements

  • Python 3.10 or higher
  • An OpenAI-compatible API key (optional — the fallback engine works without one)
  • For Ollama: a locally running Ollama instance at http://localhost:11434

Install all Python dependencies:

pip install -r requirements.txt

📖 User Guide

New to ChatForge? Check out the User Guide for a detailed walkthrough for setting it up for your business.


Contributing

Contributions are welcome.

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m 'Add your feature'
  4. Push to the branch: git push origin feature/your-feature
  5. Open a pull request

For significant changes, please open an issue first to discuss what you'd like to change.


License

Released under the MIT License.


Support

Having trouble? Open an issue on GitHub.


Made with care for local businesses everywhere.

About

ChatForge is a lightweight, embeddable AI chatbot platform built for local and small businesses. Powered by LangChain and any OpenAI-compatible API, it delivers streaming responses, per-session memory, and a smart fallback engine — all configurable via a single `.env` file and deployable with one `<script>` tag.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages