Skip to content

nd0p/ai-chat-platform

Repository files navigation

AI Chat Platform - Platform Chat AI Multi-Model Self-Hosted

Platform chat AI lengkap seperti ChatGPT dengan support multi-model (Ollama, OpenAI, Anthropic, Gemini), RAG, streaming real-time, dan agent capabilities yang dapat di-self host.

Fitur Utama

Backend (SELESAI)

  • FastAPI backend dengan async/await
  • Multi-model LLM support (Ollama, OpenAI, Anthropic, Gemini)
  • Streaming real-time dengan Server-Sent Events
  • RAG system dengan ChromaDB dan LangChain
  • Agent system dengan tools ecosystem
  • Authentication JWT + OAuth2
  • API key encryption dengan Fernet
  • File upload dan processing
  • Supabase PostgreSQL database

Frontend (Struktur Siap)

  • Next.js 14 dengan App Router
  • TypeScript + TailwindCSS
  • Shadcn UI components
  • Real-time streaming chat interface
  • Model management UI
  • Settings dan preferences
  • File upload dengan drag-drop

Struktur Project

ai-chat-platform/
├── backend/                    # FastAPI Backend (SELESAI)
│   ├── app/
│   │   ├── api/
│   │   │   ├── deps.py        # Dependencies (auth)
│   │   │   └── routes/        # API Routes
│   │   │       ├── auth.py    # Authentication
│   │   │       ├── chat.py    # Chat streaming
│   │   │       ├── models.py  # Model management
│   │   │       └── files.py   # File upload/RAG
│   │   ├── core/
│   │   │   ├── config.py      # Configuration
│   │   │   ├── database.py    # Database connection
│   │   │   └── security.py    # Security utilities
│   │   ├── models/            # SQLAlchemy models
│   │   ├── schemas/           # Pydantic schemas
│   │   ├── services/
│   │   │   ├── llm/           # LLM services
│   │   │   │   ├── base.py           # Base service
│   │   │   │   ├── ollama.py         # Ollama service
│   │   │   │   ├── openai_service.py # OpenAI service
│   │   │   │   ├── anthropic_service.py # Anthropic
│   │   │   │   ├── gemini_service.py # Gemini
│   │   │   │   └── router.py         # Model router
│   │   │   ├── auth_service.py  # Auth service
│   │   │   ├── rag_service.py   # RAG service
│   │   │   └── agent_service.py # Agent service
│   │   └── main.py            # Main application
│   ├── uploads/               # File uploads
│   ├── requirements.txt       # Python dependencies
│   └── .env.example          # Environment template
├── frontend/                  # Next.js Frontend
│   ├── app/                   # Next.js 14 App Router
│   ├── components/            # React components
│   ├── lib/                   # Utilities
│   ├── hooks/                 # Custom hooks
│   └── types/                 # TypeScript types
└── docs/                      # Documentation



## Quick Start

### 1. Generate Security Keys (CRITICAL)
```bash
cd backend

# Generate SECRET_KEY
python -c "import secrets; print('SECRET_KEY='+secrets.token_urlsafe(32))"

# Generate ENCRYPTION_KEY  
python -c "from cryptography.fernet import Fernet; print('ENCRYPTION_KEY='+Fernet.generate_key().decode())"

# Update backend/.env dengan hasil generate di atas

2. Install Ollama (untuk local models)

# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh

# Pull models
ollama pull llama2
ollama pull nomic-embed-text  # untuk RAG embeddings

3. Start Backend

cd backend

# Install dependencies
pip install -r requirements.txt

# Run server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Backend berjalan di: http://localhost:8000 API Docs: http://localhost:8000/docs

4. Test Backend

# Health check
curl http://localhost:8000/health

# Register user
curl -X POST http://localhost:8000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","username":"testuser","password":"password123"}'

API Endpoints

Authentication

  • POST /api/auth/register - Register user
  • POST /api/auth/login - Login
  • GET /api/auth/me - Get profile
  • PUT /api/auth/me - Update profile

Chat

  • POST /api/chat/stream - Stream chat (SSE)
  • POST /api/chat/message - Non-streaming chat

Models

  • GET /api/models/available - List models
  • GET /api/models/validate - Validate connections
  • POST /api/models/ollama/pull - Pull Ollama model

Files & RAG

  • POST /api/files/upload - Upload file
  • POST /api/files/process/{id} - Process document
  • GET /api/files/ - List documents
  • POST /api/files/query - Query documents

Documentation

  • Setup Guide: docs/SETUP.md - Comprehensive setup instructions
  • API Documentation: docs/API.md - Complete API reference
  • Deployment Guide: DEPLOYMENT.md - Deployment summary
  • Interactive API Docs: http://localhost:8000/docs (Swagger UI)

Technology Stack

Backend (PRODUCTION-READY)

  • FastAPI (async Python)
  • SQLAlchemy + Pydantic
  • LangChain + ChromaDB
  • Supabase PostgreSQL
  • JWT Authentication

LLM Providers

  • Ollama (local)
  • OpenAI (GPT-4, GPT-3.5)
  • Anthropic (Claude 3)
  • Google Gemini

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors