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

051b2757950437170235edc8e3fcfef23d6cd670

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

Signed
1 files changed, +14 -10Ignore whitespace
public/scripts/openai.js+14 -10
@@ -4691,6 +4691,9 @@ async function onModelChange() {
46914691 biasCache = undefined;
46924692 let value = String($(this).val() || '');
46934693
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+
46944697 if ($(this).is('#model_claude_select')) {
46954698 if (value.includes('-v')) {
46964699 value = value.replace('-v', '-');
@@ -4709,7 +4712,7 @@ async function onModelChange() {
47094712 }
47104713
47114714 if ($(this).is('#model_openrouter_select')) {
47124715 if (!value || !hasModelsLoaded) {
47134716 console.debug('Null OR model selected. Ignoring.');
47144717 return;
47154718 }
@@ -4744,7 +4747,7 @@ async function onModelChange() {
47444747 }
47454748
47464749 if ($(this).is('#model_mistralai_select')) {
47474750 if (!value || !hasModelsLoaded) {
47484751 console.debug('Null MistralAI model selected. Ignoring.');
47494752 return;
47504753 }
@@ -4769,7 +4772,7 @@ async function onModelChange() {
47694772 }
47704773
47714774 if ($(this).is('#model_groq_select')) {
47724775 if (!value || !hasModelsLoaded) {
47734776 console.debug('Null Groq model selected. Ignoring.');
47744777 return;
47754778 }
@@ -4787,7 +4790,7 @@ async function onModelChange() {
47874790 }
47884791
47894792 if ($(this).is('#model_electronhub_select')) {
47904793 if (!value || !hasModelsLoaded) {
47914794 console.debug('Null ElectronHub model selected. Ignoring.');
47924795 return;
47934796 }
@@ -4796,7 +4799,7 @@ async function onModelChange() {
47964799 }
47974800
47984801 if ($(this).is('#model_nanogpt_select')) {
47994802 if (!value || !hasModelsLoaded) {
48004803 console.debug('Null NanoGPT model selected. Ignoring.');
48014804 return;
48024805 }
@@ -4827,7 +4830,7 @@ async function onModelChange() {
48274830 }
48284831
48294832 if ($(this).is('#model_aimlapi_select')) {
48304833 if (!value || !hasModelsLoaded) {
48314834 console.debug('Null AI/ML model selected. Ignoring.');
48324835 return;
48334836 }
@@ -4844,8 +4847,8 @@ async function onModelChange() {
48444847 oai_settings.xai_model = value;
48454848 }
48464849
48474850 if (value && $(this).is('#model_moonshot_select')) {
48484851 if (!value || !hasModelsLoaded) {
48494852 console.debug('Null Moonshot model selected. Ignoring.');
48504853 return;
48514854 }
@@ -4854,7 +4857,7 @@ async function onModelChange() {
48544857 }
48554858
48564859 if ($(this).is('#model_fireworks_select')) {
48574860 if (!value || !hasModelsLoaded) {
48584861 console.debug('Null Fireworks model selected. Ignoring.');
48594862 return;
48604863 }
@@ -4917,7 +4920,7 @@ async function onModelChange() {
49174920 if (model?.context_length) {
49184921 $('#openai_max_context').attr('max', model.context_length);
49194922 } else {
49204923 $('#openai_max_context').attr('max', max_8kmax_128k);
49214924 }
49224925 }
49234926 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() {
61096112 });
61106113
61116114 $('#chat_completion_source').on('change', function () {
6115+ model_list = [];
61126116 oai_settings.chat_completion_source = String($(this).find(':selected').val());
61136117 toggleChatCompletionForms();
61146118 saveSettingsDebounced();