Adding a new options parser and selector so all works with single choices
This commit is contained in:
parent
12456dc29e
commit
e4162bf03e
@ -2,7 +2,9 @@ const { EmbedBuilder } = require('discord.js');
|
||||
var unirest = require('unirest');
|
||||
const jsonfile = require('jsonfile')
|
||||
|
||||
// Start session defaults:
|
||||
var apiUrl = `http://${process.env.INTERNAL_IP}:8008/api/chat/`;
|
||||
|
||||
var model = 'gpt4all';
|
||||
var temperature = 0.1;
|
||||
var topK = 50;
|
||||
@ -13,7 +15,10 @@ 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;
|
||||
// End session defaults
|
||||
|
||||
|
||||
// Set model list we have downloaded
|
||||
let modelList = ["7B", "7B-native", "gpt4all"]
|
||||
|
||||
module.exports = {
|
||||
@ -31,23 +36,72 @@ module.exports = {
|
||||
"description": "A prompt you want to init the chat with, a default is used if not provided.",
|
||||
"required": false,
|
||||
"type": 3
|
||||
}],
|
||||
},
|
||||
{
|
||||
"name": "temperature",
|
||||
"description": "The higher the temperature, the more random the model output. A default 0.1 is used if not provided.",
|
||||
"required": false,
|
||||
"type": 3
|
||||
}
|
||||
],
|
||||
|
||||
|
||||
|
||||
run: async (client, interaction) => {
|
||||
const file = './cache/' + interaction.user.id
|
||||
|
||||
if (!interaction.options._hoistedOptions[1]) {
|
||||
console.log("-- No init-prompt provided, using default --")
|
||||
} else {
|
||||
initPrompt = interaction.options._hoistedOptions[1].value
|
||||
let options = interaction.options._hoistedOptions;
|
||||
let varsToCheck = [
|
||||
{ name: "model", value: null },
|
||||
{ name: "temperature", value: null },
|
||||
{ name: "init-prompt", value: null }
|
||||
];
|
||||
|
||||
for (let i = 0; i < options.length; i++) {
|
||||
let option = options[i];
|
||||
for (let j = 0; j < varsToCheck.length; j++) {
|
||||
let varToCheck = varsToCheck[j];
|
||||
if (option.name === varToCheck.name) {
|
||||
varToCheck.value = option.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!interaction.options._hoistedOptions[0]) {
|
||||
// Now you can access the values of each variable you are interested in:
|
||||
let userInputModel = varsToCheck.find(v => v.name === "model")?.value;
|
||||
let userInputTemperature = varsToCheck.find(v => v.name === "temperature")?.value;
|
||||
let userInputInitPrompt = varsToCheck.find(v => v.name === "init-prompt")?.value;
|
||||
|
||||
// Init Prompt Setting
|
||||
if (userInputInitPrompt === null) {
|
||||
console.log("-- No init-prompt provided, using default --");
|
||||
} else {
|
||||
initPrompt = userInputInitPrompt;
|
||||
}
|
||||
|
||||
// Modal Setting
|
||||
if (userInputModel === null) {
|
||||
console.log("-- No model provided, using default --")
|
||||
} else {
|
||||
if (modelList.includes(interaction.options._hoistedOptions[0].value)) {
|
||||
model = interaction.options._hoistedOptions[0].value
|
||||
if (modelList.includes(userInputModel)) {
|
||||
model = userInputModel;
|
||||
} else {
|
||||
let modelListStr = modelList.join(", ");
|
||||
return interaction.followUp(`You may only use one of the following: ${modelListStr}`);
|
||||
return interaction.followUp(`You may only use one of the following: ${modelListStr}`);
|
||||
}
|
||||
}
|
||||
|
||||
// temperature setting
|
||||
if (userInputTemperature === null) {
|
||||
console.log("-- No temperature provided, using default --")
|
||||
} else {
|
||||
const parsedTemperature = parseFloat(userInputTemperature);
|
||||
if (parsedTemperature >= 0.1 && parsedTemperature <= 2) {
|
||||
// temperature is within range
|
||||
temperature = parsedTemperature;
|
||||
} else {
|
||||
// temperature is outside of range
|
||||
return interaction.followUp(`Temperature must be between 0.1 and 2`);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user