Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Webot

A production-ready conversational AI chatbot built with LangGraph, Groq LLM, and Streamlit β€” featuring persistent multi-thread memory, real-time streaming, auto-generated chat titles, and a clean ChatGPT-style interface.

Status Python Streamlit LangGraph Groq SQLite License


πŸŽ‰πŸŽ‰πŸŽ‰ APP IS LIVE ON THE INTERNET!

URLs:

πŸ“Œ Table of Contents


πŸ“– About the Project

Webot is a full-featured AI chatbot application that goes beyond a basic LLM wrapper. It manages multiple independent conversation threads, each with its own persistent memory stored in a local SQLite database β€” so your chats survive page refreshes and app restarts.

The backend is powered by LangGraph, a state machine framework that structures the conversation flow as a compiled graph. This makes the architecture scalable, inspectable, and easy to extend with new nodes (tools, RAG, agents, etc.).

On the frontend, Streamlit delivers a clean, responsive chat UI with sidebar thread management, real-time streaming responses, token tracking, and chat export β€” all in a single Python file.


🧠 How It Works

Backend β€” LangGraph State Machine

User Message
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              LangGraph Graph             β”‚
β”‚                                          β”‚
β”‚   START ──► chat_node ──► END            β”‚
β”‚                                          β”‚
β”‚   chat_node:                             β”‚
β”‚   1. Attach system prompt                β”‚
β”‚   2. Trim messages to last 4000 tokens   β”‚
β”‚   3. Invoke Groq LLM                     β”‚
β”‚   4. Log token usage                     β”‚
β”‚   5. Return AI response                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
     SQLite Checkpointer
   (persists state per thread_id)

Frontend β€” Streamlit Session Management

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Streamlit App                      β”‚
β”‚                                                      β”‚
β”‚  Sidebar                    Main Chat                β”‚
β”‚  ─────────                  ─────────                β”‚
β”‚  βž• New Chat                 Chat messages rendered   β”‚
β”‚  ⬇️ Export Chat              st.chat_input box        β”‚
β”‚  Thread list                 st.write_stream()        β”‚
β”‚    β–Ά Active thread           (real-time streaming)   β”‚
β”‚    ✏️ Rename                                          β”‚
β”‚    πŸ—‘οΈ Delete                                          β”‚
β”‚  Token counter                                       β”‚
β”‚  Thread ID display                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Each conversation is identified by a UUID thread ID. LangGraph's SqliteSaver checkpointer stores the full message history per thread, so switching between conversations loads the exact prior context.


✨ Features

  • πŸ’¬ Multi-thread conversations β€” create, switch, rename, and delete independent chat sessions
  • 🧠 Persistent memory β€” chats are saved to SQLite and survive restarts
  • ⚑ Real-time streaming β€” responses stream token-by-token like ChatGPT
  • 🏷️ Auto-generated titles β€” first message automatically generates a smart thread title via LLM
  • ✏️ Rename & delete threads β€” full conversation management from the sidebar
  • ⬇️ Export chat β€” download any conversation as a .txt file
  • βœ‚οΈ Context trimming β€” automatically trims to last 4,000 tokens to prevent cost blowup
  • 🌐 Multilingual β€” responds in whatever language the user writes in
  • πŸ“Š Token tracking β€” live session token count displayed in sidebar
  • πŸ”’ Secure config β€” API key loaded from .env, never hardcoded

πŸ› οΈ Tech Stack

