sopanam-ai
v1.0.0
Published
SopanamAI - Direct AI chat client with language model support. Built for WhatsApp bots and Node.js apps.
Maintainers
Readme
sopanam-ai
SopanamAI — Direct AI chat client with language model support. Built for WhatsApp bots (Baileys) and Node.js apps — no HTTP server, no API overhead.
Features
- Direct function calls — No HTTP server or API layer
- 5 language models — normal, malayalam, tamil, hindi, english
- Multi-turn conversations — Built-in conversation history tracking
- Auto-authentication — No manual login needed
- Token rotation — Avoids rate limits automatically
- Zero dependencies — Uses only native Node.js APIs
- Node.js 18+ — Native
fetchandcrypto.randomUUID()
Installation
# From local path
npm install /path/to/sopanam-ai
# Or copy the folder into your project's node_modulesUsage
One-shot Chat
const { chat } = require('sopanam-ai');
// Normal mode (no language restriction)
const reply = await chat('What is 2+2?');
// Language-specific
const ml = await chat('Say hello', 'malayalam');
const ta = await chat('Say hello', 'tamil');
const hi = await chat('Say hello', 'hindi');
const en = await chat('Say hello', 'english');Multi-turn Conversation
const { createConversation } = require('sopanam-ai');
const convo = createConversation('malayalam');
const r1 = await convo.ask('നിന്റെ പേരെന്ത?');
const r2 = await convo.ask('നന്ദി!'); // remembers context
// Get history
console.log(convo.getHistory());
// Clear history
convo.clearHistory();In a Baileys WhatsApp Bot
const { chat } = require('sopanam-ai');
sock.ev.on('messages.upsert', async ({ messages }) => {
const msg = messages[0];
if (!msg.message) return;
const text = msg.message.conversation || '';
if (text.startsWith('!ai ')) {
const prompt = text.slice(4);
const reply = await chat(prompt, 'malayalam');
await sock.sendMessage(msg.key.remoteJid, { text: reply });
}
});Configuration
const { configure } = require('sopanam-ai');
configure({
enableRotation: true, // Enable token rotation (default: true)
rotationLimit: 10 // Requests before rotating (default: 10)
});Models
| Model | Description |
|---|---|
| normal | No language restriction |
| malayalam | Responds only in Malayalam (മലയാളം) |
| tamil | Responds only in Tamil (தமிழ்) |
| hindi | Responds only in Hindi (हिन्दी) |
| english | Responds only in English |
API
chat(prompt, model?)
prompt(string) — The user's messagemodel(string, default:'normal') — Language model- Returns:
Promise<string>— The AI response
createConversation(model?, options?)
model(string, default:'normal') — Language modeloptions(object)maxTurns(number, default:20) — Max conversation turns to keep in memory (to prevent overflow)
- Returns:
{ ask(prompt), getHistory(), clearHistory() }
configure(options)
enableRotation(boolean) — Enable/disable token rotationrotationLimit(number) — Requests before rotating session
Error Handling
The package exports custom error classes for better control:
const { chat, errors } = require('sopanam-ai');
try {
await chat('Hello');
} catch (err) {
if (err instanceof errors.NetworkError) {
console.log('Network issue, maybe retry?');
} else if (err instanceof errors.AuthError) {
console.log('Session expired or invalid');
} else {
console.log('Unknown error:', err.message);
}
}MODELS
Object containing all model definitions.
License
MIT
