Separate getStatus into Kobold/textgen versions
This adds a bit of duplicate code for the time being, but ultimately makes the code less confusing because we only need to include the bits that are relevant to the specific API in each function. We can also remove API parameters that are useless depending on the endpoint.
This commit is contained in:
parent
a8224c16de
commit
0ea0399ed1
|
@ -232,7 +232,6 @@ export {
|
|||
isStreamingEnabled,
|
||||
getThumbnailUrl,
|
||||
getStoppingStrings,
|
||||
getStatus,
|
||||
reloadMarkdownProcessor,
|
||||
getCurrentChatId,
|
||||
chat,
|
||||
|
@ -857,7 +856,7 @@ export async function clearItemizedPrompts() {
|
|||
}
|
||||
}
|
||||
|
||||
async function getStatus() {
|
||||
async function getStatusKobold() {
|
||||
if (main_api == 'koboldhorde') {
|
||||
try {
|
||||
const hordeStatus = await checkHordeStatus();
|
||||
|
@ -870,7 +869,7 @@ async function getStatus() {
|
|||
return resultCheckStatus();
|
||||
}
|
||||
|
||||
const url = main_api == 'textgenerationwebui' ? '/api/textgenerationwebui/status' : '/getstatus';
|
||||
const url = '/getstatus';
|
||||
|
||||
let endpoint = getAPIServerUrl();
|
||||
|
||||
|
@ -886,18 +885,64 @@ async function getStatus() {
|
|||
body: JSON.stringify({
|
||||
main_api,
|
||||
api_server: endpoint,
|
||||
api_type: textgen_settings.type,
|
||||
legacy_api: main_api == 'textgenerationwebui' ?
|
||||
textgen_settings.legacy_api &&
|
||||
textgen_settings.type !== MANCER :
|
||||
false,
|
||||
}),
|
||||
signal: abortStatusCheck.signal,
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (main_api == 'textgenerationwebui' && textgen_settings.type === MANCER) {
|
||||
|
||||
online_status = data?.result;
|
||||
|
||||
if (!online_status) {
|
||||
online_status = 'no_connection';
|
||||
}
|
||||
|
||||
// Determine instruct mode preset
|
||||
autoSelectInstructPreset(online_status);
|
||||
|
||||
// determine if we can use stop sequence and streaming
|
||||
setKoboldFlags(data.version, data.koboldVersion);
|
||||
|
||||
// We didn't get a 200 status code, but the endpoint has an explanation. Which means it DID connect, but I digress.
|
||||
if (online_status === 'no_connection' && data.response) {
|
||||
toastr.error(data.response, 'API Error', { timeOut: 5000, preventDuplicates: true });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error getting status', err);
|
||||
online_status = 'no_connection';
|
||||
}
|
||||
|
||||
return resultCheckStatus();
|
||||
}
|
||||
|
||||
async function getStatusTextgen() {
|
||||
const url = '/api/textgenerationwebui/status';
|
||||
|
||||
let endpoint = getAPIServerUrl();
|
||||
|
||||
if (!endpoint) {
|
||||
console.warn('No endpoint for status check');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({
|
||||
api_server: endpoint,
|
||||
api_type: textgen_settings.type,
|
||||
legacy_api:
|
||||
textgen_settings.legacy_api &&
|
||||
textgen_settings.type !== MANCER,
|
||||
}),
|
||||
signal: abortStatusCheck.signal,
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (textgen_settings.type === MANCER) {
|
||||
online_status = textgen_settings.mancer_model;
|
||||
loadMancerModels(data?.data);
|
||||
} else {
|
||||
|
@ -911,11 +956,6 @@ async function getStatus() {
|
|||
// Determine instruct mode preset
|
||||
autoSelectInstructPreset(online_status);
|
||||
|
||||
// determine if we can use stop sequence and streaming
|
||||
if (main_api === 'kobold' || main_api === 'koboldhorde') {
|
||||
setKoboldFlags(data.version, data.koboldVersion);
|
||||
}
|
||||
|
||||
// We didn't get a 200 status code, but the endpoint has an explanation. Which means it DID connect, but I digress.
|
||||
if (online_status === 'no_connection' && data.response) {
|
||||
toastr.error(data.response, 'API Error', { timeOut: 5000, preventDuplicates: true });
|
||||
|
@ -943,6 +983,7 @@ export function resultCheckStatus() {
|
|||
stopStatusLoading();
|
||||
}
|
||||
|
||||
// TODO(valadaptive): remove the usage of this function in the tokenizers code, then remove the function entirely
|
||||
export function getAPIServerUrl() {
|
||||
if (main_api == 'textgenerationwebui') {
|
||||
if (textgen_settings.type === MANCER) {
|
||||
|
@ -5314,7 +5355,7 @@ function changeMainAPI() {
|
|||
}
|
||||
|
||||
if (main_api == 'koboldhorde') {
|
||||
getStatus();
|
||||
getStatusKobold();
|
||||
getHordeModels();
|
||||
}
|
||||
|
||||
|
@ -8268,7 +8309,7 @@ jQuery(async function () {
|
|||
|
||||
main_api = 'kobold';
|
||||
saveSettingsDebounced();
|
||||
getStatus();
|
||||
getStatusKobold();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -8304,7 +8345,7 @@ jQuery(async function () {
|
|||
startStatusLoading();
|
||||
main_api = 'textgenerationwebui';
|
||||
saveSettingsDebounced();
|
||||
getStatus();
|
||||
getStatusTextgen();
|
||||
});
|
||||
|
||||
var button = $('#options_button');
|
||||
|
|
Loading…
Reference in New Issue