Layer Technology Purpose
LLM Groq β€” llama-3.1-8b-instant Ultra-fast chat inference
Orchestration LangGraph State machine graph for conversation flow
Memory LangGraph SqliteSaver Persistent per-thread checkpointing
Database SQLite (chatbot.db) Local storage for chat history
Frontend Streamlit Full chat UI with sidebar
LLM Client LangChain Groq Groq API wrapper
Language Python 3.10+ Core language

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Streamlit Frontend                        β”‚
β”‚                        app.py                                β”‚
β”‚                                                              β”‚
β”‚  Session State:                                              β”‚
β”‚  β€’ message_history  β€” current thread messages                β”‚
β”‚  β€’ chat_threads     β€” list of all thread metadata            β”‚
β”‚  β€’ thread_id        β€” active UUID thread                     β”‚
β”‚  β€’ total_tokens     β€” running token estimate                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚  chatbot.stream() / chatbot.get_state()
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    LangGraph Backend                         β”‚
β”‚                      Backend.py                              β”‚
β”‚                                                              β”‚
β”‚   StateGraph(ChatState)                                      β”‚
β”‚   START ──► chat_node ──► END                                β”‚
β”‚                                                              β”‚
β”‚   chat_node:                                                 β”‚
β”‚   β€’ System prompt injection                                  β”‚
β”‚   β€’ trim_messages (last 4000 tokens)                         β”‚
β”‚   β€’ llm.invoke()                                             β”‚
β”‚   β€’ Token usage logging                                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚  read / write per thread_id
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  SQLite Checkpointer                         β”‚
β”‚                    chatbot.db                                β”‚
β”‚                                                              β”‚
β”‚   Stores full message state per thread_id                    β”‚
β”‚   Enables conversation persistence & resumption             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Groq API                                β”‚
β”‚               llama-3.1-8b-instant                           β”‚
β”‚          temp: 0.7 | max_tokens: 1024 | retries: 3           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

Webot/
β”‚
β”œβ”€β”€ Backend.py          # LangGraph graph, LLM setup, SQLite checkpointer
β”œβ”€β”€ app.py              # Streamlit frontend β€” full chat UI
β”‚
β”œβ”€β”€ chatbot.db          # SQLite database (auto-created on first run)
β”‚
β”œβ”€β”€ .env                # API keys β€” never commit this
β”œβ”€β”€ .env.example        # Safe template to share
β”œβ”€β”€ requirements.txt    # Python dependencies
β”œβ”€β”€ .gitignore
└── README.md

πŸš€ Getting Started

Prerequisites


1. Clone the repository

git clone https://github.com/cookieshop02/Webot.git
cd Webot

2. Create and activate a virtual environment

python -m venv venv

# macOS / Linux
source venv/bin/activate

# Windows
venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

4. Set up environment variables

cp .env.example .env

Edit .env and add your Groq API key.

5. Run the app

streamlit run app.py

Open http://localhost:8501 β€” and start chatting! πŸŽ‰

The SQLite database (chatbot.db) is created automatically on first run. No setup needed.


πŸ” Environment Variables

# Required
GROQ_API_KEY=your_groq_api_key_here

# Optional β€” defaults to ./chatbot.db
DB_PATH=./chatbot.db

Get your free Groq API key at console.groq.com.

⚠️ Never commit your .env file. It is already listed in .gitignore.

Commit this as .env.example:

GROQ_API_KEY=
DB_PATH=./chatbot.db

πŸ’‘ Usage

Once the app is running at http://localhost:8501:

Action How
Start a new chat Click βž• New Chat in the sidebar
Ask a question Type in the chat box and press Enter
Switch conversations Click any thread in the sidebar
Rename a thread Click ✏️ next to the thread name
Delete a thread Click πŸ—‘οΈ next to the thread name
Export a chat Click ⬇️ Export Chat in the sidebar
View token usage Check the bottom of the sidebar

Chats are automatically saved β€” close and reopen the app and your conversations will still be there.


Changelog

v4.0.0

  • Added JWT authentication (register, login, protected routes)
  • Added Docker support β€” run entire app with one command
  • Migrated checkpointer to PostgreSQL

v3.0.0

v3 β€” Migrated to PostgreSQL

v2.0.0

  • Added FastAPI layer as backend API
  • Frontend now communicates via REST API
  • Separated concerns β€” frontend, routes, schemas

v1.0.0

  • Initial release
  • Streamlit frontend directly connected to LangGraph

🀝 Contributing

Contributions are welcome!

# 1. Fork the repo
# 2. Create a feature branch
git checkout -b feature/your-feature-name

# 3. Commit your changes
git commit -m "Add: your feature description"

# 4. Push and open a Pull Request
git push origin feature/your-feature-name

πŸ“„ License

This project is licensed under the MIT License.


Built with ❀️ by cookieshop02

About

A mini bot

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages