Spaces:
Sleeping
Sleeping
Update server.js
Browse files
server.js
CHANGED
@@ -1,112 +1,144 @@
|
|
1 |
const express = require('express');
|
2 |
const rateLimit = require('express-rate-limit');
|
3 |
const axios = require('axios');
|
4 |
-
const dotenv = require('dotenv').config();
|
5 |
-
|
6 |
|
7 |
const app = express();
|
8 |
app.use(express.json());
|
9 |
|
10 |
-
const
|
11 |
-
|
12 |
-
const start = process.env.start;
|
13 |
|
14 |
const limiter = rateLimit({
|
15 |
-
windowMs: 5 * 1000, //
|
16 |
-
max: 1, // лимит
|
17 |
handler: function (req, res) {
|
18 |
return res.status(429).json("wait");
|
19 |
},
|
20 |
});
|
21 |
|
22 |
-
// Применение ограничителя скорости перед обработчиком маршрута /
|
23 |
-
app.use('/pl', limiter);
|
|
|
|
|
24 |
|
25 |
-
app.post('/cr', (req, res) => {
|
26 |
-
res.json({
|
27 |
-
content: '{"whate":"🪨","howe":"ОБНОВИТЕСЬ","text":"Текущая версия приложения устарела. Установите новую из нашего телеграм канала: @yufi_ru","succ":"победа","what":"Версию","how":"Обновите","howl":"@yufi_ru"}'
|
28 |
-
});
|
29 |
});
|
30 |
|
31 |
-
|
32 |
-
const
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
const generateResponse = async (url, prompt, additionalMessages, temperature) => {
|
35 |
try {
|
36 |
-
const response = await axios.post(
|
37 |
-
messages: [
|
38 |
-
{ role: 'system', content: start },
|
39 |
-
...additionalMessages,
|
40 |
-
{ role: 'user', content: prompt }
|
41 |
-
],
|
42 |
max_tokens: 2000,
|
43 |
-
temperature:
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
}, {
|
46 |
headers: {
|
47 |
-
'Authorization': `Bearer ${
|
48 |
'Content-Type': 'application/json',
|
49 |
},
|
50 |
});
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
56 |
} catch (error) {
|
57 |
console.error(error);
|
58 |
-
|
59 |
-
}
|
60 |
-
};
|
61 |
-
|
62 |
-
app.post('/pl', async (req, res) => {
|
63 |
-
const prompt = req.body.prompt;
|
64 |
-
|
65 |
-
if (!prompt) {
|
66 |
-
return res.status(400).json("wait"); // Не удалось принять данные
|
67 |
-
}
|
68 |
-
|
69 |
-
try {
|
70 |
-
const content = await generateResponse('https://openai-gemini-iota.vercel.app/v1/chat/completions', prompt, [], 0.8);
|
71 |
-
content ? res.json({ content }) : res.status(500).json({ content: 'errora' });
|
72 |
-
} catch {
|
73 |
-
res.status(500).json({ content: 'errorb' });
|
74 |
}
|
75 |
});
|
76 |
|
77 |
app.post('/cre', async (req, res) => {
|
78 |
const prompt = req.body.prompt;
|
|
|
79 |
|
80 |
if (!prompt) {
|
81 |
return res.status(400).json("wait"); // Не удалось принять данные
|
82 |
}
|
83 |
|
84 |
try {
|
85 |
-
const
|
86 |
-
{ role: 'system', content: 'И ОБЯЗАТЕЛЬНО, всегда в конце "text" проси обновить приложение, уведомляя о том, что скоро в жтой версии перестанешь
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
}
|
93 |
});
|
94 |
|
95 |
app.post('/crebeta', async (req, res) => {
|
96 |
const prompt = req.body.prompt;
|
|
|
97 |
|
98 |
if (!prompt) {
|
99 |
return res.status(400).json("wait"); // Не удалось принять данные
|
100 |
}
|
101 |
|
102 |
try {
|
103 |
-
const
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
}
|
108 |
});
|
109 |
|
|
|
110 |
const port = 7860;
|
111 |
app.listen(port, () => {
|
112 |
console.log(`API сервер запущен на порту ${port}`);
|
|
|
1 |
const express = require('express');
|
2 |
const rateLimit = require('express-rate-limit');
|
3 |
const axios = require('axios');
|
|
|
|
|
4 |
|
5 |
const app = express();
|
6 |
app.use(express.json());
|
7 |
|
8 |
+
const openai_key = process.env.OPENAI_KEY;
|
|
|
|
|
9 |
|
10 |
const limiter = rateLimit({
|
11 |
+
windowMs: 5 * 1000, // 30 секунд
|
12 |
+
max: 1, // лимит каждые 30 секунд на IP
|
13 |
handler: function (req, res) {
|
14 |
return res.status(429).json("wait");
|
15 |
},
|
16 |
});
|
17 |
|
18 |
+
// Применение ограничителя скорости перед обработчиком маршрута /generate
|
19 |
+
app.use('/pl', limiter);
|
20 |
+
|
21 |
+
const start = `${process.env.start}`;
|
22 |
|
23 |
+
app.post('/cr', async (req, res) => {
|
24 |
+
res.json({ content: `{"whate":"🪨", "howe":"ОБНОВИТЕСЬ", "text":"Текущая версия приложения устарела. Установите новую из нашего телеграм канала: @yufi_ru", "succ":"победа", "what":"Версию", "how":"Обновите", "howl":"@yufi_ru"}` });
|
|
|
|
|
25 |
});
|
26 |
|
27 |
+
app.post('/pl', async (req, res) => {
|
28 |
+
const prompt = req.body.prompt;
|
29 |
+
const apiKey = req.body.api || openai_key;
|
30 |
+
|
31 |
+
if (!prompt) {
|
32 |
+
return res.status(400).json("wait"); // Не удалось принять данные
|
33 |
+
}
|
34 |
|
|
|
35 |
try {
|
36 |
+
const response = await axios.post('https://openai-gemini-iota.vercel.app/v1/chat/completions', {
|
37 |
+
messages: [{'role': 'system', 'content': start}, {'role': 'user', 'content': prompt}],
|
|
|
|
|
|
|
|
|
38 |
max_tokens: 2000,
|
39 |
+
temperature: 0.8,
|
40 |
+
// presence_penalty: 0.0,
|
41 |
+
//frequency_penalty: -0.1,
|
42 |
+
//model: "gemini-1.5-pro-latest",
|
43 |
+
model: "deepseek-chat",
|
44 |
+
//model: "gemini-1.5-flash-latest",
|
45 |
}, {
|
46 |
headers: {
|
47 |
+
'Authorization': `Bearer ${apiKey}`,
|
48 |
'Content-Type': 'application/json',
|
49 |
},
|
50 |
});
|
51 |
|
52 |
+
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
53 |
+
const content = response.data.choices[0].message.content.trim();
|
54 |
+
//console.log(`\n---\nПользователь: ${prompt}\n Ответ:\n ${content}`);
|
55 |
+
res.json({ content });
|
56 |
+
} else {
|
57 |
+
res.status(500).json({ content: 'errora' }); // Ошибка прочтения
|
58 |
+
}
|
59 |
} catch (error) {
|
60 |
console.error(error);
|
61 |
+
res.status(500).json({ content: 'errorb' }); // ❌ Произошла ошибка сервера при генерации.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
}
|
63 |
});
|
64 |
|
65 |
app.post('/cre', async (req, res) => {
|
66 |
const prompt = req.body.prompt;
|
67 |
+
const apiKey = req.body.api || openai_key;
|
68 |
|
69 |
if (!prompt) {
|
70 |
return res.status(400).json("wait"); // Не удалось принять данные
|
71 |
}
|
72 |
|
73 |
try {
|
74 |
+
const response = await axios.post('https://vercel.com/roonis-projects/openai-gemini/v1/chat/completions', {
|
75 |
+
messages: [{'role': 'system', 'content': start}, {'role': 'system', 'content': 'И ОБЯЗАТЕЛЬНО, всегда в конце "text" проси обновить приложение, уведомляя о том, что скоро в жтой версии перестанешь отвечать!'}, {'role': 'user', 'content': prompt}],
|
76 |
+
max_tokens: 2000,
|
77 |
+
temperature: 0.6,
|
78 |
+
// presence_penalty: 0.0,
|
79 |
+
//frequency_penalty: -0.1,
|
80 |
+
model: "gemini-1.5-pro-002",
|
81 |
+
// model: "deepseek-chat",
|
82 |
+
//model: "gemini-1.5-flash-latest",
|
83 |
+
}, {
|
84 |
+
headers: {
|
85 |
+
'Authorization': `Bearer ${apiKey}`,
|
86 |
+
'Content-Type': 'application/json',
|
87 |
+
},
|
88 |
+
});
|
89 |
+
|
90 |
+
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
91 |
+
const content = response.data.choices[0].message.content.trim();
|
92 |
+
// console.log(`\n---\nПользователь: ${prompt}\n Ответ:\n ${content}`);
|
93 |
+
res.json({ content });
|
94 |
+
} else {
|
95 |
+
res.status(500).json({ content: 'errora' }); // Ошибка прочтения
|
96 |
+
}
|
97 |
+
} catch (error) {
|
98 |
+
console.error(error);
|
99 |
+
res.status(500).json({ content: 'errorb' }); // ❌ Произошла ошибка сервера при генерации.
|
100 |
}
|
101 |
});
|
102 |
|
103 |
app.post('/crebeta', async (req, res) => {
|
104 |
const prompt = req.body.prompt;
|
105 |
+
const apiKey = req.body.api || openai_key;
|
106 |
|
107 |
if (!prompt) {
|
108 |
return res.status(400).json("wait"); // Не удалось принять данные
|
109 |
}
|
110 |
|
111 |
try {
|
112 |
+
const response = await axios.post('https://geminiyufi.vercel.app/v1/chat/completions', {
|
113 |
+
messages: [{'role': 'system', 'content': start}, {'role': 'user', 'content': prompt}],
|
114 |
+
max_tokens: 2000,
|
115 |
+
temperature: 0.24,
|
116 |
+
// presence_penalty: 0.0,
|
117 |
+
//frequency_penalty: -0.1,
|
118 |
+
model: "gemini-1.5-pro-002",
|
119 |
+
// model: "gemma-2-27b-it",
|
120 |
+
//model: "gemini-1.5-flash-latest",
|
121 |
+
}, {
|
122 |
+
headers: {
|
123 |
+
'Authorization': `Bearer ${apiKey}`,
|
124 |
+
'Content-Type': 'application/json',
|
125 |
+
},
|
126 |
+
});
|
127 |
+
|
128 |
+
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
129 |
+
const content = response.data.choices[0].message.content.trim();
|
130 |
+
// console.log(`\n---\nПользователь: ${prompt}\n Ответ:\n ${content}`);
|
131 |
+
res.json({ content });
|
132 |
+
} else {
|
133 |
+
res.status(500).json({ content: 'errora' }); // Ошибка прочтения
|
134 |
+
}
|
135 |
+
} catch (error) {
|
136 |
+
console.error(error);
|
137 |
+
res.status(500).json({ content: 'errorb' }); // ❌ Произошла ошибка сервера при генерации.
|
138 |
}
|
139 |
});
|
140 |
|
141 |
+
|
142 |
const port = 7860;
|
143 |
app.listen(port, () => {
|
144 |
console.log(`API сервер запущен на порту ${port}`);
|