mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-05 21:46:49 +01:00
Remove fetchJSON
This commit is contained in:
parent
42d4ffe5e8
commit
ce8cc59e4d
76
server.js
76
server.js
@ -659,38 +659,35 @@ app.post('/getstatus', jsonParser, async function (request, response) {
|
||||
|
||||
const result = {};
|
||||
|
||||
const [koboldUnitedResponse, koboldExtraResponse] = await Promise.allSettled([
|
||||
fetchJSON(api_server + '/v1/info/version'),
|
||||
fetchJSON(api_server + '/extra/version'),
|
||||
const [koboldUnitedResponse, koboldExtraResponse, koboldModelResponse] = await Promise.all([
|
||||
// We catch errors both from the response not having a successful HTTP status and from JSON parsing failing
|
||||
|
||||
// Kobold United API version
|
||||
fetch(`${api_server}/v1/info/version`).then(response => {
|
||||
if (!response.ok) throw new Error(`Kobold API error: ${response.status, response.statusText}`);
|
||||
return response.json();
|
||||
}).catch(() => ({ result: '0.0.0' })),
|
||||
|
||||
// KoboldCpp version
|
||||
fetch(`${api_server}/extra/version`).then(response => {
|
||||
if (!response.ok) throw new Error(`Kobold API error: ${response.status, response.statusText}`);
|
||||
return response.json();
|
||||
}).catch(() => ({ version: '0.0' })),
|
||||
|
||||
// Current model
|
||||
fetch(`${api_server}/v1/model`).then(response => {
|
||||
if (!response.ok) throw new Error(`Kobold API error: ${response.status, response.statusText}`);
|
||||
return response.json();
|
||||
}).catch(() => null),
|
||||
]);
|
||||
|
||||
if (koboldUnitedResponse.status === 'fulfilled') {
|
||||
// Version number string
|
||||
result.koboldUnitedVersion = koboldUnitedResponse.value.result;
|
||||
} else {
|
||||
result.koboldUnitedVersion = '0.0.0';
|
||||
}
|
||||
result.koboldUnitedVersion = koboldUnitedResponse.result;
|
||||
result.koboldCppVersion = koboldExtraResponse.result;
|
||||
result.model = !koboldModelResponse || koboldModelResponse.result === 'ReadOnly' ?
|
||||
'no_connection' :
|
||||
koboldModelResponse.result;
|
||||
|
||||
if (koboldExtraResponse.status === 'fulfilled') {
|
||||
result.koboldCppVersion = koboldExtraResponse.value.version;
|
||||
} else {
|
||||
result.koboldCppVersion = null;
|
||||
}
|
||||
|
||||
try {
|
||||
let data = await fetchJSON(api_server + '/v1/model', args);
|
||||
|
||||
if (!data || typeof data !== 'object' || data.result === 'ReadOnly') {
|
||||
result.model = 'no_connection';
|
||||
} else {
|
||||
result.model = data.result;
|
||||
}
|
||||
|
||||
return response.send(result);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return response.send({ result: 'no_connection' });
|
||||
}
|
||||
response.send(result);
|
||||
});
|
||||
|
||||
|
||||
@ -1746,27 +1743,6 @@ redirect('/delbackground', '/api/backgrounds/delete');
|
||||
redirect('/renamebackground', '/api/backgrounds/rename');
|
||||
redirect('/downloadbackground', '/api/backgrounds/upload'); // yes, the downloadbackground endpoint actually uploads one
|
||||
|
||||
// ** REST CLIENT ASYNC WRAPPERS **
|
||||
|
||||
/**
|
||||
* Convenience function for fetch requests (default GET) returning as JSON.
|
||||
* @param {string} url
|
||||
* @param {import('node-fetch').RequestInit} args
|
||||
*/
|
||||
async function fetchJSON(url, args = {}) {
|
||||
if (args.method === undefined) args.method = 'GET';
|
||||
const response = await fetch(url, args);
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
return data;
|
||||
}
|
||||
|
||||
throw response;
|
||||
}
|
||||
|
||||
// ** END **
|
||||
|
||||
// OpenAI API
|
||||
app.use('/api/openai', require('./src/endpoints/openai').router);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user