63 lines
2.2 KiB
JavaScript
63 lines
2.2 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,
|
|
options: [{
|
|
"name": "init-prompt",
|
|
"description": "A prompt you want to init the chat with, a default is used if not provided.",
|
|
"required": false,
|
|
"type": 3 // 6 is type USER
|
|
}],
|
|
run: async (client, interaction) => {
|
|
const file = './cache/' + interaction.user.id
|
|
|
|
if (!interaction.options._hoistedOptions[0]){
|
|
console.log("-- No init-prompt provided, using default --")
|
|
} else [
|
|
initPrompt = interaction.options._hoistedOptions[0].value
|
|
]
|
|
|
|
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] });
|
|
|
|
|
|
});
|
|
}
|
|
}; |