Adding Memory usage to generation
This commit is contained in:
parent
4ff67ff28b
commit
4e69329501
16
llamabot.js
16
llamabot.js
@ -4,7 +4,12 @@ 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 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: [
|
||||||
@ -177,7 +182,10 @@ async function generateResponse(conversation, message) {
|
|||||||
// 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 () => {
|
||||||
const systemLoad = os.loadavg()[0] / os.cpus().length * 100;
|
const systemLoad = os.loadavg()[0] / os.cpus().length * 100;
|
||||||
const messageData = `Please wait, I am thinking... System Load: ${systemLoad.toFixed(2)}%`;
|
const freeMemory = os.freemem() / 1024 / 1024;
|
||||||
|
const totalMemory = os.totalmem() / 1024 / 1024;
|
||||||
|
const usedMemory = totalMemory - freeMemory;
|
||||||
|
const messageData = `Please wait, I am thinking...\nSystem Load: ${systemLoad.toFixed(2)}%\nMemory Usage: ${usedMemory.toFixed(2)} MB / ${totalMemory.toFixed(2)} MB`;
|
||||||
|
|
||||||
// if the message object doesn't exist, create it
|
// if the message object doesn't exist, create it
|
||||||
if (!botMessage) {
|
if (!botMessage) {
|
||||||
@ -190,8 +198,8 @@ async function generateResponse(conversation, message) {
|
|||||||
// call the function initially
|
// call the function initially
|
||||||
await showSystemLoad();
|
await showSystemLoad();
|
||||||
|
|
||||||
// refresh the system load percentage and update the message every 5 seconds
|
// refresh the system load percentage and update the message every 7 seconds
|
||||||
const refreshInterval = setInterval(showSystemLoad, 5000);
|
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`, {
|
||||||
|
Loading…
Reference in New Issue
Block a user