forked from mahmud-aura/HINATA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt.js
More file actions
70 lines (60 loc) · 1.98 KB
/
Copy pathgpt.js
File metadata and controls
70 lines (60 loc) · 1.98 KB
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
const axios = require("axios");
const baseApiUrl = async () => {
const base = await axios.get("https://raw.githubusercontent.com/mahmudx7/exe/main/baseApiUrl.json");
return base.data.mahmud;
};
module.exports = {
config: {
name: "gpt",
version: "1.7",
author: "MahMUD",
countDown: 5,
role: 0,
category: "ai",
guide: "{pn} <question>"
},
onStart: async function ({ api, event, args }) {
if (!args.length && !(event.type === "message_reply" && event.messageReply.attachments.length > 0)) {
return api.sendMessage("Please provide a question.", event.threadID, event.messageID);
}
const query = args.join(" ");
const apiUrl = `${await baseApiUrl()}/api/gpt`;
const requestBody = {
question: query,
contents: [
{
parts: [{ text: query }]
}
]
};
// Handle image reply
if (event.type === "message_reply" && event.messageReply.attachments.length > 0) {
const imageUrl = event.messageReply.attachments[0].url;
try {
const base64Image = await getImageBase64(imageUrl);
requestBody.contents[0].parts.push({
inlineData: { mimeType: "image/jpeg", data: base64Image },
});
} catch (err) {
return api.sendMessage("Failed to process image.", event.threadID, event.messageID);
}
}
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
"Content-Type": "application/json",
"author": module.exports.config.author
},
body: JSON.stringify(requestBody)
});
const data = await response.json();
if (data.error) {
return api.sendMessage(data.error, event.threadID, event.messageID);
}
api.sendMessage(data.response || "Sorry, I couldn't generate a response.", event.threadID, event.messageID);
} catch (error) {
api.sendMessage("An error occurred while fetching the AI response.", event.threadID, event.messageID);
}
}
};