File size: 2,713 Bytes
abed4cc 5d38af1 e6227e8 5669f71 abed4cc 5d38af1 bb1ac05 587da90 4bbe8d3 a745a55 bb1ac05 4bbe8d3 cc424de 4bbe8d3 8f80c16 4bbe8d3 2f02aea 587da90 4bbe8d3 e542f78 c08d7be f97d87a 04ade22 bb1ac05 587da90 04ade22 ce6ac9a 5d38af1 587da90 5d38af1 760f179 bb1ac05 7135754 a31a258 bb1ac05 a31a258 93d7466 bb1ac05 332f604 587da90 2b60bab bb1ac05 332f604 5de0c8e 2b60bab c08d7be 2b60bab 587da90 5d38af1 c08d7be 587da90 abed4cc 5d38af1 abed4cc |
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 |
const express = require('express');
const rateLimit = require('express-rate-limit');
const axios = require('axios');
const app = express();
app.use(express.json());
const openai_key = process.env.OPENAI_KEY;
const limiter = rateLimit({
windowMs: 5 * 1000, // 30 секунд
max: 1, // лимит каждые 30 секунд на IP
handler: function (req, res) {
return res.status(429).json("wait");
},
});
// Применение ограничителя скорости перед обработчиком маршрута /generate
// app.use('/gn', limiter);
const start = `${process.env.start}`;
app.post('/generate', async (req, res) => {
res.status(500).json({ content: '+ошибка+❗ Вы используете устаревшую версию АромаАрт. Установите версию 1.3.1 и более.-ошибка-' });
});
app.post('/cr', async (req, res) => {
res.json({ content: `{"whate":"🪨", "howe":"ОБНОВИТЕСЬ", "text":"Текущая версия приложения устарела. Установите новую из нашего телеграм канала: @yufi_ru", "succ":"победа", "what":"Обновите", "how":"Версию", "howl":"@yufi_ru"}` });
}
app.post('/cre', async (req, res) => {
const prompt = req.body.prompt;
const apiKey = req.body.api || openai_key;
if (!prompt) {
return res.status(400).json("wait"); // Не удалось принять данные
}
try {
const response = await axios.post('https://geminiyufi.vercel.app/v1/chat/completions', {
messages: [{'role': 'system', 'content': start}, {'role': 'user', 'content': prompt}],
max_tokens: 2000,
temperature: 0.25,
// presence_penalty: 0.0,
frequency_penalty: -0.1,
model: "gemma-2-27b-it",
//model: "gemini-1.5-flash-latest",
}, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
});
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
const content = response.data.choices[0].message.content.trim();
console.log(`\n---\nПользователь: ${prompt}\n Ответ:\n ${content}`);
res.json({ content });
} else {
res.status(500).json({ content: 'errora' }); // Ошибка прочтения
}
} catch (error) {
console.error(error);
res.status(500).json({ content: 'errorb' }); // ❌ Произошла ошибка сервера при генерации.
}
});
const port = 7860;
app.listen(port, () => {
console.log(`API сервер запущен на порту ${port}`);
}); |