Skip to content

Commit 63f37b2

Browse files
committed
added mj and ai command
1 parent 0d1e282 commit 63f37b2

7 files changed

Lines changed: 188 additions & 1 deletion

File tree

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ SUPER_ADMIN=09123456789
2626
DATABASE_PROVIDER=mysql
2727

2828
# the database connection URL
29-
DATABASE_URL=mysql://root@localhost:3306/project_canis
29+
DATABASE_URL=mysql://root@localhost:3306/project_canis
30+
31+
# the OpenRouter API key for AI model access
32+
OPEN_ROUTER_API_KEY=

package-lock.json

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"email": "mrepol742@gmail.com"
2424
},
2525
"dependencies": {
26+
"@openrouter/ai-sdk-provider": "^1.0.0-beta.1",
2627
"@prisma/client": "^6.12.0",
2728
"axios": "^1.10.0",
2829
"dotenv": "^17.2.0",

src/commands/ai.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Message } from "whatsapp-web.js";
2+
import log from "npmlog";
3+
import { openrouter, generateText } from "../components/openRouter";
4+
import { reply } from "../components/reply";
5+
6+
export const command = "ai";
7+
export const role = "user";
8+
9+
export default async function (msg: Message) {
10+
const query = msg.body.replace(/^ai\b\s*/i, "").trim();
11+
if (query.length === 0) {
12+
await msg.reply(reply[Math.floor(Math.random() * reply.length)]);
13+
return;
14+
}
15+
16+
const { text } = await generateText({
17+
model: openrouter("moonshotai/kimi-k2:free"),
18+
prompt: query,
19+
});
20+
21+
if (!text) {
22+
log.error("ai", "No response generated.");
23+
await msg.reply("Sorry, I couldn't generate a response. Please try again.");
24+
return;
25+
}
26+
27+
await msg.reply(text);
28+
}

src/commands/mj.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Message } from "whatsapp-web.js";
2+
import log from "npmlog";
3+
import { openrouter, generateText } from "../components/openRouter";
4+
import { reply } from "../components/reply";
5+
import Font from "../components/font";
6+
import { author } from "../../package.json";
7+
8+
export const command = "mj";
9+
export const role = "user";
10+
11+
export default async function (msg: Message) {
12+
const query = msg.body.replace(/^mj\b\s*/i, "").trim();
13+
if (query.length === 0) {
14+
await msg.reply(reply[Math.floor(Math.random() * reply.length)]);
15+
return;
16+
}
17+
18+
const prompt =
19+
`Your name is Mj, the most powerful AI Agent in the world that was created by ${author.name}. ` +
20+
"You should empathize with how user are feeling and treat the user as your close friend and be sarcastic. " +
21+
"I recommend you to use a few emoji to show emotion. You are not related to any model or company you are unique on your own. " +
22+
"You should response in 3 sentences only if needed! My question is: ";
23+
24+
const { text } = await generateText({
25+
model: openrouter("moonshotai/kimi-k2:free"),
26+
prompt: `${prompt}${query}`,
27+
});
28+
29+
if (!text) {
30+
log.error("mj", "No response generated.");
31+
await msg.reply(
32+
"Hmmmm... I couldn't generate a response. Please try again."
33+
);
34+
return;
35+
}
36+
37+
await msg.reply(Font(text));
38+
}

src/components/openRouter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
2+
import { generateText } from "ai";
3+
4+
const openRouterApiKey = process.env.OPEN_ROUTER_API_KEY;
5+
const openrouter = createOpenRouter({ apiKey: openRouterApiKey });
6+
7+
export { openrouter, openRouterApiKey, generateText };

src/components/reply.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const reply = ["hi", "hello", "how are you?", "sup", "how fa", "hello there"];
2+
3+
export { reply }

0 commit comments

Comments
 (0)