afc7d324 by Administrator

Merge branch '30852_chatbot_chatgpt' into 'master'

30852_chatbot_chatgpt

See merge request !101
2 parents 235e9839 d7fc3bf5
Showing 1 changed file with 23 additions and 6 deletions
...@@ -151,10 +151,13 @@ app.post('/api', async (req, res) => { ...@@ -151,10 +151,13 @@ 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 if(IS_FREE_USER) { 154 let usage_params = {
155 await setUsage({
156 aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE 155 aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE
157 }); 156 };
157 if(IS_FREE_USER) {
158 await setUsage(usage_params);
159 } else {
160 await setChatUsage(usage_params);
158 } 161 }
159 res.json({ 162 res.json({
160 usage: usage, 163 usage: usage,
...@@ -230,10 +233,13 @@ async function runGPTTurbo(req, res) { ...@@ -230,10 +233,13 @@ 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 }
233 if(IS_FREE_USER) { 236 let usage_params = {
234 await setUsage({
235 aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE 237 aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE
236 }); 238 };
239 if(IS_FREE_USER) {
240 await setUsage(usage_params);
241 } else {
242 await setChatUsage(usage_params);
237 } 243 }
238 res.json({ 244 res.json({
239 prompt: JSON.parse(message), 245 prompt: JSON.parse(message),
...@@ -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: {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!