edit guild, name headers for resets
This commit is contained in:
parent
dfdeec924d
commit
e475e6d374
@ -6,7 +6,8 @@ import cors from 'cors';
|
|||||||
import cheerio from 'cheerio';
|
import cheerio from 'cheerio';
|
||||||
import llamaTokenizer from 'llama-tokenizer-js';
|
import llamaTokenizer from 'llama-tokenizer-js';
|
||||||
import googleIt from 'google-it';
|
import googleIt from 'google-it';
|
||||||
|
let name;
|
||||||
|
let guild;
|
||||||
const prompt = process.env.PROMPT;
|
const prompt = process.env.PROMPT;
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 3000;
|
const port = 3000;
|
||||||
@ -31,8 +32,8 @@ const getTimestamp = () => {
|
|||||||
// Middleware to track conversation history by CF-Connecting-IP
|
// Middleware to track conversation history by CF-Connecting-IP
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
const ip = req.headers['x-forwarded-for-id'] || req.headers['cf-connecting-ip'] || req.headers['x-forwarded-for'] || req.headers['x-real-ip'] || req.ip;
|
const ip = req.headers['x-forwarded-for-id'] || req.headers['cf-connecting-ip'] || req.headers['x-forwarded-for'] || req.headers['x-real-ip'] || req.ip;
|
||||||
const name = req.headers['x-forwarded-for-name'];
|
name = req.headers['x-forwarded-for-name'];
|
||||||
const guild = req.headers['x-forwarded-for-guild'];
|
guild = req.headers['x-forwarded-for-guild'];
|
||||||
|
|
||||||
req.clientIp = ip; // Store the IP in a request property
|
req.clientIp = ip; // Store the IP in a request property
|
||||||
|
|
||||||
@ -542,12 +543,35 @@ app.post('/api/v1/restart-core', (req, res) => {
|
|||||||
|
|
||||||
app.post('/api/v1/reset-conversation', (req, res) => {
|
app.post('/api/v1/reset-conversation', (req, res) => {
|
||||||
const ip = req.clientIp;
|
const ip = req.clientIp;
|
||||||
|
console.log(name)
|
||||||
console.log(`${getTimestamp()} [INFO] Resetting conversation history for: ${ip}`); // Log the IP address
|
console.log(`${getTimestamp()} [INFO] Resetting conversation history for: ${ip}`); // Log the IP address
|
||||||
|
|
||||||
conversationHistory[ip] = [{
|
if (name) {
|
||||||
|
if (guild) {
|
||||||
|
console.log(`${getTimestamp()} [INFO] Incoming request from: ${req.clientIp} | ${name} within ${guild}`); // Log the IP address
|
||||||
|
console.log(`${getTimestamp()} [INFO] Initializing conversation history for: ${req.clientIp}`);
|
||||||
|
|
||||||
|
conversationHistory[req.clientIp] = [{
|
||||||
|
role: 'system',
|
||||||
|
content: `My name is: ${name}, We are chatting inside ${guild} a Discord Server. ` + prompt
|
||||||
|
}];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
conversationHistory[req.clientIp] = [{
|
||||||
|
role: 'system',
|
||||||
|
content: `My name is: ${name} ` + prompt
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`${getTimestamp()} [INFO] Incoming request from: ${req.clientIp}`); // Log the IP address
|
||||||
|
console.log(`${getTimestamp()} [INFO] Initializing conversation history for new IP: ${req.clientIp}`);
|
||||||
|
|
||||||
|
conversationHistory[req.clientIp] = [{
|
||||||
role: 'system',
|
role: 'system',
|
||||||
content: prompt
|
content: prompt
|
||||||
}];
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`${getTimestamp()} [INFO] Conversation history reset for: ${ip}`);
|
console.log(`${getTimestamp()} [INFO] Conversation history reset for: ${ip}`);
|
||||||
res.json({
|
res.json({
|
||||||
message: "Conversation history reset for: " + ip
|
message: "Conversation history reset for: " + ip
|
||||||
|
@ -99,8 +99,10 @@ const {Client, GatewayIntentBits, EmbedBuilder} = require('discord.js');
|
|||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`${process.env.API_PATH}/reset-conversation`, {}, {
|
`${process.env.API_PATH}/reset-conversation`, {}, {
|
||||||
headers: {
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
'x-forwarded-for-id': message.author.id,
|
'x-forwarded-for-id': message.author.id,
|
||||||
|
'x-forwarded-for-name': message.author.username,
|
||||||
|
'x-forwarded-for-guild': message.guild.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user