Update server.js
Browse files
server.js
CHANGED
@@ -2,34 +2,37 @@ const express = require('express');
|
|
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 |
-
|
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(
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
}, {
|
23 |
headers: {
|
24 |
'Content-Type': 'application/json',
|
25 |
-
'Authorization': `Bearer ${apiToken}`
|
26 |
}
|
27 |
});
|
28 |
|
29 |
-
|
|
|
|
|
|
|
30 |
} catch (error) {
|
31 |
-
console.error(
|
32 |
-
res.status(500).
|
33 |
}
|
34 |
});
|
35 |
|
|
|
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 |
+
const inputText = messages.map(msg => msg.content).join('\n');
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
const response = await axios.post('https://api-inference.huggingface.co/models/codellama/CodeLlama-34b-Instruct-hf', {
|
17 |
+
inputs: inputText,
|
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 |
+
const data = response.data;
|
30 |
+
const generatedText = data.generated_text;
|
31 |
+
|
32 |
+
res.json({ generated_text: generatedText });
|
33 |
} catch (error) {
|
34 |
+
console.error("Error during text generation:", error.response ? error.response.data : error.message);
|
35 |
+
res.status(500).json({ error: `Произошла ошибка при генерации текста: ${error.response ? error.response.data : error.message}` });
|
36 |
}
|
37 |
});
|
38 |
|