Skip to content

Repository files navigation

🤖 Personality Chatbot Server

A Node.js backend chatbot powered by Groq LLM with a unique personality system, memory, and randomness.


🚀 Features

  • 🎭 Strong personality (emoji + pauses + smart/dumb behavior)
  • 🧠 Short-term + long-term memory (MongoDB)
  • 👽 Random alien / elvish / conflict events
  • ⚡ Fast responses using Groq (free LLM API)
  • 🔒 Secure environment variable handling

🛠️ Tech Stack

  • Node.js
  • Express.js
  • MongoDB (Mongoose)
  • Groq API (Free LLM)

📦 Installation & Setup

1. Clone the repository

git clone https://github.com/aditig80/chatbot-server
cd chatbot-server

2. Install dependencies

npm install

3. Create .env file

Copy from .env.example:

PORT=5000
GROQ_API_KEY=your_api_key_here
MONGO_URI=your_mongodb_connection_string

▶️ Running the Server

node server.js

Expected output:

Server running on port 5000
MongoDB connected

🧪 Testing with Postman

Endpoint

POST http://localhost:5000/chat

Request Body (JSON)

{
  "userId": "user1",
  "message": "How do I prepare for interviews?"
}

Response Example

{
  "reply": "💡 You should focus on DSA fundamentals ||| practice mock interviews ||| build projects"
}

📸 Screenshots

1. Postman Request - Response

Postman Request

2. MongoDB Data

MongoDB


🧠 System Prompt Design

The chatbot personality is controlled using a structured system prompt with strict rules:

Key Rules

  1. Emoji Rule

    • Every response starts with exactly one emoji.
  2. Pause Rule

    • Uses ||| as natural pauses.
  3. Dual Intelligence Behavior

    • Career topics → smart, structured, helpful
    • Other topics → dumb, confused, humorous
  4. Random Behaviors

    • Alien language glitches
    • Elvish phrases
    • Mentions of elf vs alien conflict

Why this structure?

  • Ensures consistent personality
  • Creates contrast (smart vs dumb)
  • Makes chatbot feel unique and alive
  • Backend logic enforces rules to avoid LLM inconsistency

🧠 Memory Implementation

Short-Term Memory

  • Stores last 10 messages per user
  • Maintains conversation context

Long-Term Memory (MongoDB)

  • Each user has a document:
{
  "userId": "user1",
  "messages": [
    { "role": "user", "content": "Hello" },
    { "role": "assistant", "content": "..." }
  ]
}

How it works

  1. Fetch conversation from DB
  2. Append new messages
  3. Trim to last 10 messages
  4. Save back to MongoDB

Benefits

  • Persistent memory across sessions
  • Context-aware replies
  • Scalable for multiple users

📁 Project Structure

chatbot-server/
│
├── server.js
├── package.json
├── .env.example
├── README.md
├── screenshots/

🚀 Future Improvements

  • Rate limiting
  • Deployment (Render / Railway)
  • Logging system
  • UI frontend (optional)

👩‍💻 Author

Aditi Gupta

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages