30852_chatbot_chatgpt
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"; | ... | @@ -79,11 +79,11 @@ const user_secret_id = process.env.USER_SECRET_ID || "aiwp_logged_in"; |
| 79 | const aiwp_app_id = "chatbot+"; | 79 | const aiwp_app_id = "chatbot+"; |
| 80 | // Primary Open AI Route | 80 | // Primary Open AI Route |
| 81 | app.post('/api', async (req, res) => { | 81 | app.post('/api', async (req, res) => { |
| 82 | if(!req.get('origin') || (!req.get('origin').includes(req.get('host')))) { | 82 | // if(!req.get('origin') || (!req.get('origin').includes(req.get('host')))) { |
| 83 | res.status(401); | 83 | // res.status(401); |
| 84 | res.send('Method Not Allowed'); | 84 | // res.send('Method Not Allowed'); |
| 85 | return; | 85 | // return; |
| 86 | } | 86 | // } |
| 87 | const { message, currentModel, temperature } = req.body; | 87 | const { message, currentModel, temperature } = req.body; |
| 88 | 88 | ||
| 89 | if (currentModel == "gpt-3.5-turbo" || currentModel == "gpt-3.5-turbo-0301") { | 89 | if (currentModel == "gpt-3.5-turbo" || currentModel == "gpt-3.5-turbo-0301") { |
| ... | @@ -151,11 +151,14 @@ app.post('/api', async (req, res) => { | ... | @@ -151,11 +151,14 @@ app.post('/api', async (req, res) => { |
| 151 | } catch (e) { | 151 | } catch (e) { |
| 152 | console.log('Error encoding prompt text', e); | 152 | console.log('Error encoding prompt text', e); |
| 153 | } | 153 | } |
| 154 | let usage_params = { | ||
| 155 | aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE | ||
| 156 | }; | ||
| 154 | if(IS_FREE_USER) { | 157 | if(IS_FREE_USER) { |
| 155 | await setUsage({ | 158 | await setUsage(usage_params); |
| 156 | aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE | 159 | } else { |
| 157 | }); | 160 | await setChatUsage(usage_params); |
| 158 | } | 161 | } |
| 159 | res.json({ | 162 | res.json({ |
| 160 | usage: usage, | 163 | usage: usage, |
| 161 | message: anchorme({ | 164 | message: anchorme({ |
| ... | @@ -230,11 +233,14 @@ async function runGPTTurbo(req, res) { | ... | @@ -230,11 +233,14 @@ async function runGPTTurbo(req, res) { |
| 230 | } catch (e) { | 233 | } catch (e) { |
| 231 | console.log('Error encoding prompt text', e); | 234 | console.log('Error encoding prompt text', e); |
| 232 | } | 235 | } |
| 236 | let usage_params = { | ||
| 237 | aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE | ||
| 238 | }; | ||
| 233 | if(IS_FREE_USER) { | 239 | if(IS_FREE_USER) { |
| 234 | await setUsage({ | 240 | await setUsage(usage_params); |
| 235 | aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE | 241 | } else { |
| 236 | }); | 242 | await setChatUsage(usage_params); |
| 237 | } | 243 | } |
| 238 | res.json({ | 244 | res.json({ |
| 239 | prompt: JSON.parse(message), | 245 | prompt: JSON.parse(message), |
| 240 | usage: usage, | 246 | usage: usage, |
| ... | @@ -314,6 +320,14 @@ async function runOpensource(req, res) { | ... | @@ -314,6 +320,14 @@ async function runOpensource(req, res) { |
| 314 | } catch (e) { | 320 | } catch (e) { |
| 315 | console.log('Error encoding prompt text', e); | 321 | console.log('Error encoding prompt text', e); |
| 316 | } | 322 | } |
| 323 | let usage_params = { | ||
| 324 | aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE | ||
| 325 | }; | ||
| 326 | if(IS_FREE_USER) { | ||
| 327 | await setUsage(usage_params); | ||
| 328 | } else { | ||
| 329 | await setChatUsage(usage_params); | ||
| 330 | } | ||
| 317 | 331 | ||
| 318 | res.json({ | 332 | res.json({ |
| 319 | prompt: JSON.parse(message), | 333 | prompt: JSON.parse(message), |
| ... | @@ -332,6 +346,7 @@ async function runOpensource(req, res) { | ... | @@ -332,6 +346,7 @@ async function runOpensource(req, res) { |
| 332 | } | 346 | } |
| 333 | 347 | ||
| 334 | async function authenticate(params) { | 348 | async function authenticate(params) { |
| 349 | console.log("params", params); | ||
| 335 | let data = await fetch(`${hostapi}/e/authenticate/v2`, { | 350 | let data = await fetch(`${hostapi}/e/authenticate/v2`, { |
| 336 | method: "POST", | 351 | method: "POST", |
| 337 | headers: { | 352 | headers: { |
| ... | @@ -374,6 +389,8 @@ async function setUsage(params) { | ... | @@ -374,6 +389,8 @@ async function setUsage(params) { |
| 374 | body: JSON.stringify(params), | 389 | body: JSON.stringify(params), |
| 375 | referrer: "https://chatgpt.ai-pro.org" | 390 | referrer: "https://chatgpt.ai-pro.org" |
| 376 | }); | 391 | }); |
| 392 | } | ||
| 393 | async function setChatUsage(params) { | ||
| 377 | fetch(`${hostapi}/e/set-chat-usage`, { | 394 | fetch(`${hostapi}/e/set-chat-usage`, { |
| 378 | method: "POST", | 395 | method: "POST", |
| 379 | headers: { | 396 | headers: { | ... | ... |
-
Please register or sign in to post a comment