Add select2 style for NanoGPT list Closes #4911
| @@ -1792,6 +1792,35 @@ function getChutesModelTemplate(option) { | |||
| 1792 | `)); | 1792 | `)); |
| 1793 | } | 1793 | } |
| 1794 | 1794 | ||
| 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 | |||
| 1795 | function calculateChutesCost() { | 1824 | function calculateChutesCost() { |
| 1796 | if (oai_settings.chat_completion_source !== chat_completion_sources.CHUTES) { | 1825 | if (oai_settings.chat_completion_source !== chat_completion_sources.CHUTES) { |
| 1797 | return; | 1826 | return; |
| @@ -6708,6 +6737,14 @@ export function initOpenAI() { | |||
| 6708 | templateResult: getChutesModelTemplate, | 6737 | templateResult: getChutesModelTemplate, |
| 6709 | matcher: textValueMatcher, | 6738 | matcher: textValueMatcher, |
| 6710 | }); | 6739 | }); |
| 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 | }); | ||
| 6711 | $('#completion_prompt_manager_popup_entry_form_injection_trigger').select2({ | 6748 | $('#completion_prompt_manager_popup_entry_form_injection_trigger').select2({ |
| 6712 | placeholder: t`All types (default)`, | 6749 | placeholder: t`All types (default)`, |
| 6713 | width: '100%', | 6750 | width: '100%', |