0fe0aa08 by Marwin Cañeta

Merge branch 'master' into 31531_apply_tokenization_on_other_llms

# Conflicts:
#	index.js
2 parents d150f036 7a230c24
......@@ -105,7 +105,7 @@ function App() {
}
if(currentModel === "openchat_3.5" || currentModel === "zephyr-7B-beta"
|| currentModel === "meta-llama/Llama-3-8b-chat-hf" || currentModel === "google/gemma-7b-it") {
|| currentModel === "meta-llama/Llama-3-8b-chat-hf" || currentModel === "google/gemma-2-9b-it") {
// "gpt-3.5-turbo"
let chatLogOpenSourceNew = [...chatLogOpenSource, { role: "user", content: chatInput }];
setChatLogOpenSource(chatLogOpenSourceNew);
......
......@@ -93,7 +93,7 @@ app.post('/api', async (req, res) => {
}
if (currentModel == "openchat_3.5" || currentModel == "zephyr-7B-beta"
|| currentModel == "google/gemma-7b-it" || currentModel == "meta-llama/Llama-3-8b-chat-hf"
|| currentModel == "google/gemma-2-9b-it" || currentModel == "meta-llama/Llama-3-8b-chat-hf"
) {
runOpensource(req, res);
......@@ -195,7 +195,7 @@ async function runGPTTurbo(req, res) {
const moderation = await axios.post("https://api.openai.com/v1/moderations", {
input: query_prompt
}, { headers: { 'content-type': 'application/json', 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` } });
const validate = await validation(aiwp_app_id, req, res);
if(!validate) return;
const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate;
......@@ -276,7 +276,7 @@ async function runOpensource(req, res) {
var input = '';
const message_history = JSON.parse(message);
const query_prompt = message_history.length ? message_history[message_history.length - 1].content : "";
const validate = await validation(aiwp_app_id, req, res);
if(!validate) return;
const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate;
......@@ -289,14 +289,23 @@ async function runOpensource(req, res) {
const response = await axios.post(endpoint_api_url + '/chat/completions', {
model: currentModel,
messages: JSON.parse(message),
temperature
max_tokens: 2048,
temperature,
top_p: 0.7,
top_k: 50,
repetition_penalty: 1
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + api_key
},
}).catch(error => {
error_msg = error.response.statusText ? error.response.statusText : '';
if(error.response?.data?.error?.param === 'max_tokens') {
input = "The output for your prompt is too long for us to process. Please reduce your prompt and try again.";
} else {
error_msg = error.response.statusText ? error.response.statusText : '';
}
console.log("err",error.response.data.error);
});
if (error_msg !== '') {
......@@ -350,7 +359,7 @@ async function authenticate(params) {
body: JSON.stringify(params),
referrer: "https://chatgpt.ai-pro.org"
});
return await data.json();
}
......@@ -405,7 +414,7 @@ async function setChatUsage(params) {
async function validation (aiwp_app_id, req, res) {
const aiwp_logged_in = req.cookies[user_secret_id] ? decodeURIComponent(req.cookies[user_secret_id]) : "";
const limit = req.cookies["WcvYPABR"] ? parseInt(req.cookies["WcvYPABR"].replace(/\D/g, '')) : -1;
const limit = req.cookies["WcvYPABR"] ? parseInt(req.cookies["WcvYPABR"].replace(/\D/g, '')) : 3;
let IS_FREE_USER = false;
let TRIED_USAGE = 0;
......@@ -442,7 +451,7 @@ async function validation (aiwp_app_id, req, res) {
if (data.usage !== null) {
TRIED_USAGE = parseInt(data.usage);
}
}
if (IS_FREE_USER && TRIED_USAGE >= limit) {
res.json({ status: "invalid", limited: true });
......@@ -458,39 +467,31 @@ async function validation (aiwp_app_id, req, res) {
// Get Models Route
app.get('/models', async (req, res) => {
const response = await openai.listModels();
const models = response.data;
const openai_models = process.env.OPENAI_MODELS ? JSON.parse(process.env.OPENAI_MODELS) : [{"value": "gpt-3.5-turbo", "label": "GPT-3.5"}];
const opensource_models = process.env.OPENSOURCE_MODELS ? JSON.parse(process.env.OPENSOURCE_MODELS) : [];
models.data = models.data.filter((model) => {
return model.id.indexOf('gpt-3') === 0
const models = {
data: []
};
openai_models.forEach((model) => {
models.data.push({
id: model.value,
label: model.label,
name: model.label,
beta: false,
});
})
opensource_models.forEach((model) => {
models.data.push({
id: model.value,
label: model.label,
name: model.label,
beta: true,
});
})
const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
// add name
models.data.forEach((model) => {
if (model.id.includes('gpt-3')) {
const d = new Date(model.created * 1000);
let month = months[d.getMonth()];
model.name = 'GPT-3.5 ' + month + ' ' + d.getDate();
} else if (model.id == 'dall-e-2') {
model.name = 'DALL-E 2';
} else if (model.id == 'dall-e-3') {
model.name = 'DALL-E 3';
} else {
model.name = model.label ? model.label: model.id;
}
})
res.json({
models
})
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!