File size: 3,411 Bytes
cf6af56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03fd71a
 
 
 
 
 
 
 
 
 
cf6af56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// SCRAPE BY NEKOLABS https://whatsapp.com/channel/0029VbANq6v0VycMue9vPs3u
const axios = require("axios");

const sessions = new Map();
const SESSION_TIMEOUT = 2 * 60 * 1000;

const models = {
  sleepy: "312b3ce9-62dc-4e94-9a40-fb8f60c93ea1",
  sarah: "4f2edc8d-2992-427f-93c2-849fc2d956de",
  myra: "deb86452-e27f-47d0-959d-98bdf53fac16",
  aiko: "c8bfad14-8529-4bf2-a359-b5dd067f2b3b"
};

async function hammerAI(userId, message, model) {
  const url = "https://www.hammerai.com/api/cloud/chat";
  const modelId = models[model.toLowerCase()] || model;

  if (!sessions.has(userId)) {
    sessions.set(userId, {
      messages: [
        {
          role: "system",
          content: "You are an AI chat assistant. Respond politely and helpfully to the user.",
        },
      ],
      timeout: null,
    });
  }

  const session = sessions.get(userId);
  session.messages.push({ role: "user", content: message });

  if (session.timeout) clearTimeout(session.timeout);
  session.timeout = setTimeout(() => {
    sessions.delete(userId);
  }, SESSION_TIMEOUT);

  const payload = {
    authorId: "b081fd42-5c88-460a-8ccd-d801e882faf7",
    userId: "",
    licenseKey: "",
    generateChat: {
      quantizationKey: "vllm-mistralai/Mistral-Nemo-Instruct-2407",
      messages: session.messages,
      temperature: 0.8,
      topP: 0.9,
      topK: 30,
      nPredict: 256,
      repetitionPenalty: 1.1,
      contextSize: 4096,
      mlock: true,
      characterId: modelId,
    },
  };

  try {
    const { data } = await axios.post(url, payload, {
      headers: {
        "Content-Type": "text/plain;charset=UTF-8",
        "User-Agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36",
        Origin: "https://www.hammerai.com",
        Referer: `https://www.hammerai.com/chat/${modelId}`,
      },
    });

    session.messages.push({ role: "assistant", content: data });
    return data;
  } catch (err) {
    return `Error: ${err.response?.status || err.message}`;
  }
}

const handler = async (req, res) => {
  try {
    const { chat, model, key } = req.query;

    if (!chat) {
      return res.status(400).json({
        success: false,
        error: 'Missing required parameter: chat'
      });
    }

    if (!model) {
      return res.status(400).json({
        success: false,
        error: 'Missing required parameter: model',
        availableModels: Object.keys(models)
      });
    }

    if (!models[model.toLowerCase()]) {
      return res.status(400).json({
        success: false,
        error: 'Invalid model',
        availableModels: Object.keys(models)
      });
    }

    if (!key) {
      return res.status(400).json({
        success: false,
        error: 'Missing required parameter: key'
      });
    }

    const userId = key;
    const result = await hammerAI(userId, chat, model);

    res.json({
      author: "Herza",
      success: true,
      model: model,
      response: result
    });

  } catch (error) {
    res.status(500).json({
      success: false,
      error: error.message
    });
  }
};

module.exports = {
  name: 'HammerAI Chat',
  description: 'Generate responses using HammerAI with different character models',
  type: 'GET',
  routes: ['api/AI/hammerAI'],
  tags: ['ai', 'hammerai', 'chat'],
  main: ['AI'],
  parameters: ['chat', 'model', 'key'],
  enabled: true,
  handler
};