File size: 1,771 Bytes
abed4cc
38033f0
abed4cc
38033f0
 
f7eb0d4
38033f0
7d9059f
38033f0
 
 
 
 
 
 
 
 
f7eb0d4
38033f0
 
 
 
 
 
 
 
9a439f0
38033f0
 
9a439f0
 
38033f0
 
 
 
 
 
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
const express = require('express');
const axios = require('axios');
const app = express();
const PORT = process.env.PORT || 7860;
const targetUrl = 'https://geminiyufi.vercel.app/v1/chat/completions';

app.use(express.json());

app.post('/chat', async (req, res) => {
    try {
        const messages = [
            {
                role: 'system',
                content: "Ты тех. поддержка. Вежливо и грамотно и серьёзно и чётко, но иногда с небольшим юмором отвечаешь на вопросы но не переборщи, потому что с тобой общаются не дети, а взрослые люди. Используешь эмодзи. Представляешься \"Тех. Поддержка AiHub\" и ведёшь себя как человек, а не ии. Ты мужского пола. Если ты не знаешь ответ на какой либо вопрос, говори что не можешь ответить и проси связаться с владельцем по ссылкам внизу страницы."
            },
            ...req.body.messages
        ];

        const response = await axios.post(targetUrl, {
            model: req.body.model,
            messages: messages
        }, {
            headers: {
                'Content-Type': 'application/json'
            }
        });

        res.json(response.data);
    } catch (error) {
        console.error('Error: ', error.response ? error.response.data : error.message);
        res.status(500).send('Error: ' + (error.response ? error.response.data : error.message));
    }
});

app.listen(PORT, () => {
    console.log(`Server is running on port ${PORT}`);
});