chatbot-ai-db
v0.1.0
Published
AI-powered MongoDB chatbot with Google Generative AI
Maintainers
Readme
🤖 chatbot-ai-db
A flexible TypeScript library for building AI-powered chatbots with MongoDB integration using Google's Gemini (Generative AI).
⚠️ Dual Licensing & Commercial Use
- Free for personal, educational, and non-commercial use.
- Commercial use requires a paid license.
- Contact: Induranga Gunasekara [email protected]
- See LICENSE for details.
🚀 Features
- 🔗 MongoDB Integration — Query and store data with MongoDB
- 🤖 Google Gemini AI — Natural language understanding and response
- 🔄 API Key Rotation — Handles rate limits automatically
- 🧠 Smart Caching — Reduces token usage and speeds up repeated queries
- 🛡️ TypeScript Support — Full typings for safe and modern development
- ⚡ Configurable — Control word limits, query limits, and more
📦 Installation
npm install chatbot-ai-db🟢 Quick Start
import { ChatBot, connect } from 'chatbot-ai-db';
// Connect to MongoDB
await connect('mongodb://localhost:27017/yourDatabase');
// Create a chatbot instance
const chatbot = new ChatBot({
apiKeys: ['YOUR_GOOGLE_AI_API_KEY'],
model: 'gemini-2.0-flash'
});
// Ask a question
const response = await chatbot.chat('Show me the latest orders', { responseWordLimit: 20 });
console.log(response.response);⚙️ Configuration
const chatbot = new ChatBot({
// Required
apiKeys: ['YOUR_PRIMARY_API_KEY', 'YOUR_BACKUP_API_KEY'],
// Optional
model: 'gemini-2.0-flash',
cacheConfig: {
maxSize: 100, // Cache size
ttl: 24 * 60 * 60 * 1000 // Cache time-to-live (ms)
},
queryTimeout: 5000 // MongoDB query timeout (ms)
});📝 Usage Examples
- Example: Set MongoDB query result limit:
await chatbot.chat('Show me all movies from 2020', { resultLimit: 5 }); - Example: Set AI response word limit:
await chatbot.chat('Show me all movies from 2020', { responseWordLimit: 15 }); - See more in
examples/
📚 API Reference
ChatBot class
chat(message: string, options?: ChatOptions): Promise<ChatResponse>— Ask a question or make a data requestresetChat(): Promise<void>— Clear chat historygetStats(): UsageStats— Get usage and cache statistics
connect(uri: string, options?)
Connect to your MongoDB database before using the chatbot.
🛠️ Advanced
- See more usage in the
examples/folder for advanced usage, custom word limits, and more. - Full TypeScript types included.
📝 License
MIT © 2025
