Skip to content

RaheesAhmed/OpenGPT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ OpenGPT

The Open Source ChatGPT Alternative - Bring Your Own API Key

Next.js TypeScript Tailwind CSS License: MIT

🎯 Mission: Make AI accessible to everyone by providing a free, open-source ChatGPT interface where users control their own API keys and data.

πŸ“Έ Preview

OpenGPT Screenshot

OpenGPT's clean and intuitive interface - bringing the power of ChatGPT with complete privacy and control

✨ Features

πŸ”₯ Core Features

  • πŸ’¬ ChatGPT-like Interface - Familiar and intuitive chat experience
  • πŸ”‘ Bring Your Own API Key - No subscriptions, use your OpenAI credits directly
  • 🧠 Intelligent Memory System - Advanced conversation context with 4-layer memory architecture
  • πŸ“± Fully Responsive - Perfect experience on desktop, tablet, and mobile
  • ⚑ Real-time Streaming - See responses as they're generated, just like ChatGPT
  • πŸ’Ύ Persistent Chat History - All conversations saved locally with full control
  • πŸ—‚οΈ Smart Chat Management - Organize with search, rename, delete, and auto-titles

🧠 Advanced Memory System

  • 🎯 4-Layer Architecture - Immediate, recent, historical, and important context layers
  • πŸ“Š Token Optimization - 85-90% token reduction for long conversations
  • πŸ”„ Automatic Summarization - Intelligent compression of conversation history
  • πŸ’‘ Context Preservation - Never lose important details from past messages
  • ⚑ Infinite Scalability - Handle 500+ message conversations efficiently

πŸ›‘οΈ Security & Privacy

  • πŸ” Encrypted Local Storage - Your API keys are encrypted and stored locally
  • 🚫 Zero Data Collection - We don't see, store, or analyze your conversations
  • 🏠 Completely Local - All processing happens in your browser
  • πŸ›‘οΈ XSS Protection - Built-in security against common web vulnerabilities
  • πŸ”’ No Server Logging - Your conversations never touch our servers

🎨 User Experience

  • πŸŒ™ Beautiful Dark Theme - Sleek, modern design that's easy on the eyes
  • 🎭 Smooth Animations - Polished micro-interactions throughout
  • ⌨️ Keyboard Shortcuts - Power user friendly with Enter to send
  • πŸ“„ Markdown Support - Rich text rendering with code highlighting
  • πŸ“Ž File Upload - Support for text, code, and document files
  • πŸŽ›οΈ Model Selection - Choose from GPT-4, GPT-3.5-turbo, and more

πŸ”§ MCP Tools Integration

  • πŸ”Œ Model Context Protocol - Extend your agent with external tools and data sources
  • πŸ“‘ Stdio Servers - Local servers accessed via command line (npx, node, python)
  • 🌐 HTTP Servers - Remote or local servers with Streamable HTTP transport
  • πŸ”‘ Environment Variables - Configure API tokens and credentials securely
  • πŸ› οΈ Tool Discovery - Automatically discover and display available tools
  • πŸ‘οΈ Tool Visibility - See all tool calls in real-time with collapsible dropdowns
  • ⚑ Persistent Connections - Servers connect once and stay alive
  • πŸ“Š Tool Results - View arguments, results, and visited URLs

πŸš€ Quick Start

Prerequisites

Installation

  1. Clone the repository
git clone https://github.com/RaheesAhmed/OpenGPT.git
cd OpenGPT
  1. Install dependencies
npm install
# or
yarn install
# or
pnpm install
  1. Run the development server
npm run dev
# or
yarn dev
# or
pnpm dev
  1. Open your browser

    Navigate to http://localhost:3000

  2. Add your API key

    Click the settings icon and securely add your OpenAI API key

That's it! Start chatting with AI while maintaining complete control over your data.

πŸ“– How It Works

πŸ”‘ API Key Security

// Your API key workflow:
1. Enter API key in settings β†’
2. Encrypted with AES-256 β†’
3. Stored locally in browser β†’
4. Never sent to our servers β†’
5. Used directly with OpenAI API

🧠 Memory Architecture

// 4-Layer Memory System:
Layer 1: Immediate Context (5-8 messages)    // 800-1200 tokens
Layer 2: Recent Chunks (summarized)          // 600-900 tokens
Layer 3: Historical Summary (compressed)     // 400-600 tokens
Layer 4: Important Messages (preserved)      // 200-400 tokens

Total: ~3k tokens (regardless of conversation length)

πŸ’Ύ Data Storage

// Local Browser Storage:
β”œβ”€β”€ Encrypted API Keys
β”œβ”€β”€ Chat Messages (by conversation ID)
β”œβ”€β”€ Memory Context (intelligent summaries)
β”œβ”€β”€ User Preferences
└── No server-side data (100% local)

πŸ—οΈ Architecture

