Merge branch 'master' into 31531_apply_tokenization_on_other_llms
# Conflicts: # index.js
Showing
2 changed files
with
31 additions
and
30 deletions
| ... | @@ -105,7 +105,7 @@ function App() { | ... | @@ -105,7 +105,7 @@ function App() { |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | if(currentModel === "openchat_3.5" || currentModel === "zephyr-7B-beta" | 107 | if(currentModel === "openchat_3.5" || currentModel === "zephyr-7B-beta" |
| 108 | || currentModel === "meta-llama/Llama-3-8b-chat-hf" || currentModel === "google/gemma-7b-it") { | 108 | || currentModel === "meta-llama/Llama-3-8b-chat-hf" || currentModel === "google/gemma-2-9b-it") { |
| 109 | // "gpt-3.5-turbo" | 109 | // "gpt-3.5-turbo" |
| 110 | let chatLogOpenSourceNew = [...chatLogOpenSource, { role: "user", content: chatInput }]; | 110 | let chatLogOpenSourceNew = [...chatLogOpenSource, { role: "user", content: chatInput }]; |
| 111 | setChatLogOpenSource(chatLogOpenSourceNew); | 111 | setChatLogOpenSource(chatLogOpenSourceNew); | ... | ... |
| ... | @@ -93,7 +93,7 @@ app.post('/api', async (req, res) => { | ... | @@ -93,7 +93,7 @@ app.post('/api', async (req, res) => { |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | if (currentModel == "openchat_3.5" || currentModel == "zephyr-7B-beta" | 95 | if (currentModel == "openchat_3.5" || currentModel == "zephyr-7B-beta" |
| 96 | || currentModel == "google/gemma-7b-it" || currentModel == "meta-llama/Llama-3-8b-chat-hf" | 96 | || currentModel == "google/gemma-2-9b-it" || currentModel == "meta-llama/Llama-3-8b-chat-hf" |
| 97 | ) { | 97 | ) { |
| 98 | runOpensource(req, res); | 98 | runOpensource(req, res); |
| 99 | 99 | ||
| ... | @@ -195,7 +195,7 @@ async function runGPTTurbo(req, res) { | ... | @@ -195,7 +195,7 @@ async function runGPTTurbo(req, res) { |
| 195 | const moderation = await axios.post("https://api.openai.com/v1/moderations", { | 195 | const moderation = await axios.post("https://api.openai.com/v1/moderations", { |
| 196 | input: query_prompt | 196 | input: query_prompt |
| 197 | }, { headers: { 'content-type': 'application/json', 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` } }); | 197 | }, { headers: { 'content-type': 'application/json', 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` } }); |
| 198 | 198 | ||
| 199 | const validate = await validation(aiwp_app_id, req, res); | 199 | const validate = await validation(aiwp_app_id, req, res); |
| 200 | if(!validate) return; | 200 | if(!validate) return; |
| 201 | const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate; | 201 | const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate; |
| ... | @@ -276,7 +276,7 @@ async function runOpensource(req, res) { | ... | @@ -276,7 +276,7 @@ async function runOpensource(req, res) { |
| 276 | var input = ''; | 276 | var input = ''; |
| 277 | const message_history = JSON.parse(message); | 277 | const message_history = JSON.parse(message); |
| 278 | const query_prompt = message_history.length ? message_history[message_history.length - 1].content : ""; | 278 | const query_prompt = message_history.length ? message_history[message_history.length - 1].content : ""; |
| 279 | 279 | ||
| 280 | const validate = await validation(aiwp_app_id, req, res); | 280 | const validate = await validation(aiwp_app_id, req, res); |
| 281 | if(!validate) return; | 281 | if(!validate) return; |
| 282 | const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate; | 282 | const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate; |
| ... | @@ -289,14 +289,23 @@ async function runOpensource(req, res) { | ... | @@ -289,14 +289,23 @@ async function runOpensource(req, res) { |
| 289 | const response = await axios.post(endpoint_api_url + '/chat/completions', { | 289 | const response = await axios.post(endpoint_api_url + '/chat/completions', { |
| 290 | model: currentModel, | 290 | model: currentModel, |
| 291 | messages: JSON.parse(message), | 291 | messages: JSON.parse(message), |
| 292 | temperature | 292 | max_tokens: 2048, |
| 293 | temperature, | ||
| 294 | top_p: 0.7, | ||
| 295 | top_k: 50, | ||
| 296 | repetition_penalty: 1 | ||
| 293 | }, { | 297 | }, { |
| 294 | headers: { | 298 | headers: { |
| 295 | 'Content-Type': 'application/json', | 299 | 'Content-Type': 'application/json', |
| 296 | 'Authorization': 'Bearer ' + api_key | 300 | 'Authorization': 'Bearer ' + api_key |
| 297 | }, | 301 | }, |
| 298 | }).catch(error => { | 302 | }).catch(error => { |
| 299 | error_msg = error.response.statusText ? error.response.statusText : ''; | 303 | if(error.response?.data?.error?.param === 'max_tokens') { |
| 304 | input = "The output for your prompt is too long for us to process. Please reduce your prompt and try again."; | ||
| 305 | } else { | ||
| 306 | error_msg = error.response.statusText ? error.response.statusText : ''; | ||
| 307 | } | ||
| 308 | console.log("err",error.response.data.error); | ||
| 300 | }); | 309 | }); |
| 301 | 310 | ||
| 302 | if (error_msg !== '') { | 311 | if (error_msg !== '') { |
| ... | @@ -350,7 +359,7 @@ async function authenticate(params) { | ... | @@ -350,7 +359,7 @@ async function authenticate(params) { |
| 350 | body: JSON.stringify(params), | 359 | body: JSON.stringify(params), |
| 351 | referrer: "https://chatgpt.ai-pro.org" | 360 | referrer: "https://chatgpt.ai-pro.org" |
| 352 | }); | 361 | }); |
| 353 | 362 | ||
| 354 | return await data.json(); | 363 | return await data.json(); |
| 355 | } | 364 | } |
| 356 | 365 | ||
| ... | @@ -405,7 +414,7 @@ async function setChatUsage(params) { | ... | @@ -405,7 +414,7 @@ async function setChatUsage(params) { |
| 405 | 414 | ||
| 406 | async function validation (aiwp_app_id, req, res) { | 415 | async function validation (aiwp_app_id, req, res) { |
| 407 | const aiwp_logged_in = req.cookies[user_secret_id] ? decodeURIComponent(req.cookies[user_secret_id]) : ""; | 416 | const aiwp_logged_in = req.cookies[user_secret_id] ? decodeURIComponent(req.cookies[user_secret_id]) : ""; |
| 408 | const limit = req.cookies["WcvYPABR"] ? parseInt(req.cookies["WcvYPABR"].replace(/\D/g, '')) : -1; | 417 | const limit = req.cookies["WcvYPABR"] ? parseInt(req.cookies["WcvYPABR"].replace(/\D/g, '')) : 3; |
| 409 | let IS_FREE_USER = false; | 418 | let IS_FREE_USER = false; |
| 410 | let TRIED_USAGE = 0; | 419 | let TRIED_USAGE = 0; |
| 411 | 420 | ||
| ... | @@ -442,7 +451,7 @@ async function validation (aiwp_app_id, req, res) { | ... | @@ -442,7 +451,7 @@ async function validation (aiwp_app_id, req, res) { |
| 442 | if (data.usage !== null) { | 451 | if (data.usage !== null) { |
| 443 | TRIED_USAGE = parseInt(data.usage); | 452 | TRIED_USAGE = parseInt(data.usage); |
| 444 | } | 453 | } |
| 445 | 454 | ||
| 446 | } | 455 | } |
| 447 | if (IS_FREE_USER && TRIED_USAGE >= limit) { | 456 | if (IS_FREE_USER && TRIED_USAGE >= limit) { |
| 448 | res.json({ status: "invalid", limited: true }); | 457 | res.json({ status: "invalid", limited: true }); |
| ... | @@ -458,39 +467,31 @@ async function validation (aiwp_app_id, req, res) { | ... | @@ -458,39 +467,31 @@ async function validation (aiwp_app_id, req, res) { |
| 458 | 467 | ||
| 459 | // Get Models Route | 468 | // Get Models Route |
| 460 | app.get('/models', async (req, res) => { | 469 | app.get('/models', async (req, res) => { |
| 461 | const response = await openai.listModels(); | 470 | const openai_models = process.env.OPENAI_MODELS ? JSON.parse(process.env.OPENAI_MODELS) : [{"value": "gpt-3.5-turbo", "label": "GPT-3.5"}]; |
| 462 | const models = response.data; | ||
| 463 | const opensource_models = process.env.OPENSOURCE_MODELS ? JSON.parse(process.env.OPENSOURCE_MODELS) : []; | 471 | const opensource_models = process.env.OPENSOURCE_MODELS ? JSON.parse(process.env.OPENSOURCE_MODELS) : []; |
| 464 | 472 | ||
| 465 | models.data = models.data.filter((model) => { | 473 | const models = { |
| 466 | return model.id.indexOf('gpt-3') === 0 | 474 | data: [] |
| 475 | }; | ||
| 476 | |||
| 477 | openai_models.forEach((model) => { | ||
| 478 | models.data.push({ | ||
| 479 | id: model.value, | ||
| 480 | label: model.label, | ||
| 481 | name: model.label, | ||
| 482 | beta: false, | ||
| 483 | }); | ||
| 467 | }) | 484 | }) |
| 468 | 485 | ||
| 469 | opensource_models.forEach((model) => { | 486 | opensource_models.forEach((model) => { |
| 470 | models.data.push({ | 487 | models.data.push({ |
| 471 | id: model.value, | 488 | id: model.value, |
| 472 | label: model.label, | 489 | label: model.label, |
| 490 | name: model.label, | ||
| 473 | beta: true, | 491 | beta: true, |
| 474 | }); | 492 | }); |
| 475 | }) | 493 | }) |
| 476 | 494 | ||
| 477 | |||
| 478 | const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"]; | ||
| 479 | // add name | ||
| 480 | models.data.forEach((model) => { | ||
| 481 | if (model.id.includes('gpt-3')) { | ||
| 482 | const d = new Date(model.created * 1000); | ||
| 483 | let month = months[d.getMonth()]; | ||
| 484 | model.name = 'GPT-3.5 ' + month + ' ' + d.getDate(); | ||
| 485 | } else if (model.id == 'dall-e-2') { | ||
| 486 | model.name = 'DALL-E 2'; | ||
| 487 | } else if (model.id == 'dall-e-3') { | ||
| 488 | model.name = 'DALL-E 3'; | ||
| 489 | } else { | ||
| 490 | model.name = model.label ? model.label: model.id; | ||
| 491 | } | ||
| 492 | }) | ||
| 493 | |||
| 494 | res.json({ | 495 | res.json({ |
| 495 | models | 496 | models |
| 496 | }) | 497 | }) | ... | ... |
-
Please register or sign in to post a comment