revert back to older style of workflow until new logic is written
This commit is contained in:
parent
73636804a5
commit
2ac55922d2
102
llamabot.js
102
llamabot.js
@ -5,8 +5,6 @@ import { resetResponses, userResetMessages } from './assets/resetMessages.js';
|
|||||||
import { errorMessages, busyResponses } from './assets/errorMessages.js';
|
import { errorMessages, busyResponses } from './assets/errorMessages.js';
|
||||||
import cpuStat from 'cpu-stat';
|
import cpuStat from 'cpu-stat';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import smi from 'node-nvidia-smi';
|
|
||||||
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Client,
|
Client,
|
||||||
@ -15,8 +13,6 @@ import {
|
|||||||
Partials
|
Partials
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
|
||||||
let botMessage; // define a variable to hold the message object
|
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
GatewayIntentBits.DirectMessages,
|
GatewayIntentBits.DirectMessages,
|
||||||
@ -145,7 +141,6 @@ client.on('messageCreate', async (message) => {
|
|||||||
|
|
||||||
const response = await generateResponse(conversation, message);
|
const response = await generateResponse(conversation, message);
|
||||||
|
|
||||||
|
|
||||||
// Append bot message to conversation history
|
// Append bot message to conversation history
|
||||||
conversation.messages.push({
|
conversation.messages.push({
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
@ -261,6 +256,7 @@ async function generateResponse(conversation, message) {
|
|||||||
|
|
||||||
const messagesCopy = [...conversation.messages]; // create a copy of the messages array
|
const messagesCopy = [...conversation.messages]; // create a copy of the messages array
|
||||||
|
|
||||||
|
let botMessage; // define a variable to hold the message object
|
||||||
let time = 0
|
let time = 0
|
||||||
// define a function that shows the system load percentage and updates the message
|
// define a function that shows the system load percentage and updates the message
|
||||||
const showSystemLoad = async () => {
|
const showSystemLoad = async () => {
|
||||||
@ -275,7 +271,10 @@ async function generateResponse(conversation, message) {
|
|||||||
const totalMemory = os.totalmem() / 1024 / 1024 / 1024;
|
const totalMemory = os.totalmem() / 1024 / 1024 / 1024;
|
||||||
const usedMemory = totalMemory - freeMemory;
|
const usedMemory = totalMemory - freeMemory;
|
||||||
|
|
||||||
let filedsData = [
|
const embedData = {
|
||||||
|
color: 0x0099ff,
|
||||||
|
title: 'Please wait.. I am thinking...',
|
||||||
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'System Load',
|
name: 'System Load',
|
||||||
value: `${systemLoad.toFixed(2)}%`,
|
value: `${systemLoad.toFixed(2)}%`,
|
||||||
@ -288,96 +287,17 @@ async function generateResponse(conversation, message) {
|
|||||||
name: 'Time',
|
name: 'Time',
|
||||||
value: `~${time} seconds.`,
|
value: `~${time} seconds.`,
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
|
|
||||||
if (process.env.GPU == 1) {
|
|
||||||
smi(function (err, data) {
|
|
||||||
if (err) {
|
|
||||||
// Handle error if smi function fails
|
|
||||||
console.error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let utilization = data.nvidia_smi_log.gpu.utilization;
|
|
||||||
let gpuUtilization = utilization.gpu_util;
|
|
||||||
let memoryUtilization = utilization.memory_util;
|
|
||||||
let gpuTemp = data.nvidia_smi_log.gpu.temperature.gpu_temp;
|
|
||||||
|
|
||||||
// These are not used until nvidia-docker fixes their support
|
|
||||||
let gpuTarget = data.nvidia_smi_log.gpu.temperature.gpu_target_temperature;
|
|
||||||
let gpuFanSpeed = data.nvidia_smi_log.gpu.fan_speed;
|
|
||||||
|
|
||||||
let filedsData = [
|
|
||||||
{
|
|
||||||
name: 'System Load',
|
|
||||||
value: `${systemLoad.toFixed(2)}%`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Memory Usage',
|
|
||||||
value: `${usedMemory.toFixed(2)} GB / ${totalMemory.toFixed(2)} GB`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'GPU Utilization',
|
|
||||||
value: `${gpuUtilization}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Memory Utilization',
|
|
||||||
value: `${memoryUtilization}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'GPU Temperature',
|
|
||||||
value: `${gpuTemp}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Time',
|
|
||||||
value: `~${time} seconds.`,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const embedData = {
|
|
||||||
color: 0x0099ff,
|
|
||||||
title: 'Please wait.. I am thinking...',
|
|
||||||
fields: filedsData,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// if the message object doesn't exist, create it
|
// if the message object doesn't exist, create it
|
||||||
if (botMessage == null) {
|
if (!botMessage) {
|
||||||
(async () => {
|
(async () => {
|
||||||
botMessage = await message.channel.send({ embeds: [embedData] });
|
botMessage = await message.channel.send({ embeds: [embedData] });
|
||||||
})();
|
})();
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
message.channel.messages.fetch(botMessage.id)
|
|
||||||
.then(message => console.log(message.content)) //it fetched the message - good
|
|
||||||
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
|
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
|
||||||
} catch (error) {
|
|
||||||
return; //the message no longer exists and will be ignored
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const embedData = {
|
|
||||||
color: 0x0099ff,
|
|
||||||
title: 'Please wait.. I am thinking...',
|
|
||||||
fields: filedsData,
|
|
||||||
};
|
|
||||||
|
|
||||||
// if the message object doesn't exist, create it
|
|
||||||
if (botMessage == null) {
|
|
||||||
(async () => {
|
|
||||||
botMessage = await message.channel.send({ embeds: [embedData] });
|
|
||||||
})();
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
message.channel.messages.fetch(botMessage.id)
|
|
||||||
.then(message => console.log(message.content)) //it fetched the message - good
|
|
||||||
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
|
|
||||||
} catch (error) {
|
|
||||||
return; //the message no longer exists and will be ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -409,18 +329,16 @@ async function generateResponse(conversation, message) {
|
|||||||
|
|
||||||
const responseText = choice.message.content;
|
const responseText = choice.message.content;
|
||||||
|
|
||||||
message.channel.messages.fetch(botMessage.id).then(message => message.delete())
|
|
||||||
|
|
||||||
// clear the interval, replace the "please wait" message with the response, and update the message
|
// clear the interval, replace the "please wait" message with the response, and update the message
|
||||||
await clearInterval(refreshInterval);
|
clearInterval(refreshInterval);
|
||||||
console.log(responseText);
|
console.log(responseText);
|
||||||
botMessage = null;
|
botMessage.delete()
|
||||||
|
|
||||||
return responseText;
|
return responseText;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
botMessage = null;
|
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
time = 0
|
time = 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user