File size: 2,870 Bytes
b78e2b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79b96bf
b78e2b2
79b96bf
b78e2b2
 
79b96bf
b78e2b2
 
 
 
 
 
 
 
 
b1d256f
 
 
79b96bf
b78e2b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79b96bf
 
b78e2b2
 
 
79b96bf
b78e2b2
 
 
 
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
const axios = require('axios');
const { v4: uuidv4 } = require('uuid');

const models = {
    'gpt-4o-mini': '25865',
    'gpt-5-nano': '25871',
    'gemini': '25874',
    'deepseek': '25873',
    'claude': '25875',
    'grok': '25872',
    'meta-ai': '25870',
    'qwen': '25869'
};

async function aichat(question, model) {
    let { data: html } = await axios.get(`https://px.nekolabs.my.id/${encodeURIComponent('https://chatgptfree.ai/')}`);
    
    let nonce = html.data.content.match(/"nonce"\s*:\s*"([^&]+)"/);
    if (!nonce) throw new Error('Nonce not found.');
    
    let { data } = await axios.post(`https://px.nekolabs.my.id/${encodeURIComponent('https://chatgptfree.ai/wp-admin/admin-ajax.php')}`, new URLSearchParams({
        action: 'aipkit_frontend_chat_message',
        _ajax_nonce: nonce[1],
        bot_id: models[model],
        session_id: uuidv4(),
        conversation_uuid: uuidv4(),
        post_id: '6',
        message: question
    }).toString(), {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Origin': 'https://chatgptfree.ai',
            'Referer': 'https://chatgptfree.ai/',
            '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'
        }
    });
    
    return data.data.content.data.reply;
}

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

        if (!text) {
            return res.status(400).json({
                author: 'Herza',
                success: false,
                msg: 'Missing required parameter: text'
            });
        }

        if (!model || !models[model]) {
            return res.status(400).json({
                author: 'Herza',
                success: false,
                msg: 'Invalid or missing model parameter',
                available_models: Object.keys(models)
            });
        }

        const result = await aichat(text, model);

        res.json({
            author: 'Herza',
            success: true,
            model: model,
            msg: result.trim()
        });

    } catch (error) {
        console.error('Error fetching from AI:', error);
        res.status(500).json({
            author: 'Herza',
            success: false,
            msg: error.message || 'Terjadi kesalahan saat menghubungi AI.'
        });
    }
};

module.exports = {
    name: 'Model AI Chat',
    description: 'Generate responses using multiple AI models, availabe models is Claude, gpt-4o-mini, gpt-5-nano, gemini, deepseek, grok, meta-ai, qwen',
    type: 'GET',
    routes: ['api/AI/chat'],
    tags: ['ai', 'gpt', 'gemini', 'claude', 'deepseek'],
    parameters: ['text', 'model', 'key'],
    enabled: true,
    main: ['AI'],
    handler
};