Spaces:
Running
Running
Update server.js
Browse files
server.js
CHANGED
@@ -38,10 +38,12 @@ app.post('/pl', async (req, res) => {
|
|
38 |
const prompt = req.body.prompt;
|
39 |
const apiKey = req.body.api || getRandomApiKey();
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
45 |
}
|
46 |
|
47 |
if (!prompt) {
|
@@ -63,16 +65,13 @@ app.post('/pl', async (req, res) => {
|
|
63 |
|
64 |
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
65 |
const content = response.data.choices[0].message.content.trim();
|
66 |
-
// console.log(`\n---\nПользователь: ${prompt}\n Ответ:\n ${content}`);
|
67 |
res.json({ content });
|
68 |
} else {
|
69 |
-
|
70 |
-
res.json({ content: `{"error":"", "title":"Ошибка", "text":"Произошла ошибка на сервере. (Ошибка прочтения)", "okb":"Ок", "oklink":"", "cancelable":"true"` })
|
71 |
}
|
72 |
} catch (error) {
|
73 |
console.error(error);
|
74 |
-
|
75 |
-
res.json({ content: `{"error":"", "title":"Ошибка", "text":"Произошла ошибка на сервере. (Ошибка при генерации)", "okb":"Ок", "oklink":"", "cancelable":"true"` })
|
76 |
}
|
77 |
});
|
78 |
|
@@ -80,10 +79,12 @@ app.post('/plbeta', async (req, res) => {
|
|
80 |
const prompt = req.body.prompt;
|
81 |
const apiKey = req.body.api || getRandomApiKey();
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
87 |
}
|
88 |
|
89 |
if (!prompt) {
|
@@ -105,19 +106,18 @@ app.post('/plbeta', async (req, res) => {
|
|
105 |
|
106 |
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
107 |
const content = response.data.choices[0].message.content.trim();
|
108 |
-
|
109 |
res.json({ content });
|
110 |
} else {
|
111 |
-
|
112 |
-
res.json({ content: `{"error":"", "title":"Ошибка", "text":"Произошла ошибка на сервере. (Ошибка прочтения)", "okb":"Ок", "oklink":"", "cancelable":"true"` })
|
113 |
}
|
114 |
} catch (error) {
|
115 |
console.error(error);
|
116 |
-
|
117 |
-
res.json({ content: `{"error":"", "title":"Ошибка", "text":"Произошла ошибка на сервере. (Ошибка при генерации)", "okb":"Ок", "oklink":"", "cancelable":"true"` })
|
118 |
}
|
119 |
});
|
120 |
|
|
|
121 |
const port = 7860;
|
122 |
app.listen(port, () => {
|
123 |
console.log(`API сервер запущен на порту ${port}`);
|
|
|
38 |
const prompt = req.body.prompt;
|
39 |
const apiKey = req.body.api || getRandomApiKey();
|
40 |
|
41 |
+
let prs; // Объявление переменной prs перед использованием
|
42 |
+
|
43 |
+
if (req.body.mode === "1") {
|
44 |
+
prs = start;
|
45 |
+
} else {
|
46 |
+
prs = startconnect;
|
47 |
}
|
48 |
|
49 |
if (!prompt) {
|
|
|
65 |
|
66 |
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
67 |
const content = response.data.choices[0].message.content.trim();
|
|
|
68 |
res.json({ content });
|
69 |
} else {
|
70 |
+
res.json({ content: `{"error":"", "title":"Ошибка", "text":"Произошла ошибка на сервере. (Ошибка прочтения)", "okb":"Ок", "oklink":"", "cancelable":"true"` });
|
|
|
71 |
}
|
72 |
} catch (error) {
|
73 |
console.error(error);
|
74 |
+
res.json({ content: `{"error":"", "title":"Ошибка", "text":"Произошла ошибка на сервере. (Ошибка при генерации)", "okb":"Ок", "oklink":"", "cancelable":"true"` });
|
|
|
75 |
}
|
76 |
});
|
77 |
|
|
|
79 |
const prompt = req.body.prompt;
|
80 |
const apiKey = req.body.api || getRandomApiKey();
|
81 |
|
82 |
+
let prs; // Объявление переменной prs перед использованием
|
83 |
+
|
84 |
+
if (req.body.mode === "1") {
|
85 |
+
prs = start;
|
86 |
+
} else {
|
87 |
+
prs = startconnect;
|
88 |
}
|
89 |
|
90 |
if (!prompt) {
|
|
|
106 |
|
107 |
if (response.data.choices && response.data.choices.length > 0 && response.data.choices[0].message) {
|
108 |
const content = response.data.choices[0].message.content.trim();
|
109 |
+
console.log(`\n---\nПользователь: ${prompt}\n Ответ:\n ${content}`);
|
110 |
res.json({ content });
|
111 |
} else {
|
112 |
+
res.json({ content: `{"error":"", "title":"Ошибка", "text":"Произошла ошибка на сервере. (Ошибка прочтения)", "okb":"Ок", "oklink":"", "cancelable":"true"` });
|
|
|
113 |
}
|
114 |
} catch (error) {
|
115 |
console.error(error);
|
116 |
+
res.json({ content: `{"error":"", "title":"Ошибка", "text":"Произошла ошибка на сервере. (Ошибка при генерации)", "okb":"Ок", "oklink":"", "cancelable":"true"` });
|
|
|
117 |
}
|
118 |
});
|
119 |
|
120 |
+
|
121 |
const port = 7860;
|
122 |
app.listen(port, () => {
|
123 |
console.log(`API сервер запущен на порту ${port}`);
|