A modern, AI-powered comment moderation system built with Next.js and OpenRouter AI. This project provides real-time comment validation with context awareness and detailed feedback.
- 🔥 Real-time comment validation
- 🤖 AI-powered content moderation
- 💬 Context-aware responses
- ⏱️ Debounced API calls for better performance
- 📈 Detailed validation statistics
- 💻 Modern React hooks for easy integration
- 🎨 Beautiful UI with Tailwind CSS
- 🚀 Next.js App Router support
npm install @livehashan/comment-check- Set up your environment variables:
OPENROUTER_API_KEY=your_api_key_here
OPENROUTER_MODEL=deepseek/deepseek-chat-v3-0324:free- Create your API route (Next.js):
import { CommentChecker } from '@livehashan/comment-check';
const checker = new CommentChecker(
process.env.OPENROUTER_API_KEY,
process.env.OPENROUTER_MODEL
);
export async function POST(req) {
const body = await req.json();
const result = await checker.checkComment(body);
return new Response(JSON.stringify(result));
}- Use the React hook in your component:
'use client'
import { useCommentCheck } from '@livehashan/comment-check'
export default function CommentForm() {
const [comment, setComment] = useState('')
const { isLoading, result, checkComment } = useCommentCheck()
const handleSubmit = async (e) => {
e.preventDefault()
await checkComment(comment)
}
return (
<form onSubmit={handleSubmit}>
<textarea
value={comment}
onChange={(e) => setComment(e.target.value)}
placeholder="Write your comment here..."
/>
<button type="submit" disabled={isLoading}>
{isLoading ? 'Checking...' : 'Submit'}
</button>
{result && (
<div>
{result.approved ? '✅ Approved!' : '❌ Not Approved'}
<p>{result.reason}</p>
</div>
)}
</form>
)
}- Next.js 13+ (App Router)
- React 18+
- OpenRouter AI API
- TypeScript
- Tailwind CSS
MIT © Hashan
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
If you have any questions or need help, please:
- Open an issue
- Contact me on Twitter
- Visit our Discord community
Made with ❤️ by Hashan