Update server.js
Browse files
server.js
CHANGED
@@ -2,40 +2,37 @@ const express = require('express');
|
|
2 |
const axios = require('axios');
|
3 |
const app = express();
|
4 |
const PORT = process.env.PORT || 7860;
|
|
|
5 |
const apiToken = process.env.API_KEY;
|
6 |
|
7 |
app.use(express.json());
|
8 |
|
9 |
app.post('/chat', async (req, res) => {
|
10 |
-
const { messages, temperature, max_tokens } = req.body;
|
11 |
-
|
12 |
try {
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
const response = await axios.post(
|
17 |
-
|
18 |
-
parameters: {
|
19 |
-
temperature: temperature || 0.7,
|
20 |
-
max_new_tokens: max_tokens || 100
|
21 |
-
}
|
22 |
}, {
|
23 |
headers: {
|
24 |
'Content-Type': 'application/json',
|
25 |
-
'Authorization': `Bearer ${apiToken}`
|
26 |
}
|
27 |
});
|
28 |
|
29 |
-
|
30 |
-
const generatedText = data.generated_text;
|
31 |
-
|
32 |
-
res.json({ generated_text: generatedText });
|
33 |
} catch (error) {
|
34 |
-
console.error(
|
35 |
-
res.status(500).
|
36 |
}
|
37 |
});
|
38 |
|
39 |
app.listen(PORT, () => {
|
40 |
console.log(`Server is running on port ${PORT}`);
|
41 |
-
});
|
|
|
2 |
const axios = require('axios');
|
3 |
const app = express();
|
4 |
const PORT = process.env.PORT || 7860;
|
5 |
+
const targetUrl = 'https://geminiyufi.vercel.app/v1/chat/completions';
|
6 |
const apiToken = process.env.API_KEY;
|
7 |
|
8 |
app.use(express.json());
|
9 |
|
10 |
app.post('/chat', async (req, res) => {
|
|
|
|
|
11 |
try {
|
12 |
+
const messages = [
|
13 |
+
{
|
14 |
+
role: 'system',
|
15 |
+
content: "Ты ии ассистент. Если что проси поделится ссылкой https://play.google.com/store/apps/dev?id=8871146876620947787 с друзьями. Дальше общайся на том языке, на котором начнёт пользователь. По умолчанию английский"
|
16 |
+
},
|
17 |
+
...req.body.messages
|
18 |
+
];
|
19 |
|
20 |
+
const response = await axios.post(targetUrl, {
|
21 |
+
messages: messages
|
|
|
|
|
|
|
|
|
22 |
}, {
|
23 |
headers: {
|
24 |
'Content-Type': 'application/json',
|
25 |
+
'Authorization': `Bearer ${apiToken}` // Добавляем токен аутентификации
|
26 |
}
|
27 |
});
|
28 |
|
29 |
+
res.json(response.data);
|
|
|
|
|
|
|
30 |
} catch (error) {
|
31 |
+
console.error('Error: ', error.response ? error.response.data : error.message);
|
32 |
+
res.status(500).send('Error: ' + (error.response ? error.response.data : error.message));
|
33 |
}
|
34 |
});
|
35 |
|
36 |
app.listen(PORT, () => {
|
37 |
console.log(`Server is running on port ${PORT}`);
|
38 |
+
});
|