2023-03-25 13:09:44 -04:00
const { EmbedBuilder } = require ( 'discord.js' ) ;
var unirest = require ( 'unirest' ) ;
const jsonfile = require ( 'jsonfile' )
2023-04-02 17:54:12 -04:00
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 ;
2023-03-25 13:09:44 -04:00
module . exports = {
name : "create-session" ,
description : "create a new session chat" ,
private : true ,
2023-04-02 18:20:06 -04:00
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
} ] ,
2023-03-25 13:09:44 -04:00
run : async ( client , interaction ) => {
const file = './cache/' + interaction . user . id
2023-04-02 17:57:14 -04:00
2023-04-02 18:20:06 -04:00
if ( ! interaction . options . _hoistedOptions [ 0 ] ) {
console . log ( "-- No init-prompt provided, using default --" )
} else [
initPrompt = interaction . options . _hoistedOptions [ 0 ] . value
]
2023-04-02 17:54:12 -04:00
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'
2023-03-25 13:09:44 -04:00
} )
2023-04-02 17:54:12 -04:00
. send ( '' )
. end ( function ( response ) {
console . log ( response . body ) ;
2023-03-25 13:09:44 -04:00
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 ] } ) ;
2023-04-02 17:54:12 -04:00
} ) ;
}
2023-03-25 13:09:44 -04:00
} ;