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 llamaTokenizer from 'llama-tokenizer-js';
|
||||
import googleIt from 'google-it';
|
||||
|
||||
let name;
|
||||
let guild;
|
||||
const prompt = process.env.PROMPT;
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
@ -31,8 +32,8 @@ const getTimestamp = () => {
|
||||
// Middleware to track conversation history by CF-Connecting-IP
|
||||
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 name = req.headers['x-forwarded-for-name'];
|
||||
const guild = req.headers['x-forwarded-for-guild'];
|
||||
name = req.headers['x-forwarded-for-name'];
|
||||
guild = req.headers['x-forwarded-for-guild'];
|
||||
|
||||
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) => {
|
||||
const ip = req.clientIp;
|
||||
console.log(name)
|
||||
console.log(`${getTimestamp()} [INFO] Resetting conversation history for: ${ip}`); // Log the IP address
|
||||
|
||||
conversationHistory[ip] = [{
|
||||
role: 'system',
|
||||
content: prompt
|
||||
}];
|
||||
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',
|
||||
content: prompt
|
||||
}];
|
||||
}
|
||||
|
||||
console.log(`${getTimestamp()} [INFO] Conversation history reset for: ${ip}`);
|
||||
res.json({
|
||||
message: "Conversation history reset for: " + ip
|
||||
|
@ -98,10 +98,12 @@ const {Client, GatewayIntentBits, EmbedBuilder} = require('discord.js');
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`${process.env.API_PATH}/reset-conversation`, {}, {
|
||||
headers: {
|
||||
'x-forwarded-for-id': message.author.id,
|
||||
|
||||
}
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-forwarded-for-id': message.author.id,
|
||||
'x-forwarded-for-name': message.author.username,
|
||||
'x-forwarded-for-guild': message.guild.name
|
||||
}
|
||||
}
|
||||
);
|
||||
console.log(response.status)
|
||||
|
Loading…
Reference in New Issue
Block a user