const axios = require('axios');
const https = require('https');
const crypto = require('crypto');
class TypeEasy {
constructor() {
this.pid = '119';
this.channel = 'admin';
this.osType = '1';
this.deviceType = '1';
this.packageId = 'com.gpttype.aikeyboard';
}
generateNoncestr = function () {
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let result = '';
for (let i = 0; i < 32; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
};
sign = function (uuid, params) {
const secret = crypto.createHash('md5').update(uuid, 'utf8').digest('hex').substring(3, 8);
const sorted = Object.keys(params).sort();
let str = '';
for (const key of sorted) {
const val = params[key];
if (val !== null && val !== undefined && val !== '') {
str += key + '=' + val + '&';
}
}
str = str.slice(0, -1);
const signStr = 'keyValue=' + secret + '&' + str;
return crypto.createHash('md5').update(signStr, 'utf8').digest('hex').toUpperCase();
};
chat = async function (prompt) {
try {
if (!prompt) throw new Error('Prompt is required.');
const uuid = crypto.randomUUID();
const timestamp = Math.floor(Date.now() / 1000);
const noncestr = this.generateNoncestr();
const osRelease = '10';
const versionName = '1.1.5';
const params = {
channel: this.channel,
content: prompt,
device_type: this.deviceType,
is_vip: '2',
language_code: 'in',
noncestr: noncestr,
os_type: this.osType,
pid: this.pid,
sver: osRelease,
timestamp: String(timestamp),
uid: '',
user_type: '1',
uuid: uuid,
version: versionName
};
params.sign = this.sign(uuid, params);
const { data } = await axios.post('http://keyword.saetatech.com/api/chat/word', null, {
params: params,
headers: {
'connection': 'Keep-Alive',
'content-type': 'application/x-www-form-urlencoded',
'language-code': 'in',
'user-agent': 'okhttp/4.9.1'
}
});
const result = data?.Content?.text;
if (!result) throw new Error('No result found.');
return result;
} catch (error) {
throw new Error(error.message);
}
};
}
const ai = new TypeEasy();
ai.chat('hai! apa kabar?').then(console.log);