SillyTavern/public/scripts/mancer-settings.js

62 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-11-08 01:52:03 +01:00
import { setGenerationParamsFromPreset } from "../script.js";
2023-09-10 13:39:49 +02:00
import { getDeviceInfo } from "./RossAscends-mods.js";
import { textgenerationwebui_settings } from "./textgen-settings.js";
2023-09-10 03:08:15 +02:00
let models = [];
2023-11-08 01:52:03 +01:00
export async function loadMancerModels(data) {
if (!Array.isArray(data)) {
console.error('Invalid Mancer models data', data);
return;
}
2023-09-10 03:08:15 +02:00
2023-11-08 01:52:03 +01:00
models = data;
2023-09-10 03:08:15 +02:00
2023-11-08 01:52:03 +01:00
$('#mancer_model').empty();
for (const model of data) {
const option = document.createElement('option');
option.value = model.id;
option.text = model.name;
option.selected = model.id === textgenerationwebui_settings.mancer_model;
$('#mancer_model').append(option);
2023-09-10 03:08:15 +02:00
}
}
function onMancerModelSelect() {
const modelId = String($('#mancer_model').val());
textgenerationwebui_settings.mancer_model = modelId;
2023-09-10 03:08:15 +02:00
$('#api_button_textgenerationwebui').trigger('click');
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">
<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
});