Add select2 style for NanoGPT list Closes #4911

373da39bf47bd0bf018585f347f1bba32850b5ff

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +37 -0Showing whitespace changes
public/scripts/openai.js+37 -0
@@ -1792,6 +1792,35 @@ function getChutesModelTemplate(option) {
17921792 `));
17931793}
17941794
1795+function getNanoGptModelTemplate(option) {
1796+ const model = model_list.find(x => x.id === option?.element?.value);
1797+
1798+ if (!option.id || !model) {
1799+ return option.text;
1800+ }
1801+
1802+ const inputPrice = model.pricing?.prompt;
1803+ const outputPrice = model.pricing?.completion;
1804+
1805+ let price = 'Unknown';
1806+ if (inputPrice !== undefined && outputPrice !== undefined) {
1807+ // Check if both prices are 0 (free model)
1808+ if (inputPrice === 0 && outputPrice === 0) {
1809+ price = 'Free';
1810+ } else {
1811+ price = `$${Math.round(inputPrice * 100) / 100}/$${Math.round(outputPrice * 100) / 100} in/out Mtoken`;
1812+ }
1813+ }
1814+
1815+ const contextLength = model.context_length || 'Unknown';
1816+
1817+ return $((`
1818+ <div class="flex-container alignItemsBaseline" title="${DOMPurify.sanitize(model.id)}">
1819+ <strong>${DOMPurify.sanitize(model.id)}</strong> | ${contextLength} ctx | <small>${price}</small>
1820+ </div>
1821+ `));
1822+}
1823+
17951824function calculateChutesCost() {
17961825 if (oai_settings.chat_completion_source !== chat_completion_sources.CHUTES) {
17971826 return;
@@ -6708,6 +6737,14 @@ export function initOpenAI() {
67086737 templateResult: getChutesModelTemplate,
67096738 matcher: textValueMatcher,
67106739 });
6740+ $('#model_nanogpt_select').select2({
6741+ placeholder: t`Select a model`,
6742+ searchInputPlaceholder: t`Search models...`,
6743+ searchInputCssClass: 'text_pole',
6744+ width: '100%',
6745+ templateResult: getNanoGptModelTemplate,
6746+ matcher: textValueMatcher,
6747+ });
67116748 $('#completion_prompt_manager_popup_entry_form_injection_trigger').select2({
67126749 placeholder: t`All types (default)`,
67136750 width: '100%',