bug fix
This commit is contained in:
parent
da0650d3b6
commit
bc6157e4a1
17
llamabot.js
17
llamabot.js
@ -31,6 +31,9 @@ const channelIDs = process.env.CHANNEL_IDS.split(',');
|
|||||||
// Store Conversations in a MAP
|
// Store Conversations in a MAP
|
||||||
const conversations = new Map();
|
const conversations = new Map();
|
||||||
|
|
||||||
|
let botMessage; // define a variable to hold the message object
|
||||||
|
|
||||||
|
|
||||||
// Set busy function this allows us to set our bot into busy mode
|
// Set busy function this allows us to set our bot into busy mode
|
||||||
// locking out all other tasks until the current one is complete
|
// locking out all other tasks until the current one is complete
|
||||||
function setBusy(userId, isBusy) {
|
function setBusy(userId, isBusy) {
|
||||||
@ -302,7 +305,6 @@ async function generateResponse(conversation, message) {
|
|||||||
// Copy our messages from MAP
|
// Copy our messages from MAP
|
||||||
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 () => {
|
||||||
@ -348,7 +350,13 @@ async function generateResponse(conversation, message) {
|
|||||||
botMessage = await message.channel.send({ embeds: [embedData] });
|
botMessage = await message.channel.send({ embeds: [embedData] });
|
||||||
})();
|
})();
|
||||||
} else {
|
} else {
|
||||||
botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
|
(async () => {
|
||||||
|
if (!isAnyConversationBusy()) {
|
||||||
|
botMessage.delete()
|
||||||
|
} else {
|
||||||
|
await botMessage.edit({ embeds: [embedData] }); // otherwise, update the message
|
||||||
|
}
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If we do have GPU=1 lets send some card info too!
|
// If we do have GPU=1 lets send some card info too!
|
||||||
@ -410,13 +418,14 @@ async function generateResponse(conversation, message) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
// call the function initially
|
// call the function initially
|
||||||
await showSystemLoad();
|
await showSystemLoad();
|
||||||
|
|
||||||
// Grab the REFRESH_INTERVAL from ENV if not exist, lets use 7 (seconds)
|
// Grab the REFRESH_INTERVAL from ENV if not exist, lets use 7 (seconds)
|
||||||
const refreshInterval = setInterval(showSystemLoad, (process.env.REFRESH_INTERVAL || 7) * 1000);
|
const refreshInterval = setInterval(showSystemLoad, (process.env.REFRESH_INTERVAL || 7) * 1000);
|
||||||
|
|
||||||
try {
|
|
||||||
// Sending request to our API
|
// Sending request to our API
|
||||||
const response = await fetch(`http://${process.env.ROOT_IP}:${process.env.ROOT_PORT}/v1/chat/completions`, {
|
const response = await fetch(`http://${process.env.ROOT_IP}:${process.env.ROOT_PORT}/v1/chat/completions`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -442,7 +451,7 @@ async function generateResponse(conversation, message) {
|
|||||||
// 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
|
||||||
clearInterval(refreshInterval);
|
clearInterval(refreshInterval);
|
||||||
console.log(responseText);
|
console.log(responseText);
|
||||||
botMessage.delete()
|
await botMessage.delete()
|
||||||
botMessage = null;
|
botMessage = null;
|
||||||
return responseText;
|
return responseText;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user