HerzaJ commited on
Commit
b78e2b2
·
verified ·
1 Parent(s): 6893e4d

Create aimodel.js

Browse files
Files changed (1) hide show
  1. plugins/aimodel.js +105 -0
plugins/aimodel.js ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const axios = require('axios');
2
+ const { chromium } = require('playwright');
3
+ const { v4: uuidv4 } = require('uuid');
4
+
5
+ const models = {
6
+ 'gpt-4o-mini': '25865',
7
+ 'gpt-5-nano': '25871',
8
+ 'gemini': '25874',
9
+ 'deepseek': '25873',
10
+ 'claude': '25875',
11
+ 'grok': '25872',
12
+ 'meta-ai': '25870',
13
+ 'qwen': '25869'
14
+ };
15
+
16
+ async function aichat(question, model) {
17
+ const browser = await chromium.launch({ headless: true });
18
+ const context = await browser.newContext({
19
+ userAgent: 'Mozilla/5.0 (Linux; Android 15; SM-F958 Build/AP3A.240905.015) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.86 Mobile Safari/537.36'
20
+ });
21
+ const page = await context.newPage();
22
+
23
+ await page.goto('https://chatgptfree.ai/', { waitUntil: 'networkidle' });
24
+
25
+ const html = await page.content();
26
+ const cookies = await context.cookies();
27
+
28
+ await browser.close();
29
+
30
+ let nonce = html.match(/"nonce"\s*:\s*"([^&]+)"/);
31
+ if (!nonce) throw new Error('Nonce not found.');
32
+
33
+ let cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; ');
34
+
35
+ let { data } = await axios.post('https://chatgptfree.ai/wp-admin/admin-ajax.php', new URLSearchParams({
36
+ action: 'aipkit_frontend_chat_message',
37
+ _ajax_nonce: nonce[1],
38
+ bot_id: models[model],
39
+ session_id: uuidv4(),
40
+ conversation_uuid: uuidv4(),
41
+ post_id: '6',
42
+ message: question
43
+ }).toString(), {
44
+ headers: {
45
+ origin: 'https://chatgptfree.ai',
46
+ referer: 'https://chatgptfree.ai/',
47
+ 'user-agent': 'Mozilla/5.0 (Linux; Android 15; SM-F958 Build/AP3A.240905.015) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.86 Mobile Safari/537.36',
48
+ 'cookie': cookieString
49
+ }
50
+ });
51
+
52
+ return data.data.content.data.reply;
53
+ }
54
+
55
+ const handler = async (req, res) => {
56
+ try {
57
+ const { text, model } = req.query;
58
+
59
+ if (!text) {
60
+ return res.status(400).json({
61
+ author: 'Herza',
62
+ success: false,
63
+ msg: 'Missing required parameter: text'
64
+ });
65
+ }
66
+
67
+ if (!model || !models[model]) {
68
+ return res.status(400).json({
69
+ author: 'Herza',
70
+ success: false,
71
+ msg: 'Invalid or missing model parameter',
72
+ available_models: Object.keys(models)
73
+ });
74
+ }
75
+
76
+ const result = await aichat(text, model);
77
+
78
+ res.json({
79
+ author: 'Herza',
80
+ success: true,
81
+ model: model,
82
+ msg: result.trim()
83
+ });
84
+
85
+ } catch (error) {
86
+ console.error('Error fetching from AI:', error);
87
+ res.status(500).json({
88
+ author: 'Herza',
89
+ success: false,
90
+ msg: error.message || 'Terjadi kesalahan saat menghubungi AI.'
91
+ });
92
+ }
93
+ };
94
+
95
+ module.exports = {
96
+ name: 'AI Chat',
97
+ description: 'Generate responses using multiple AI models',
98
+ type: 'GET',
99
+ routes: ['api/AI/chat'],
100
+ tags: ['ai', 'gpt', 'gemini', 'claude', 'deepseek'],
101
+ parameters: ['text', 'model', 'key'],
102
+ enabled: true,
103
+ main: ['AI'],
104
+ handler
105
+ };