import { setGenerationParamsFromPreset } from '../script.js'; import { getDeviceInfo } from './RossAscends-mods.js'; import { textgenerationwebui_settings as textgen_settings } from './textgen-settings.js'; let models = []; export async function loadMancerModels(data) { if (!Array.isArray(data)) { console.error('Invalid Mancer models data', data); return; } models = data; $('#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 === textgen_settings.mancer_model; $('#mancer_model').append(option); } } function onMancerModelSelect() { const modelId = String($('#mancer_model').val()); textgen_settings.mancer_model = modelId; $('#api_button_textgenerationwebui').trigger('click'); const limits = models.find(x => x.id === modelId)?.limits; setGenerationParamsFromPreset({ max_length: limits.context, genamt: limits.completion }); } function getMancerModelTemplate(option) { const model = models.find(x => x.id === option?.element?.value); if (!option.id || !model) { return option.text; } const creditsPerPrompt = (model.limits?.context - model.limits?.completion) * model.pricing?.prompt; const creditsPerCompletion = model.limits?.completion * model.pricing?.completion; const creditsTotal = Math.round(creditsPerPrompt + creditsPerCompletion).toFixed(0); return $((`
${DOMPurify.sanitize(model.name)} | ${model.limits?.context} ctx / ${model.limits?.completion} res | Credits per request (max): ${creditsTotal}
`)); } jQuery(function () { $('#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, }); } });