Compare commits

..

10 Commits

Author SHA1 Message Date
Raven Scott
21690c48c1 Adding CPU Percentage during generation. 2023-04-16 19:29:55 -07:00
Raven Scott
c061e0d7ab Moving init_prompt for chat to .env 2023-04-16 19:27:15 -07:00
GooeyTuxedo
a854079e3c Containerize bot and server in one stack. 2023-04-16 19:25:26 -07:00
Raven Scott
c97e525d45 adding aprox 2023-04-17 04:02:16 +02:00
Raven Scott
3806892349 remove odd artifact 2023-04-17 03:57:02 +02:00
Raven Scott
b72875e744 Adding timer 2023-04-17 03:56:09 +02:00
Raven Scott
fffef84119 Making system status reporting better 2023-04-17 03:17:15 +02:00
Raven Scott
4e69329501 Adding Memory usage to generation 2023-04-17 02:30:38 +02:00
Raven Scott
4ff67ff28b Adding CPU Percentage during generation. 2023-04-17 02:07:41 +02:00
Raven Scott
c2396f7e5d Moving init_prompt for chat to .env 2023-04-17 00:50:04 +02:00
4 changed files with 66 additions and 13 deletions

View File

@ -1,6 +1,6 @@
THE_TOKEN = "DISCORD_TOKEN_HERE" THE_TOKEN = "DISCORD_TOKEN_HERE"
CHANNEL_IDS = 1094494101631680653,1094628334727614605 CHANNEL_IDS = 1094494101631680653,1094628334727614605
# ROOT_IP is only used when running the bot without docker compose INIT_PROMPT = "Assistant name: ChatAI. You code, write and provide any information without any mistakes."
ROOT_IP = 192.168.0.15
ROOT_PORT = 8000 ROOT_PORT = 8000
DATA_DIR = /home/USERNAME/weights DATA_DIR = /home/USERNAME/weights
CACHE = 1

View File

@ -25,3 +25,4 @@ services:
- ROOT_IP=llama-python-server - ROOT_IP=llama-python-server
- ROOT_PORT=8000 - ROOT_PORT=8000
- CACHE=1 - CACHE=1
- INIT_PROMPT: "Assistant name: ChatAI. You code, write and provide any information without any mistakes."

View File

@ -3,8 +3,15 @@ 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 cpuStat from 'cpu-stat';
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({
intents: [ intents: [
@ -82,7 +89,7 @@ client.on('messageCreate', async (message) => {
// Only respond in the specified channels // Only respond in the specified channels
if (!channelIDs.includes(message.channel.id)) { if (!channelIDs.includes(message.channel.id)) {
return; return;
} }
if (message.author.bot) return; // Ignore messages from bots if (message.author.bot) return; // Ignore messages from bots
@ -104,7 +111,7 @@ client.on('messageCreate', async (message) => {
if (conversation.messages.length === 0) { if (conversation.messages.length === 0) {
conversation.messages.push({ conversation.messages.push({
role: 'user', role: 'user',
content: ` Assistant name: ChatAI. You code, write and provide any information without any mistakes.` content: ` ${process.env.INIT_PROMPT}`
}); });
conversation.messages.push({ conversation.messages.push({
role: 'user', role: 'user',
@ -132,7 +139,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 +170,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 +179,39 @@ 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
let time = 0
// define a function that shows the system load percentage and updates the message
const showSystemLoad = async () => {
time = time + 7
cpuStat.usagePercent(function(err, percent, seconds) {
if (err) {
return console.log(err);
}
const systemLoad = percent //the percentage cpu usage over all cores
const freeMemory = os.freemem() / 1024 / 1024 / 1024;
const totalMemory = os.totalmem() / 1024 / 1024 / 1024;
const usedMemory = totalMemory - freeMemory;
const messageData = `Please wait, I am thinking...\nSystem Load: ${systemLoad.toFixed(2)}%\nMemory Usage: ${usedMemory.toFixed(2)} GB / ${totalMemory.toFixed(2)} GB | Time: ~${time} seconds.`;
// if the message object doesn't exist, create it
if (!botMessage) {
(async () => {
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 7 seconds
const refreshInterval = setInterval(showSystemLoad, 7000);
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,17 +227,23 @@ 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;
} catch (err) { } catch (err) {
throw err; throw err;
} finally { } finally {
clearTimeout(timeout); clearTimeout(timeout);
time = 0
} }
} }

View File

@ -12,6 +12,12 @@
"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",
<<<<<<< HEAD
"os": "^0.1.2",
"cpu-stat": "^2.0.1"
=======
"os": "^0.1.2"
>>>>>>> 6defc62 (Adding CPU Percentage during generation.)
} }
} }