Tech Stack

  • Framework: Next.js 15+ (App Router)
  • Language: TypeScript (Strict Mode)
  • Styling: Tailwind CSS + shadcn/ui
  • State Management: React Hooks + Local Storage
  • Memory System: Custom intelligent context management
  • Security: AES-256 encryption for API keys
  • Deployment: Vercel-ready with Docker support

Project Structure

β”œβ”€β”€ app/                    # Next.js App Router
β”‚   β”œβ”€β”€ api/               # API routes (chat, models)
β”‚   β”œβ”€β”€ globals.css        # Global styles
β”‚   └── page.tsx          # Main chat interface
β”œβ”€β”€ components/            # React components
β”‚   β”œβ”€β”€ ui/               # shadcn/ui components
β”‚   β”œβ”€β”€ chat-sidebar.tsx  # Chat management
β”‚   β”œβ”€β”€ sidebar.tsx       # Expanded sidebar
β”‚   β”œβ”€β”€ mini-sidebar.tsx  # Collapsed sidebar
β”‚   └── model-selector.tsx # AI model selection
β”œβ”€β”€ lib/                  # Utility functions
β”‚   β”œβ”€β”€ chat-memory.ts    # Memory system
β”‚   └── utils.ts         # Helper functions
└── public/              # Static assets

πŸ”§ Configuration

Supported Models

All models from OpenAI are supported

Default Settings

const DEFAULT_CONFIG = {
  model: "gpt-4o-mini",
  temperature: 0.7,
  streaming: true,
  memoryEnabled: true,
  autoTitle: true,
};

πŸš€ Deployment

Vercel (One-Click Deploy)

Deploy with Vercel

  1. Click the button above
  2. Fork the repository
  3. Deploy automatically
  4. Start using immediately!

Manual Deployment

# Build for production
npm run build

# Start production server
npm start

Docker

# Build the image
docker build -t opengpt .

# Run the container
docker run -p 3000:3000 opengpt

Self-Hosting

Perfect for complete privacy! Deploy on your own server:

# Clone and build
git clone https://github.com/RaheesAhmed/OpenGPT.git
cd OpenGPT
npm install
npm run build

# Run with PM2 (recommended)
pm2 start npm --name "opengpt" -- start

🀝 Contributing

We welcome contributions! Here's how you can help:

πŸ› Bug Reports

Found a bug? Please create an issue with:

  • Clear description of the problem
  • Steps to reproduce
  • Expected vs actual behavior
  • Screenshots if applicable

πŸ’‘ Feature Requests

Have an idea? We'd love to hear it! Please include:

  • Clear description of the feature
  • Use case and benefits
  • Any implementation ideas

πŸ”§ Pull Requests

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Test thoroughly
  5. Commit with clear messages: git commit -m 'Add amazing feature'
  6. Push to your branch: git push origin feature/amazing-feature
  7. Open a Pull Request

Code Guidelines

  • Use TypeScript for all new code
  • Follow existing code style and patterns
  • Add comments for complex logic
  • Test your changes thoroughly
  • Update documentation if needed

πŸ›Ÿ Support

Get Help

FAQ

❓ Is my API key safe? βœ… Yes! Your API key is encrypted and stored only in your browser. We never see it.

❓ Do you collect my conversations? βœ… No! All conversations stay on your device. Zero data collection.

❓ Can I use this offline? ❌ You need internet for API calls to OpenAI, but your data stays local.

❓ Which models are supported? βœ… All OpenAI models: GPT-4, GPT-4 Turbo, GPT-4o, GPT-3.5 Turbo, and more.

❓ Can I export my chats? βœ… Yes! Your chats are saved locally and can be backed up from browser storage.

❓ Is this really free? βœ… Completely free! You only pay OpenAI for your API usage.

πŸ“Š Why OpenGPT?

Feature OpenGPT ChatGPT Plus Other Alternatives
Cost Free + Your API $20/month Varies
Privacy 100% Local Data collected Usually collected
API Key Control You own it N/A Rarely
Customization Full control Limited Limited
Open Source βœ… MIT License ❌ Closed Rarely
Memory System Advanced 4-layer Basic Basic
Self-Hosting βœ… Yes ❌ No Rarely

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • OpenAI - For the incredible GPT models
  • Vercel - For Next.js and amazing deployment platform
  • shadcn - For beautiful UI components
  • The Open Source Community - For inspiration and contributions

πŸ“ˆ Stats

GitHub stars GitHub forks GitHub issues GitHub last commit GitHub repo size


Made with ❀️ by Rahees Ahmed

⭐ Star us on GitHub if you find this project useful!

πŸ”— Live Demo | Documentation | Contributing


"AI should be accessible to everyone, with complete privacy and control." - OpenGPT Mission

About

The Open Source ChatGPT Alternative - Bring Your Own API Key

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published