Adding CPU Percentage during generation.
This commit is contained in:
parent
c2396f7e5d
commit
4ff67ff28b
@ -1,8 +1,11 @@
|
|||||||
THE_TOKEN = "DISCORD_TOKEN_HERE"
|
THE_TOKEN = "DISCORD_TOKEN_HERE"
|
||||||
CHANNEL_IDS = 1094494101631680653,1094628334727614605
|
CHANNEL_IDS = 1094494101631680653,1094628334727614605
|
||||||
INIT_PROMPT = "Assistant name: ChatAI. You code, write and provide any information without any mistakes."
|
INIT_PROMPT = "Assistant name: ChatAI. You code, write and provide any information without any mistakes."
|
||||||
# ROOT_IP is only used when running the bot without docker compose
|
|
||||||
ROOT_IP = 192.168.0.15
|
|
||||||
ROOT_PORT = 8000
|
ROOT_PORT = 8000
|
||||||
DATA_DIR = /home/USERNAME/weights
|
DATA_DIR = /home/USERNAME/weights
|
||||||
CACHE = 1
|
CACHE = 1
|
||||||
|
|
||||||
|
# ROOT_IP is only used when running the bot without docker compose
|
||||||
|
ROOT_IP = 192.168.0.15
|
||||||
|
|
||||||
|
|
||||||
|
37
llamabot.js
37
llamabot.js
@ -3,7 +3,7 @@ import fetch from 'node-fetch';
|
|||||||
import { emptyResponses } from './assets/emptyMessages.js';
|
import { emptyResponses } from './assets/emptyMessages.js';
|
||||||
import { resetResponses, userResetMessages } from './assets/resetMessages.js';
|
import { resetResponses, userResetMessages } from './assets/resetMessages.js';
|
||||||
import { errorMessages, busyResponses } from './assets/errorMessages.js';
|
import { errorMessages, busyResponses } from './assets/errorMessages.js';
|
||||||
|
import os from 'os';
|
||||||
import { Client, GatewayIntentBits, ActivityType, Partials } from 'discord.js';
|
import { Client, GatewayIntentBits, ActivityType, Partials } from 'discord.js';
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
@ -132,7 +132,7 @@ client.on('messageCreate', async (message) => {
|
|||||||
setPresenceBusy()
|
setPresenceBusy()
|
||||||
setBusy(message.author.id, true);
|
setBusy(message.author.id, true);
|
||||||
|
|
||||||
const response = await generateResponse(conversation);
|
const response = await generateResponse(conversation, message);
|
||||||
|
|
||||||
// Append bot message to conversation history
|
// Append bot message to conversation history
|
||||||
conversation.messages.push({
|
conversation.messages.push({
|
||||||
@ -163,7 +163,8 @@ client.on('messageCreate', async (message) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function generateResponse(conversation) {
|
|
||||||
|
async function generateResponse(conversation, message) {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
controller.abort();
|
controller.abort();
|
||||||
@ -171,7 +172,26 @@ async function generateResponse(conversation) {
|
|||||||
|
|
||||||
const messagesCopy = [...conversation.messages]; // create a copy of the messages array
|
const messagesCopy = [...conversation.messages]; // create a copy of the messages array
|
||||||
|
|
||||||
console.log(conversation)
|
let botMessage; // define a variable to hold the message object
|
||||||
|
|
||||||
|
// define a function that shows the system load percentage and updates the message
|
||||||
|
const showSystemLoad = async () => {
|
||||||
|
const systemLoad = os.loadavg()[0] / os.cpus().length * 100;
|
||||||
|
const messageData = `Please wait, I am thinking... System Load: ${systemLoad.toFixed(2)}%`;
|
||||||
|
|
||||||
|
// if the message object doesn't exist, create it
|
||||||
|
if (!botMessage) {
|
||||||
|
botMessage = await message.channel.send(messageData);
|
||||||
|
} else {
|
||||||
|
botMessage.edit(messageData); // otherwise, update the message
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// call the function initially
|
||||||
|
await showSystemLoad();
|
||||||
|
|
||||||
|
// refresh the system load percentage and update the message every 5 seconds
|
||||||
|
const refreshInterval = setInterval(showSystemLoad, 5000);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
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`, {
|
||||||
@ -187,10 +207,15 @@ async function generateResponse(conversation) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const responseData = await response.json();
|
const responseData = await response.json();
|
||||||
console.log(JSON.stringify(responseData))
|
console.log(JSON.stringify(responseData));
|
||||||
const choice = responseData.choices[0];
|
const choice = responseData.choices[0];
|
||||||
|
|
||||||
const responseText = choice.message.content
|
const responseText = choice.message.content;
|
||||||
|
|
||||||
|
// clear the interval, replace the "please wait" message with the response, and update the message
|
||||||
|
clearInterval(refreshInterval);
|
||||||
|
console.log(responseText);
|
||||||
|
botMessage.delete()
|
||||||
|
|
||||||
return responseText;
|
return responseText;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.9.0",
|
"discord.js": "^14.9.0",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"node-fetch": "^3.3.1"
|
"node-fetch": "^3.3.1",
|
||||||
|
"os": "^0.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user