2023-11-07 23:17:13 +01:00
|
|
|
import { getRequestHeaders, setGenerationParamsFromPreset } from "../script.js";
|
2023-09-10 13:39:49 +02:00
|
|
|
import { getDeviceInfo } from "./RossAscends-mods.js";
|
2023-11-07 23:17:13 +01:00
|
|
|
import { textgenerationwebui_settings } from "./textgen-settings.js";
|
2023-09-10 03:08:15 +02:00
|
|
|
|
|
|
|
let models = [];
|
|
|
|
|
|
|
|
export async function loadMancerModels() {
|
|
|
|
try {
|
|
|
|
const response = await fetch('/api/mancer/models', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: getRequestHeaders(),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
models = data;
|
|
|
|
|
|
|
|
$('#mancer_model').empty();
|
|
|
|
for (const model of data) {
|
|
|
|
const option = document.createElement('option');
|
|
|
|
option.value = model.id;
|
|
|
|
option.text = model.name;
|
2023-11-07 23:17:13 +01:00
|
|
|
option.selected = model.id === textgenerationwebui_settings.mancer_model;
|
2023-09-10 03:08:15 +02:00
|
|
|
$('#mancer_model').append(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
console.warn('Failed to load Mancer models');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMancerModelSelect() {
|
|
|
|
const modelId = String($('#mancer_model').val());
|
2023-11-07 23:17:13 +01:00
|
|
|
textgenerationwebui_settings.mancer_model = modelId;
|
2023-09-10 03:08:15 +02:00
|
|
|
$('#api_button_textgenerationwebui').trigger('click');
|
|
|
|
|
2023-11-07 23:17:13 +01:00
|
|
|
const limits = models.find(x => x.id === modelId)?.limits;
|
|
|
|
setGenerationParamsFromPreset({ max_length: limits.context, genamt: limits.completion });
|
2023-09-10 03:08:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getMancerModelTemplate(option) {
|
|
|
|
const model = models.find(x => x.id === option?.element?.value);
|
|
|
|
|
|
|
|
if (!option.id || !model) {
|
|
|
|
return option.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $((`
|
|
|
|
<div class="flex-container flexFlowColumn">
|
2023-11-07 23:17:13 +01:00
|
|
|
<div><strong>${DOMPurify.sanitize(model.name)}</strong> | <span>${model.limits?.context} ctx</span></div>
|
2023-09-10 03:08:15 +02:00
|
|
|
</div>
|
|
|
|
`));
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery(function () {
|
2023-09-10 13:39:49 +02:00
|
|
|
$('#mancer_model').on('change', onMancerModelSelect);
|
|
|
|
|
|
|
|
const deviceInfo = getDeviceInfo();
|
|
|
|
if (deviceInfo && deviceInfo.device.type === 'desktop') {
|
|
|
|
$('#mancer_model').select2({
|
|
|
|
placeholder: 'Select a model',
|
|
|
|
searchInputPlaceholder: 'Search models...',
|
|
|
|
searchInputCssClass: 'text_pole',
|
|
|
|
width: '100%',
|
|
|
|
templateResult: getMancerModelTemplate,
|
|
|
|
});
|
|
|
|
}
|
2023-09-10 03:08:15 +02:00
|
|
|
});
|