Fix resetting the context size when switching between CC sources (#4816) * Fix resetting the context size when switching between CC sources that load the models list dynamically * Revert the requirement to have models list for XAI * Revert for sources that don't load context size from endpoint
Signed| @@ -4691,6 +4691,9 @@ async function onModelChange() { | ||
| 4691 | 4691 | biasCache = undefined; |
| 4692 | 4692 | let value = String($(this).val() || ''); |
| 4693 | 4693 | |
| 4694 | + // Skip setting the context size for sources that get it from external APIs | |
| 4695 | + const hasModelsLoaded = Array.isArray(model_list) && model_list.length > 0; | |
| 4696 | + | |
| 4694 | 4697 | if ($(this).is('#model_claude_select')) { |
| 4695 | 4698 | if (value.includes('-v')) { |
| 4696 | 4699 | value = value.replace('-v', '-'); |
| @@ -4709,7 +4712,7 @@ async function onModelChange() { | ||
| 4709 | 4712 | } |
| 4710 | 4713 | |
| 4711 | 4714 | if ($(this).is('#model_openrouter_select')) { |
| 4712 | 4715 | if (!value || !hasModelsLoaded) { |
| 4713 | 4716 | console.debug('Null OR model selected. Ignoring.'); |
| 4714 | 4717 | return; |
| 4715 | 4718 | } |
| @@ -4744,7 +4747,7 @@ async function onModelChange() { | ||
| 4744 | 4747 | } |
| 4745 | 4748 | |
| 4746 | 4749 | if ($(this).is('#model_mistralai_select')) { |
| 4747 | 4750 | if (!value || !hasModelsLoaded) { |
| 4748 | 4751 | console.debug('Null MistralAI model selected. Ignoring.'); |
| 4749 | 4752 | return; |
| 4750 | 4753 | } |
| @@ -4769,7 +4772,7 @@ async function onModelChange() { | ||
| 4769 | 4772 | } |
| 4770 | 4773 | |
| 4771 | 4774 | if ($(this).is('#model_groq_select')) { |
| 4772 | 4775 | if (!value || !hasModelsLoaded) { |
| 4773 | 4776 | console.debug('Null Groq model selected. Ignoring.'); |
| 4774 | 4777 | return; |
| 4775 | 4778 | } |
| @@ -4787,7 +4790,7 @@ async function onModelChange() { | ||
| 4787 | 4790 | } |
| 4788 | 4791 | |
| 4789 | 4792 | if ($(this).is('#model_electronhub_select')) { |
| 4790 | 4793 | if (!value || !hasModelsLoaded) { |
| 4791 | 4794 | console.debug('Null ElectronHub model selected. Ignoring.'); |
| 4792 | 4795 | return; |
| 4793 | 4796 | } |
| @@ -4796,7 +4799,7 @@ async function onModelChange() { | ||
| 4796 | 4799 | } |
| 4797 | 4800 | |
| 4798 | 4801 | if ($(this).is('#model_nanogpt_select')) { |
| 4799 | 4802 | if (!value || !hasModelsLoaded) { |
| 4800 | 4803 | console.debug('Null NanoGPT model selected. Ignoring.'); |
| 4801 | 4804 | return; |
| 4802 | 4805 | } |
| @@ -4827,7 +4830,7 @@ async function onModelChange() { | ||
| 4827 | 4830 | } |
| 4828 | 4831 | |
| 4829 | 4832 | if ($(this).is('#model_aimlapi_select')) { |
| 4830 | 4833 | if (!value || !hasModelsLoaded) { |
| 4831 | 4834 | console.debug('Null AI/ML model selected. Ignoring.'); |
| 4832 | 4835 | return; |
| 4833 | 4836 | } |
| @@ -4844,8 +4847,8 @@ async function onModelChange() { | ||
| 4844 | 4847 | oai_settings.xai_model = value; |
| 4845 | 4848 | } |
| 4846 | 4849 | |
| 4847 | 4850 | if (value && $(this).is('#model_moonshot_select')) { |
| 4848 | 4851 | if (!value || !hasModelsLoaded) { |
| 4849 | 4852 | console.debug('Null Moonshot model selected. Ignoring.'); |
| 4850 | 4853 | return; |
| 4851 | 4854 | } |
| @@ -4854,7 +4857,7 @@ async function onModelChange() { | ||
| 4854 | 4857 | } |
| 4855 | 4858 | |
| 4856 | 4859 | if ($(this).is('#model_fireworks_select')) { |
| 4857 | 4860 | if (!value || !hasModelsLoaded) { |
| 4858 | 4861 | console.debug('Null Fireworks model selected. Ignoring.'); |
| 4859 | 4862 | return; |
| 4860 | 4863 | } |
| @@ -4917,7 +4920,7 @@ async function onModelChange() { | ||
| 4917 | 4920 | if (model?.context_length) { |
| 4918 | 4921 | $('#openai_max_context').attr('max', model.context_length); |
| 4919 | 4922 | } else { |
| 4920 | 4923 | $('#openai_max_context').attr('max', max_8kmax_128k); |
| 4921 | 4924 | } |
| 4922 | 4925 | } |
| 4923 | 4926 | oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context); |
| @@ -6109,6 +6112,7 @@ export function initOpenAI() { | ||
| 6109 | 6112 | }); |
| 6110 | 6113 | |
| 6111 | 6114 | $('#chat_completion_source').on('change', function () { |
| 6115 | + model_list = []; | |
| 6112 | 6116 | oai_settings.chat_completion_source = String($(this).find(':selected').val()); |
| 6113 | 6117 | toggleChatCompletionForms(); |
| 6114 | 6118 | saveSettingsDebounced(); |