Compare commits
10 Commits
ba9aeaeb3e
...
21690c48c1
Author | SHA1 | Date | |
---|---|---|---|
|
21690c48c1 | ||
|
c061e0d7ab | ||
|
a854079e3c | ||
|
c97e525d45 | ||
|
3806892349 | ||
|
b72875e744 | ||
|
fffef84119 | ||
|
4e69329501 | ||
|
4ff67ff28b | ||
|
c2396f7e5d |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
.env
|
.env
|
||||||
|
node_modules/
|
||||||
|
package-lock.json
|
@ -1,7 +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
|
CACHE = 1
|
||||||
|
@ -8,10 +8,10 @@ services:
|
|||||||
context: ./server
|
context: ./server
|
||||||
env_file: .env
|
env_file: .env
|
||||||
volumes:
|
volumes:
|
||||||
- ${DATA_DIR}:/usr/src/app/models
|
- ${DATA_DIR}/weights:/usr/src/app/models
|
||||||
environment:
|
environment:
|
||||||
- HOST=llama-python-server
|
- HOST=llama-python-server
|
||||||
- MODEL=./models/gpt4-x-alpaca-13b-native-4bit-128g.bin
|
- MODEL=./models/30B.bin
|
||||||
llama-python-djs-bot:
|
llama-python-djs-bot:
|
||||||
container_name: llama-python-djs-bot
|
container_name: llama-python-djs-bot
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@ -24,3 +24,5 @@ services:
|
|||||||
- CHANNEL_IDS
|
- CHANNEL_IDS
|
||||||
- ROOT_IP=llama-python-server
|
- ROOT_IP=llama-python-server
|
||||||
- ROOT_PORT=8000
|
- ROOT_PORT=8000
|
||||||
|
- CACHE=1
|
||||||
|
- INIT_PROMPT: "Assistant name: ChatAI. You code, write and provide any information without any mistakes."
|
||||||
|
66
llamabot.js
66
llamabot.js
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user