mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge remote-tracking branch 'origin/softprompt'
This commit is contained in:
73
server.js
73
server.js
@@ -362,6 +362,79 @@ app.post("/getstatus", jsonParser, function(request, response_getstatus = respon
|
||||
response_getstatus.send({result: "no_connection"});
|
||||
});
|
||||
});
|
||||
|
||||
const formatApiUrl = (url) => (url.indexOf('localhost') !== -1)
|
||||
? url.replace('localhost', '127.0.0.1')
|
||||
: url;
|
||||
|
||||
// TODO Rewrite using async wrapper from worldinfo branch
|
||||
app.post('/getsoftprompts', jsonParser, async function (request, response) {
|
||||
if (!request.body || !request.body.api_server) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const baseUrl = formatApiUrl(request.body.api_server);
|
||||
let soft_prompts = [];
|
||||
|
||||
try {
|
||||
var args = { headers: { "Content-Type": "application/json" } };
|
||||
const softPromptsList = await new Promise((resolve, reject) => {
|
||||
client.get(`${baseUrl}/v1/config/soft_prompts_list`, args, function (data, response) {
|
||||
if (response.statusCode == 200) {
|
||||
const nameList = data.values.map(x => x.value);
|
||||
resolve(nameList);
|
||||
}
|
||||
else {
|
||||
reject(response.status);
|
||||
}
|
||||
}).on('error', function (err) {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
const softPromptSelected = await new Promise((resolve, reject) => {
|
||||
client.get(`${baseUrl}/v1/config/soft_prompt`, args, function (data, response) {
|
||||
if (response.statusCode == 200) {
|
||||
resolve(data.value);
|
||||
}
|
||||
else {
|
||||
reject(response.status);
|
||||
}
|
||||
}).on('error', function (err) {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
soft_prompts = softPromptsList.map(x => ({ name: x, selected: x === softPromptSelected }));
|
||||
} catch (err) {
|
||||
soft_prompts = [];
|
||||
}
|
||||
|
||||
return response.send({ soft_prompts });
|
||||
});
|
||||
|
||||
// TODO Rewrite using async wrapper from worldinfo branch
|
||||
app.post("/setsoftprompt", jsonParser, async function(request, response) {
|
||||
if (!request.body || !request.body.api_server) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const baseUrl = formatApiUrl(request.body.api_server);
|
||||
const args = {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
data: { value: request.body.name ?? '' },
|
||||
};
|
||||
client.put(`${baseUrl}/v1/config/soft_prompt`, args, function (_, res) {
|
||||
if (res.statusCode == 200) {
|
||||
return response.sendStatus(200);
|
||||
} else {
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
}).on('error', () => {
|
||||
return response.sendStatus(500);
|
||||
});
|
||||
});
|
||||
|
||||
function checkServer(){
|
||||
//console.log('Check run###################################################');
|
||||
api_server = 'http://127.0.0.1:5000';
|
||||
|
Reference in New Issue
Block a user