A modern URL shortener with integrated AI chat assistant powered by Hugging Face and custom bot verification.
✨ URL Shortening - Create custom short links 🤖 AI Assistant - Chat with Hugging Face AI models 🔐 Bot Verification - Custom math challenge to verify humans 🎨 Modern UI - Dark theme with gradient styling
- Visit https://huggingface.co/settings/tokens
- Create a new token with read access
- Copy the token
- Edit
ai-chat.htmlline 156:
const HF_API_KEY = "hf_YOUR_HUGGING_FACE_API_KEY"; // Paste your token here- Open
ai-chat.htmlin browser or add link in navbar
npm installcp .env.example .env
# Edit .env and add your Hugging Face API keynpm start
# Server runs on http://localhost:3000POST /api/verify- Get math challengePOST /api/verify-answer- Verify answer & get tokenPOST /api/chat- Send message to AI (requires token)
POST /api/detect-bot- Analyze user patternsGET /api/health- Check server status
Use any of these Hugging Face models:
// Conversational AI
'microsoft/DialoGPT-medium' // Good for chat
'facebook/blenderbot-400M-distill' // Friendly conversations
// General text generation
'gpt2' // Simple, fast
'EleutherAI/gpt-neo-125M' // Larger model
// Custom fine-tuned model
'your-username/your-model-name' // Your own model- User visits chat → Shown math challenge
- User solves → Gets verification token
- Token stored → In localStorage
- Token verified → On each message to AI
- Patterns checked → User agent, response time, message length
🔐 Frontend: Tokens expire after 5 minutes 🔐 Backend: Server-side verification required 🔐 API Key: Never expose in frontend (use backend for production) 🔐 Rate limiting: Add in production 🔐 Input validation: Sanitize all inputs
.
├── index.html # Main URL shortener
├── ai-chat.html # AI chat interface (frontend)
├── api-server.js # Backend server (optional)
├── style.css # Styling
├── package.json # Node dependencies
├── .env.example # Environment template
└── README.md # This file
// Get challenge
fetch('/api/verify').then(r => r.json()).then(data => {
console.log(data.question); // "15 + 23 = ?"
});
// Verify answer
fetch('/api/verify-answer', {
method: 'POST',
body: JSON.stringify({
challengeId: data.challengeId,
answer: 38
})
}).then(r => r.json()).then(data => {
localStorage.setItem('token', data.token);
});
// Chat with token
fetch('/api/chat', {
method: 'POST',
headers: {
'x-verification-token': localStorage.getItem('token')
},
body: JSON.stringify({ message: 'Hello!' })
});"Model is loading"
- Hugging Face needs to load model on first request (can take 30s)
"API rate limit exceeded"
- Free tier has limits. Upgrade or use different model
"Verification token invalid"
- Clear localStorage and refresh:
localStorage.clear()
"CORS error"
- Use backend server instead of direct frontend calls
MIT - Feel free to use and modify
Made with ❤️ by Kit-Url