rai-serge-discord-bot/commands/system/new-chat.js
2023-04-02 23:54:12 +02:00

51 lines
2.1 KiB
JavaScript

const { EmbedBuilder } = require('discord.js');
var unirest = require('unirest');
const jsonfile = require('jsonfile')
var apiUrl = `http://${process.env.INTERNAL_IP}:8008/api/chat/`;
var model = 'gpt4all';
var temperature = 0.1;
var topK = 50;
var topP = 0.95;
var maxLength = 256;
var contextWindow = 512;
var repeatLastN = 64;
var repeatPenalty = 1.3;
var initPrompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request. The response must be accurate, concise and evidence-based whenever possible. A complete answer is always ended by [end of text].';
var nThreads = 7;
module.exports = {
name: "create-session",
description: "create a new session chat",
private: true,
run: async (client, interaction) => {
const file = './cache/' + interaction.user.id
console.log("DEBUG: " + apiUrl + '?model=' + model + '&temperature=' + temperature + '&top_k=' + topK + '&top_p=' + topP + '&max_length=' + maxLength + '&context_window=' + contextWindow + '&repeat_last_n=' + repeatLastN + '&repeat_penalty=' + repeatPenalty + '&init_prompt=' + initPrompt + '&n_threads=' + nThreads)
var req = unirest('POST', apiUrl + '?model=' + model + '&temperature=' + temperature + '&top_k=' + topK + '&top_p=' + topP + '&max_length=' + maxLength + '&context_window=' + contextWindow + '&repeat_last_n=' + repeatLastN + '&repeat_penalty=' + repeatPenalty + '&init_prompt=' + initPrompt + '&n_threads=' + nThreads)
.headers({
'accept': 'application/json'
})
.send('')
.end(function (response) {
console.log(response.body);
const obj = { id: response.body }
jsonfile.writeFile(file, obj, function (err) {
if (err) console.error(err)
})
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle("New Chat Session Started!")
.setDescription(`New Chat Session ID: \n` + response.body)
.setTimestamp()
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
interaction.followUp({ embeds: [embed] });
});
}
};