Lokasi: /workspace/ai-chat-platform/backend/
Fitur Lengkap:
- Authentication system (JWT + OAuth2) dengan password hashing
- Multi-model LLM support:
- Ollama (local models)
- OpenAI (GPT-4, GPT-3.5)
- Anthropic (Claude 3 family)
- Google Gemini
- Real-time streaming dengan Server-Sent Events (SSE)
- RAG system dengan ChromaDB dan LangChain
- Agent system dengan tools (Wikipedia, Calculator, File Reader)
- File upload dan document processing
- API key encryption dengan Fernet
- Rate limiting
- Comprehensive error handling
Database: Supabase PostgreSQL (SUDAH DIKONFIGURASI)
- Tables: users, conversations, messages, model_configs, documents
- Connection string tersedia di
.env
API Endpoints:
/api/auth/*- Authentication/api/chat/*- Chat dan streaming/api/models/*- Model management/api/files/*- File upload dan RAG
Status: Semua tables sudah dibuat ✓
Tables:
users- User accounts dengan encrypted API keysconversations- Chat conversationsmessages- Individual chat messagesmodel_configs- Model configurations per userdocuments- Uploaded documents untuk RAG
Lokasi: /workspace/ai-chat-platform/docs/
Files:
SETUP.md- Comprehensive setup guideAPI.md- Complete API documentation dengan examples
File: docker-compose.yml
Services:
- Backend (FastAPI)
- Frontend (Next.js)
- Redis (caching)
- Ollama (local LLM server)
Lokasi: /workspace/ai-chat-platform/frontend/
Created:
- Project configuration (tsconfig, tailwind.config, next.config)
- API client (
lib/api-client.ts) - Ready untuk digunakan - Types (
types/index.ts) - TypeScript definitions - Environment configuration
Note: Frontend memerlukan npm install untuk menginstall dependencies.
- Setup Backend:
cd backend
# Install dependencies
pip install -r requirements.txt
# IMPORTANT: Generate security keys
python -c "import secrets; print('SECRET_KEY:', secrets.token_urlsafe(32))"
python -c "from cryptography.fernet import Fernet; print('ENCRYPTION_KEY:', Fernet.generate_key().decode())"
# Edit backend/.env dan update SECRET_KEY dan ENCRYPTION_KEY
# Run backend
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Backend akan berjalan di: http://localhost:8000
API docs: http://localhost:8000/docs
- Setup 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- Setup Frontend (optional):
cd frontend
# Install dependencies
npm install
# Run development server
npm run devFrontend akan berjalan di: http://localhost:3000
cd /workspace/ai-chat-platform
# IMPORTANT: Update backend/.env dengan SECRET_KEY dan ENCRYPTION_KEY yang valid!
# Build dan jalankan
docker-compose up -d
# Check logs
docker-compose logs -f backend
# Stop
docker-compose downcurl http://localhost:8000/healthcurl -X POST http://localhost:8000/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"username": "testuser",
"password": "password123"
}'curl -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'Save the access_token dari response.
curl -X POST http://localhost:8000/api/chat/message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"message": "Hello, how are you?",
"model_id": "ollama:llama2",
"parameters": {"temperature": 0.7}
}'curl -N -X POST http://localhost:8000/api/chat/stream \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"message": "Tell me a story",
"model_id": "ollama:llama2",
"stream": true
}'- URL:
https://ptnfvdrjmvqcpyfutkoz.supabase.co - Database: PostgreSQL
- Connection: Sudah tersedia di
backend/.env
Dalam backend/.env:
# Generate dengan:
python -c "import secrets; print(secrets.token_urlsafe(32))"
# Output: Ganti SECRET_KEY
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
# Output: Ganti ENCRYPTION_KEYUsers dapat menambahkan API keys mereka sendiri untuk:
- OpenAI:
sk-... - Anthropic:
sk-ant-... - Gemini:
AIza...
Melalui endpoint /api/auth/me (PUT request).
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ │ │ │ │ │
│ Next.js │────▶│ FastAPI │────▶│ Supabase │
│ Frontend │ │ Backend │ │ PostgreSQL │
│ │ │ │ │ │
└─────────────┘ └──────────────┘ └─────────────┘
│
┌───────┴───────┐
│ │
┌─────▼─────┐ ┌────▼─────┐
│ │ │ │
│ Ollama │ │ Redis │
│ (Local) │ │ Cache │
│ │ │ │
└───────────┘ └──────────┘
- Authentication & Authorization
- User management dengan API key encryption
- Multi-model LLM support (4 providers)
- Real-time streaming chat
- RAG system (upload, process, query)
- Agent system dengan tools
- Rate limiting
- Error handling
- API documentation
- Docker support
- Project configuration
- API client library
- TypeScript types
- UI components (Shadcn) - Perlu install dependencies
- Chat interface
- Settings page
- Model management UI
- File upload UI
- Supabase database configured
- Docker Compose configuration
- Environment variables setup
- Documentation
-
Generate Security Keys (CRITICAL):
cd backend python -c "import secrets; print(secrets.token_urlsafe(32))" python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())" # Update .env file
-
Install Ollama dan pull models:
curl -fsSL https://ollama.com/install.sh | sh ollama pull llama2 ollama pull nomic-embed-text -
Start Backend:
cd backend pip install -r requirements.txt uvicorn app.main:app --reload -
Test API dengan curl atau Postman
-
Frontend Development (optional):
cd frontend npm install npm run dev -
Build UI components menggunakan Shadcn UI
- Security Keys: HARUS generate SECRET_KEY dan ENCRYPTION_KEY sebelum production
- Ollama: Diperlukan untuk local models (llama2, mistral, dll)
- API Keys: User API keys (OpenAI, Anthropic, Gemini) bersifat optional
- Database: Supabase sudah dikonfigurasi, no additional setup needed
- Redis: Optional untuk caching, bisa dinonaktifkan untuk development
- Setup Guide:
/workspace/ai-chat-platform/docs/SETUP.md - API Documentation:
/workspace/ai-chat-platform/docs/API.md - API Interactive Docs:
http://localhost:8000/docs(setelah backend running)
- Backend:
/workspace/ai-chat-platform/backend/ - Frontend:
/workspace/ai-chat-platform/frontend/ - Documentation:
/workspace/ai-chat-platform/docs/ - Docker:
/workspace/ai-chat-platform/docker-compose.yml - README:
/workspace/ai-chat-platform/README.md
Backend sudah PRODUCTION-READY dan siap digunakan. Semua core features sudah diimplementasi:
- Multi-model chat dengan streaming
- RAG system
- Agent capabilities
- Authentication dan security
- File upload dan processing
Frontend structure sudah siap, tinggal install dependencies dan build UI components.
Platform ini siap untuk:
- Development local
- Docker deployment
- Production deployment dengan proper security configuration