Clarify getstatus API

Instead of "version" and "koboldVersion", have "koboldUnitedVersion" and
"koboldCppVersion", the latter of which is null if we're not connected
to KoboldCpp.
This commit is contained in:
valadaptive 2023-12-10 20:34:11 -05:00
parent 1fbf4394c8
commit d33cb0d8d1
3 changed files with 56 additions and 66 deletions

View File

@ -901,17 +901,17 @@ async function getStatusKobold() {
const data = await response.json();
online_status = data?.result;
online_status = data?.model ?? 'no_connection';
if (!online_status) {
online_status = 'no_connection';
if (!data.koboldUnitedVersion) {
throw new Error('Missing mandatory Kobold version in data:', data);
}
// Determine instruct mode preset
autoSelectInstructPreset(online_status);
// determine if we can use stop sequence and streaming
setKoboldFlags(data.version, data.koboldVersion);
setKoboldFlags(data.koboldUnitedVersion, data.koboldCppVersion);
// 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) {

View File

@ -317,14 +317,14 @@ const sliders = [
},
];
export function setKoboldFlags(version, koboldVersion) {
kai_flags.can_use_stop_sequence = canUseKoboldStopSequence(version);
kai_flags.can_use_streaming = canUseKoboldStreaming(koboldVersion);
kai_flags.can_use_tokenization = canUseKoboldTokenization(koboldVersion);
kai_flags.can_use_default_badwordsids = canUseDefaultBadwordIds(version);
kai_flags.can_use_mirostat = canUseMirostat(koboldVersion);
kai_flags.can_use_grammar = canUseGrammar(koboldVersion);
kai_flags.can_use_min_p = canUseMinP(koboldVersion);
export function setKoboldFlags(koboldUnitedVersion, koboldCppVersion) {
kai_flags.can_use_stop_sequence = canUseKoboldStopSequence(koboldUnitedVersion);
kai_flags.can_use_streaming = canUseKoboldStreaming(koboldCppVersion);
kai_flags.can_use_tokenization = canUseKoboldTokenization(koboldCppVersion);
kai_flags.can_use_default_badwordsids = canUseDefaultBadwordIds(koboldUnitedVersion);
kai_flags.can_use_mirostat = canUseMirostat(koboldCppVersion);
kai_flags.can_use_grammar = canUseGrammar(koboldCppVersion);
kai_flags.can_use_min_p = canUseMinP(koboldCppVersion);
}
/**
@ -333,7 +333,7 @@ export function setKoboldFlags(version, koboldVersion) {
* @returns {boolean} True if the Kobold stop sequence can be used, false otherwise.
*/
function canUseKoboldStopSequence(version) {
return (version || '0.0.0').localeCompare(MIN_STOP_SEQUENCE_VERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
return version.localeCompare(MIN_STOP_SEQUENCE_VERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
}
/**
@ -342,62 +342,57 @@ function canUseKoboldStopSequence(version) {
* @returns {boolean} True if the Kobold default badword ids can be used, false otherwise.
*/
function canUseDefaultBadwordIds(version) {
return (version || '0.0.0').localeCompare(MIN_UNBAN_VERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
return version.localeCompare(MIN_UNBAN_VERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
}
/**
* Determines if the Kobold streaming API can be used with the given version.
* @param {{ result: string; version: string; }} koboldVersion KoboldAI version object.
* @param {string|null} koboldCppVersion KoboldAI version object.
* @returns {boolean} True if the Kobold streaming API can be used, false otherwise.
*/
function canUseKoboldStreaming(koboldVersion) {
if (koboldVersion && koboldVersion.result == 'KoboldCpp') {
return (koboldVersion.version || '0.0').localeCompare(MIN_STREAMING_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
} else return false;
function canUseKoboldStreaming(koboldCppVersion) {
if (koboldCppVersion === null) return false;
return koboldCppVersion.localeCompare(MIN_STREAMING_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
}
/**
* Determines if the Kobold tokenization API can be used with the given version.
* @param {{ result: string; version: string; }} koboldVersion KoboldAI version object.
* @param {string|null} koboldCppVersion KoboldAI version object.
* @returns {boolean} True if the Kobold tokenization API can be used, false otherwise.
*/
function canUseKoboldTokenization(koboldVersion) {
if (koboldVersion && koboldVersion.result == 'KoboldCpp') {
return (koboldVersion.version || '0.0').localeCompare(MIN_TOKENIZATION_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
} else return false;
function canUseKoboldTokenization(koboldCppVersion) {
if (koboldCppVersion === null) return false;
return koboldCppVersion.localeCompare(MIN_TOKENIZATION_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
}
/**
* Determines if the Kobold mirostat can be used with the given version.
* @param {{result: string; version: string;}} koboldVersion KoboldAI version object.
* @param {string|null} koboldCppVersion KoboldAI version object.
* @returns {boolean} True if the Kobold mirostat API can be used, false otherwise.
*/
function canUseMirostat(koboldVersion) {
if (koboldVersion && koboldVersion.result == 'KoboldCpp') {
return (koboldVersion.version || '0.0').localeCompare(MIN_MIROSTAT_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
} else return false;
function canUseMirostat(koboldCppVersion) {
if (koboldCppVersion === null) return false;
return koboldCppVersion.localeCompare(MIN_MIROSTAT_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
}
/**
* Determines if the Kobold grammar can be used with the given version.
* @param {{result: string; version:string;}} koboldVersion KoboldAI version object.
* @param {string|null} koboldCppVersion KoboldAI version object.
* @returns {boolean} True if the Kobold grammar can be used, false otherwise.
*/
function canUseGrammar(koboldVersion) {
if (koboldVersion && koboldVersion.result == 'KoboldCpp') {
return (koboldVersion.version || '0.0').localeCompare(MIN_GRAMMAR_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
} else return false;
function canUseGrammar(koboldCppVersion) {
if (koboldCppVersion === null) return false;
return koboldCppVersion.localeCompare(MIN_GRAMMAR_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
}
/**
* Determines if the Kobold min_p can be used with the given version.
* @param {{result:string, version:string;}} koboldVersion KoboldAI version object.
* @param {string|null} koboldCppVersion KoboldAI version object.
* @returns {boolean} True if the Kobold min_p can be used, false otherwise.
*/
function canUseMinP(koboldVersion) {
if (koboldVersion && koboldVersion.result == 'KoboldCpp') {
return (koboldVersion.version || '0.0').localeCompare(MIN_MIN_P_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
} else return false;
function canUseMinP(koboldCppVersion) {
if (koboldCppVersion === null) return false;
return koboldCppVersion.localeCompare(MIN_MIN_P_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
}
/**

View File

@ -657,41 +657,36 @@ app.post('/getstatus', jsonParser, async function (request, response) {
setAdditionalHeaders(request, args, api_server);
const url = api_server + '/v1/model';
let version = '';
let koboldVersion = {};
const result = {};
try {
version = (await fetchJSON(api_server + '/v1/info/version')).result;
const [koboldUnitedResponse, koboldExtraResponse] = await Promise.allSettled([
fetchJSON(api_server + '/v1/info/version'),
fetchJSON(api_server + '/extra/version'),
]);
if (koboldUnitedResponse.status === 'fulfilled') {
// Version number string
result.koboldUnitedVersion = koboldUnitedResponse.value.result;
} else {
result.koboldUnitedVersion = '0.0.0';
}
catch {
version = '0.0.0';
}
try {
koboldVersion = (await fetchJSON(api_server + '/extra/version'));
}
catch {
koboldVersion = {
result: 'Kobold',
version: '0.0',
};
if (koboldExtraResponse.status === 'fulfilled') {
result.koboldCppVersion = koboldExtraResponse.value.version;
} else {
result.koboldCppVersion = null;
}
try {
let data = await fetchJSON(url, args);
let data = await fetchJSON(api_server + '/v1/model', args);
if (!data || typeof data !== 'object') {
data = {};
if (!data || typeof data !== 'object' || data.result === 'ReadOnly') {
result.model = 'no_connection';
} else {
result.model = data.result;
}
if (data.result == 'ReadOnly') {
data.result = 'no_connection';
}
data.version = version;
data.koboldVersion = koboldVersion;
return response.send(data);
return response.send(result);
} catch (error) {
console.log(error);
return response.send({ result: 'no_connection' });