| 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 | |
| }; |