c59d976c by Leff Tubat

30852_chatbot_chatgpt

1 parent 235e9839
Showing 1 changed file with 30 additions and 13 deletions
......@@ -79,11 +79,11 @@ const user_secret_id = process.env.USER_SECRET_ID || "aiwp_logged_in";
const aiwp_app_id = "chatbot+";
// Primary Open AI Route
app.post('/api', async (req, res) => {
if(!req.get('origin') || (!req.get('origin').includes(req.get('host')))) {
res.status(401);
res.send('Method Not Allowed');
return;
}
// if(!req.get('origin') || (!req.get('origin').includes(req.get('host')))) {
// res.status(401);
// res.send('Method Not Allowed');
// return;
// }
const { message, currentModel, temperature } = req.body;
if (currentModel == "gpt-3.5-turbo" || currentModel == "gpt-3.5-turbo-0301") {
......@@ -151,11 +151,14 @@ app.post('/api', async (req, res) => {
} catch (e) {
console.log('Error encoding prompt text', e);
}
let usage_params = {
aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE
};
if(IS_FREE_USER) {
await setUsage({
aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE
});
}
await setUsage(usage_params);
} else {
await setChatUsage(usage_params);
}
res.json({
usage: usage,
message: anchorme({
......@@ -230,11 +233,14 @@ async function runGPTTurbo(req, res) {
} catch (e) {
console.log('Error encoding prompt text', e);
}
let usage_params = {
aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE
};
if(IS_FREE_USER) {
await setUsage({
aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE
});
}
await setUsage(usage_params);
} else {
await setChatUsage(usage_params);
}
res.json({
prompt: JSON.parse(message),
usage: usage,
......@@ -314,6 +320,14 @@ async function runOpensource(req, res) {
} catch (e) {
console.log('Error encoding prompt text', e);
}
let usage_params = {
aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE
};
if(IS_FREE_USER) {
await setUsage(usage_params);
} else {
await setChatUsage(usage_params);
}
res.json({
prompt: JSON.parse(message),
......@@ -332,6 +346,7 @@ async function runOpensource(req, res) {
}
async function authenticate(params) {
console.log("params", params);
let data = await fetch(`${hostapi}/e/authenticate/v2`, {
method: "POST",
headers: {
......@@ -374,6 +389,8 @@ async function setUsage(params) {
body: JSON.stringify(params),
referrer: "https://chatgpt.ai-pro.org"
});
}
async function setChatUsage(params) {
fetch(`${hostapi}/e/set-chat-usage`, {
method: "POST",
headers: {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!