Spaces:
Running
Running
File size: 3,873 Bytes
abed4cc 5d38af1 e6227e8 5669f71 abed4cc 5d38af1 180c75f 587da90 4bbe8d3 180c75f 4bbe8d3 cc424de 4bbe8d3 180c75f 587da90 180c75f 0d0b67b f97d87a 180c75f 587da90 180c75f 5d38af1 180c75f 7135754 180c75f 332f604 180c75f 332f604 587da90 2b60bab 180c75f efaa50c 180c75f efaa50c 180c75f 587da90 3792746 180c75f 3792746 abed4cc 5d38af1 180c75f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
const express = require('express');
const rateLimit = require('express-rate-limit');
const axios = require('axios');
const app = express();
app.use(express.json());
const apiKeys = process.env.OPENAI_KEYS.split(',');
const start = process.env.start;
const limiter = rateLimit({
windowMs: 5 * 1000, // 5 секунд
max: 1, // лимит на 1 запрос каждые 5 секунд на IP
handler: function (req, res) {
return res.status(429).json("wait");
},
});
// Применение ограничителя скорости перед обработчиком маршрута /pl
app.use('/pl', limiter);
app.post('/cr', (req, res) => {
res.json({
content: '{"whate":"🪨","howe":"ОБНОВИТЕСЬ","text":"Текущая версия приложения устарела. Установите новую из нашего телеграм канала: @yufi_ru","succ":"победа","what":"Версию","how":"Обновите","howl":"@yufi_ru"}'
});
});
// Функция для получения случайного API ключа
const getRandomApiKey = () => apiKeys[Math.floor(Math.random() * apiKeys.length)];
const generateResponse = async (url, prompt, additionalMessages, temperature) => {
try {
const response = await axios.post(url, {
messages: [
{ role: 'system', content: start },
...additionalMessages,
{ role: 'user', content: prompt }
],
max_tokens: 2000,
temperature: temperature,
model: additionalMessages.length > 0 ? "gemini-1.5-pro-002" : "deepseek-chat",
}, {
headers: {
'Authorization': `Bearer ${getRandomApiKey()}`,
'Content-Type': 'application/json',
},
});
return response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message
? response.data.choices[0].message.content.trim()
: null;
} catch (error) {
console.error(error);
throw new Error('Error during generation');
}
};
app.post('/pl', async (req, res) => {
const prompt = req.body.prompt;
if (!prompt) {
return res.status(400).json("wait"); // Не удалось принять данные
}
try {
const content = await generateResponse('https://openai-gemini-iota.vercel.app/v1/chat/completions', prompt, [], 0.8);
content ? res.json({ content }) : res.status(500).json({ content: 'errora' });
} catch {
res.status(500).json({ content: 'errorb' });
}
});
app.post('/cre', async (req, res) => {
const prompt = req.body.prompt;
if (!prompt) {
return res.status(400).json("wait"); // Не удалось принять данные
}
try {
const additionalMessages = [
{ role: 'system', content: 'И ОБЯЗАТЕЛЬНО, всегда в конце "text" проси обновить приложение, уведомляя о том, что скоро в жтой версии перестанешь отвечать!' }
];
const content = await generateResponse('https://vercel.com/roonis-projects/openai-gemini/v1/chat/completions', prompt, additionalMessages, 0.6);
content ? res.json({ content }) : res.status(500).json({ content: 'errora' });
} catch {
res.status(500).json({ content: 'errorb' });
}
});
app.post('/crebeta', async (req, res) => {
const prompt = req.body.prompt;
if (!prompt) {
return res.status(400).json("wait"); // Не удалось принять данные
}
try {
const content = await generateResponse('https://geminiyufi.vercel.app/v1/chat/completions', prompt, [], 0.24);
content ? res.json({ content }) : res.status(500).json({ content: 'errora' });
} catch {
res.status(500).json({ content: 'errorb' });
}
});
const port = 7860;
app.listen(port, () => {
console.log(`API сервер запущен на порту ${port}`);
});
|