Skip to content

Latest commit

 

History

History
291 lines (213 loc) · 5.56 KB

File metadata and controls

291 lines (213 loc) · 5.56 KB

🤖 Support Bot with RAG

An intelligent customer support chatbot using RAG (Retrieval-Augmented Generation) with OrkaJS, Next.js and NestJS.

📋 Table of contents

🎯 Overview

This project is a complete example of a Support Bot application using RAG technology to provide accurate, knowledge-based answers. It demonstrates the integration of Orka AI into a modern, full-stack architecture.

Technologies used

Frontend:

  • Next.js 14 (App Router)
  • React 18
  • TypeScript
  • TailwindCSS
  • Lucide Icons

Backend:

  • NestJS
  • OrkaJS (RAG & LLM)
  • OpenAI GPT-4
  • TypeScript

Infrastructure:

  • Docker & Docker Compose
  • NPM Workspaces (Mono-repo)

✨ Features

  • 💬 Real-time chat - Intuitive conversation interface
  • 🧠 Intelligent RAG - Answers based on a knowledge base
  • 🎨 Modern UI - Responsive design with smooth animations
  • 🔒 Type-safe - TypeScript end-to-end
  • 🐳 Dockerized - Easy deployment with Docker
  • 📦 Mono-repo - Simplified management with NPM Workspaces

🏗️ Architecture

┌─────────────────┐
│   Frontend      │
│   (Next.js 14)  │
│   Port: 3000    │
└────────┬────────┘
         │
         │ HTTP/REST
         │
┌────────▼────────┐
│   Backend       │
│   (NestJS)      │
│   Port: 3001    │
└────────┬────────┘
         │
         │
    ┌────▼─────┐
    │ Orka AI  │
    │   RAG    │
    └────┬─────┘
         │
    ┌────▼─────┐
    │ OpenAI   │
    │ GPT-4    │
    └──────────┘

📦 Prerequisites

  • Node.js >= 18.0.0
  • npm >= 9.0.0
  • Docker & Docker Compose (optional)
  • OpenAI API key

🚀 Installation

📖 For a detailed installation guide, see INSTALLATION.md

Quick installation

# 1. Install dependencies
npm install

# 2. Configure the backend
cp apps/backend/.env.example apps/backend/.env
# Edit apps/backend/.env and add your OPENAI_API_KEY

# 3. Start the application
npm run dev

# 4. Access http://localhost:3000

⚙️ Configuration

Backend (.env)

NODE_ENV=development
PORT=3001
OPENAI_API_KEY=your_openai_api_key_here

Frontend (.env)

NEXT_PUBLIC_API_URL=http://localhost:3001

💻 Usage

Development mode

# Start backend and frontend simultaneously
npm run dev

# Or separately:
npm run dev:backend   # Backend on http://localhost:3001
npm run dev:frontend  # Frontend on http://localhost:3000

Production mode

# Build
npm run build

# Start
npm start

Access the application

🐳 Docker

Development with Docker

# Start in development mode
docker-compose -f docker-compose.dev.yml up

# With rebuild
docker-compose -f docker-compose.dev.yml up --build

Production with Docker

# Build and start
npm run docker:build
npm run docker:up

# Or directly
docker-compose up --build

# Stop
npm run docker:down

Docker environment variables

Create a .env file at the root:

OPENAI_API_KEY=your_openai_api_key_here

🔌 API Endpoints

POST /api/support/ask

Ask a question to the support bot.

Request:

{
  "question": "How do I reset my password?",
  "conversationId": "optional-conversation-id"
}

Response:

{
  "answer": "To reset your password, follow these steps...",
  "conversationId": "conv_1234567890_abc123"
}

GET /api/support/health

Check the service status.

Response:

{
  "status": "healthy",
  "timestamp": "2024-03-06T15:30:00.000Z"
}

🎨 Customization

Modify the knowledge base

Edit apps/backend/src/support-bot/orka.service.ts in the initializeKnowledgeBase() method:

const supportDocuments = [
  {
    content: `# Your content here`,
    metadata: { category: 'category-name', topic: 'topic-name' },
  },
  // Add more documents...
];

Customize the system prompt

Modify the systemPrompt in apps/backend/src/support-bot/orka.service.ts:

systemPrompt: `You are a personalized support assistant...`

Change the LLM model

In apps/backend/src/support-bot/orka.service.ts:

const llmAdapter = new OpenAIAdapter({
  apiKey,
  model: 'gpt-4-turbo-preview', // Change here
  temperature: 0.7,
});

🧪 Tests

# Backend
cd apps/backend
npm run test

# Frontend
cd apps/frontend
npm run test

Checklist before sharing

  • Remove node_modules and build files
  • Remove all .env.local files (contain API keys)
  • Verify that .gitignore is correct
  • Test installation from scratch

� Licence

MIT

🤝 Contribution

Contributions are welcome! Consult CONTRIBUTING.md for more details.

📧 Support

For any questions, consult:


Developed with ❤️ using OrkaJS