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() {
4691 biasCache = undefined;4691 biasCache = undefined;
4692 let value = String($(this).val() || '');4692 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
4694 if ($(this).is('#model_claude_select')) {4697 if ($(this).is('#model_claude_select')) {
4695 if (value.includes('-v')) {4698 if (value.includes('-v')) {
4696 value = value.replace('-v', '-');4699 value = value.replace('-v', '-');
@@ -4709,7 +4712,7 @@ async function onModelChange() {
4709 }4712 }
47104713
4711 if ($(this).is('#model_openrouter_select')) {4714 if ($(this).is('#model_openrouter_select')) {
4712 if (!value) {4715 if (!value || !hasModelsLoaded) {
4713 console.debug('Null OR model selected. Ignoring.');4716 console.debug('Null OR model selected. Ignoring.');
4714 return;4717 return;
4715 }4718 }
@@ -4744,7 +4747,7 @@ async function onModelChange() {
4744 }4747 }
47454748
4746 if ($(this).is('#model_mistralai_select')) {4749 if ($(this).is('#model_mistralai_select')) {
4747 if (!value) {4750 if (!value || !hasModelsLoaded) {
4748 console.debug('Null MistralAI model selected. Ignoring.');4751 console.debug('Null MistralAI model selected. Ignoring.');
4749 return;4752 return;
4750 }4753 }
@@ -4769,7 +4772,7 @@ async function onModelChange() {
4769 }4772 }
47704773
4771 if ($(this).is('#model_groq_select')) {4774 if ($(this).is('#model_groq_select')) {
4772 if (!value) {4775 if (!value || !hasModelsLoaded) {
4773 console.debug('Null Groq model selected. Ignoring.');4776 console.debug('Null Groq model selected. Ignoring.');
4774 return;4777 return;
4775 }4778 }
@@ -4787,7 +4790,7 @@ async function onModelChange() {
4787 }4790 }
47884791
4789 if ($(this).is('#model_electronhub_select')) {4792 if ($(this).is('#model_electronhub_select')) {
4790 if (!value) {4793 if (!value || !hasModelsLoaded) {
4791 console.debug('Null ElectronHub model selected. Ignoring.');4794 console.debug('Null ElectronHub model selected. Ignoring.');
4792 return;4795 return;
4793 }4796 }
@@ -4796,7 +4799,7 @@ async function onModelChange() {
4796 }4799 }
47974800
4798 if ($(this).is('#model_nanogpt_select')) {4801 if ($(this).is('#model_nanogpt_select')) {
4799 if (!value) {4802 if (!value || !hasModelsLoaded) {
4800 console.debug('Null NanoGPT model selected. Ignoring.');4803 console.debug('Null NanoGPT model selected. Ignoring.');
4801 return;4804 return;
4802 }4805 }
@@ -4827,7 +4830,7 @@ async function onModelChange() {
4827 }4830 }
48284831
4829 if ($(this).is('#model_aimlapi_select')) {4832 if ($(this).is('#model_aimlapi_select')) {
4830 if (!value) {4833 if (!value || !hasModelsLoaded) {
4831 console.debug('Null AI/ML model selected. Ignoring.');4834 console.debug('Null AI/ML model selected. Ignoring.');
4832 return;4835 return;
4833 }4836 }
@@ -4844,8 +4847,8 @@ async function onModelChange() {
4844 oai_settings.xai_model = value;4847 oai_settings.xai_model = value;
4845 }4848 }
48464849
4847 if (value && $(this).is('#model_moonshot_select')) {4850 if ($(this).is('#model_moonshot_select')) {
4848 if (!value) {4851 if (!value || !hasModelsLoaded) {
4849 console.debug('Null Moonshot model selected. Ignoring.');4852 console.debug('Null Moonshot model selected. Ignoring.');
4850 return;4853 return;
4851 }4854 }
@@ -4854,7 +4857,7 @@ async function onModelChange() {
4854 }4857 }
48554858
4856 if ($(this).is('#model_fireworks_select')) {4859 if ($(this).is('#model_fireworks_select')) {
4857 if (!value) {4860 if (!value || !hasModelsLoaded) {
4858 console.debug('Null Fireworks model selected. Ignoring.');4861 console.debug('Null Fireworks model selected. Ignoring.');
4859 return;4862 return;
4860 }4863 }
@@ -4917,7 +4920,7 @@ async function onModelChange() {
4917 if (model?.context_length) {4920 if (model?.context_length) {
4918 $('#openai_max_context').attr('max', model.context_length);4921 $('#openai_max_context').attr('max', model.context_length);
4919 } else {4922 } else {
4920 $('#openai_max_context').attr('max', max_8k);4923 $('#openai_max_context').attr('max', max_128k);
4921 }4924 }
4922 }4925 }
4923 oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context);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 });
61106113
6111 $('#chat_completion_source').on('change', function () {6114 $('#chat_completion_source').on('change', function () {
6115 model_list = [];
6112 oai_settings.chat_completion_source = String($(this).find(':selected').val());6116 oai_settings.chat_completion_source = String($(this).find(':selected').val());
6113 toggleChatCompletionForms();6117 toggleChatCompletionForms();
6114 saveSettingsDebounced();6118 saveSettingsDebounced();