Spaces:
Sleeping
Sleeping
Create hammer.js
Browse files- plugins/hammer.js +126 -0
plugins/hammer.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SCRAPE BY NEKOLABS https://whatsapp.com/channel/0029VbANq6v0VycMue9vPs3u
|
| 2 |
+
const axios = require("axios");
|
| 3 |
+
|
| 4 |
+
const sessions = new Map();
|
| 5 |
+
const SESSION_TIMEOUT = 2 * 60 * 1000;
|
| 6 |
+
|
| 7 |
+
const models = {
|
| 8 |
+
sleepy: "312b3ce9-62dc-4e94-9a40-fb8f60c93ea1",
|
| 9 |
+
sarah: "4f2edc8d-2992-427f-93c2-849fc2d956de",
|
| 10 |
+
myra: "deb86452-e27f-47d0-959d-98bdf53fac16",
|
| 11 |
+
aiko: "c8bfad14-8529-4bf2-a359-b5dd067f2b3b"
|
| 12 |
+
};
|
| 13 |
+
|
| 14 |
+
async function hammerAI(userId, message, model) {
|
| 15 |
+
const url = "https://www.hammerai.com/api/cloud/chat";
|
| 16 |
+
const modelId = models[model.toLowerCase()] || model;
|
| 17 |
+
|
| 18 |
+
if (!sessions.has(userId)) {
|
| 19 |
+
sessions.set(userId, {
|
| 20 |
+
messages: [
|
| 21 |
+
{
|
| 22 |
+
role: "system",
|
| 23 |
+
content: "You are an AI chat assistant. Respond politely and helpfully to the user.",
|
| 24 |
+
},
|
| 25 |
+
],
|
| 26 |
+
timeout: null,
|
| 27 |
+
});
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
const session = sessions.get(userId);
|
| 31 |
+
session.messages.push({ role: "user", content: message });
|
| 32 |
+
|
| 33 |
+
if (session.timeout) clearTimeout(session.timeout);
|
| 34 |
+
session.timeout = setTimeout(() => {
|
| 35 |
+
sessions.delete(userId);
|
| 36 |
+
}, SESSION_TIMEOUT);
|
| 37 |
+
|
| 38 |
+
const payload = {
|
| 39 |
+
authorId: "b081fd42-5c88-460a-8ccd-d801e882faf7",
|
| 40 |
+
userId: "",
|
| 41 |
+
licenseKey: "",
|
| 42 |
+
generateChat: {
|
| 43 |
+
quantizationKey: "vllm-mistralai/Mistral-Nemo-Instruct-2407",
|
| 44 |
+
messages: session.messages,
|
| 45 |
+
temperature: 0.8,
|
| 46 |
+
topP: 0.9,
|
| 47 |
+
topK: 30,
|
| 48 |
+
nPredict: 256,
|
| 49 |
+
repetitionPenalty: 1.1,
|
| 50 |
+
contextSize: 4096,
|
| 51 |
+
mlock: true,
|
| 52 |
+
characterId: modelId,
|
| 53 |
+
},
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
try {
|
| 57 |
+
const { data } = await axios.post(url, payload, {
|
| 58 |
+
headers: {
|
| 59 |
+
"Content-Type": "text/plain;charset=UTF-8",
|
| 60 |
+
"User-Agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36",
|
| 61 |
+
Origin: "https://www.hammerai.com",
|
| 62 |
+
Referer: `https://www.hammerai.com/chat/${modelId}`,
|
| 63 |
+
},
|
| 64 |
+
});
|
| 65 |
+
|
| 66 |
+
session.messages.push({ role: "assistant", content: data });
|
| 67 |
+
return data;
|
| 68 |
+
} catch (err) {
|
| 69 |
+
return `Error: ${err.response?.status || err.message}`;
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
const handler = async (req, res) => {
|
| 74 |
+
try {
|
| 75 |
+
const { chat, model, key } = req.query;
|
| 76 |
+
|
| 77 |
+
if (!chat) {
|
| 78 |
+
return res.status(400).json({
|
| 79 |
+
success: false,
|
| 80 |
+
error: 'Missing required parameter: chat'
|
| 81 |
+
});
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
if (!model) {
|
| 85 |
+
return res.status(400).json({
|
| 86 |
+
success: false,
|
| 87 |
+
error: 'Missing required parameter: model (sleepy, sarah, myra, aiko)'
|
| 88 |
+
});
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
if (!key) {
|
| 92 |
+
return res.status(400).json({
|
| 93 |
+
success: false,
|
| 94 |
+
error: 'Missing required parameter: key'
|
| 95 |
+
});
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
const userId = key;
|
| 99 |
+
const result = await hammerAI(userId, chat, model);
|
| 100 |
+
|
| 101 |
+
res.json({
|
| 102 |
+
author: "Herza",
|
| 103 |
+
success: true,
|
| 104 |
+
model: model,
|
| 105 |
+
response: result
|
| 106 |
+
});
|
| 107 |
+
|
| 108 |
+
} catch (error) {
|
| 109 |
+
res.status(500).json({
|
| 110 |
+
success: false,
|
| 111 |
+
error: error.message
|
| 112 |
+
});
|
| 113 |
+
}
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
module.exports = {
|
| 117 |
+
name: 'HammerAI Chat',
|
| 118 |
+
description: 'Generate responses using HammerAI with different character models',
|
| 119 |
+
type: 'GET',
|
| 120 |
+
routes: ['api/AI/hammerAI'],
|
| 121 |
+
tags: ['ai', 'hammerai', 'chat'],
|
| 122 |
+
main: ['AI'],
|
| 123 |
+
parameters: ['chat', 'model', 'key'],
|
| 124 |
+
enabled: true,
|
| 125 |
+
handler
|
| 126 |
+
};
|