fixing creating a new chat

This commit is contained in:
Raven Scott 2023-04-02 23:54:12 +02:00
parent e08e8f6f93
commit 02e28978c6
1 changed files with 26 additions and 14 deletions

View File

@ -2,25 +2,35 @@ 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
// The Auth stuff here is internal to my set up only and may be removed if you use this bot.
// My chat GUI for Serge is locked down by basic auth in apache to safe guard from
// Users issuing mulitple jobs at a time until there is some built in way to do so.
unirest
.post(`https://${process.env.PUBLIC_URL}/api/chat`)
.headers({ 'Accept': 'application/json', 'Content-Type': 'application/json' })
.auth({
user: process.env.USERNAME,
pass: process.env.PASS,
sendImmediately: true
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'
})
.then((response) => {
.send('')
.end(function (response) {
console.log(response.body);
const obj = { id: response.body }
jsonfile.writeFile(file, obj, function (err) {
@ -34,6 +44,8 @@ module.exports = {
.setTimestamp()
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
interaction.followUp({ embeds: [embed] });
})
},
});
}
};