Moonshot: Load models list from endpoint
| @@ -1991,6 +1991,20 @@ function saveModelList(data) { | |||
| 1991 | 1991 | ||
| 1992 | $('#model_xai_select').val(oai_settings.xai_model).trigger('change'); | 1992 | $('#model_xai_select').val(oai_settings.xai_model).trigger('change'); |
| 1993 | } | 1993 | } |
| 1994 | |||
| 1995 | if (oai_settings.chat_completion_source == chat_completion_sources.MOONSHOT) { | ||
| 1996 | $('#model_moonshot_select').empty(); | ||
| 1997 | model_list.forEach((model) => { | ||
| 1998 | $('#model_moonshot_select').append(new Option(model.id, model.id)); | ||
| 1999 | }); | ||
| 2000 | |||
| 2001 | const selectedModel = model_list.find(model => model.id === oai_settings.moonshot_model); | ||
| 2002 | if (model_list.length > 0 && (!selectedModel || !oai_settings.moonshot_model)) { | ||
| 2003 | oai_settings.moonshot_model = model_list[0].id; | ||
| 2004 | } | ||
| 2005 | |||
| 2006 | $('#model_moonshot_select').val(oai_settings.moonshot_model).trigger('change'); | ||
| 2007 | } | ||
| 1994 | } | 2008 | } |
| 1995 | 2009 | ||
| 1996 | function appendOpenRouterOptions(model_list, groupModels = false, sort = false) { | 2010 | function appendOpenRouterOptions(model_list, groupModels = false, sort = false) { |
| @@ -4746,11 +4760,24 @@ function getZaiMaxContext(model, isUnlocked) { | |||
| 4746 | return Object.entries(contextMap).find(([key]) => model.includes(key))?.[1] || max_128k; | 4760 | return Object.entries(contextMap).find(([key]) => model.includes(key))?.[1] || max_128k; |
| 4747 | } | 4761 | } |
| 4748 | 4762 | ||
| 4763 | /** | ||
| 4764 | * Get the maximum context size for the Moonshot model | ||
| 4765 | * @param {string} model Model identifier | ||
| 4766 | * @param {boolean} isUnlocked If context limits are unlocked | ||
| 4767 | * @returns {number} Maximum context size in tokens | ||
| 4768 | */ | ||
| 4749 | function getMoonshotMaxContext(model, isUnlocked) { | 4769 | function getMoonshotMaxContext(model, isUnlocked) { |
| 4750 | if (isUnlocked) { | 4770 | if (isUnlocked) { |
| 4751 | return unlocked_max; | 4771 | return unlocked_max; |
| 4752 | } | 4772 | } |
| 4753 | 4773 | ||
| 4774 | if (Array.isArray(model_list) && model_list.length > 0) { | ||
| 4775 | const modelInfo = model_list.find((record) => record.id === model); | ||
| 4776 | if (modelInfo?.context_length) { | ||
| 4777 | return modelInfo.context_length; | ||
| 4778 | } | ||
| 4779 | } | ||
| 4780 | |||
| 4754 | const contextMap = { | 4781 | const contextMap = { |
| 4755 | 'moonshot-v1-8k': max_8k, | 4782 | 'moonshot-v1-8k': max_8k, |
| 4756 | 'moonshot-v1-32k': max_32k, | 4783 | 'moonshot-v1-32k': max_32k, |
| @@ -4983,6 +5010,10 @@ async function onModelChange() { | |||
| 4983 | } | 5010 | } |
| 4984 | 5011 | ||
| 4985 | if (value && $(this).is('#model_moonshot_select')) { | 5012 | if (value && $(this).is('#model_moonshot_select')) { |
| 5013 | if (!value) { | ||
| 5014 | console.debug('Null Moonshot model selected. Ignoring.'); | ||
| 5015 | return; | ||
| 5016 | } | ||
| 4986 | console.log('Moonshot model changed to', value); | 5017 | console.log('Moonshot model changed to', value); |
| 4987 | oai_settings.moonshot_model = value; | 5018 | oai_settings.moonshot_model = value; |
| 4988 | } | 5019 | } |