Moonshot: Pull vision flag from model data Fixes #5068

0e5b4de10c6e8d123a8e0d22a8aef7992fed151b

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

4 files changed, +40 -6Showing whitespace changes
public/scripts/extensions/caption/index.js+1 -0
@@ -623,6 +623,7 @@ jQuery(async function () {
623623 await processEndpoint('electronhub', '/api/backends/chat-completions/multimodal-models/electronhub');
624624 await processEndpoint('mistral', '/api/backends/chat-completions/multimodal-models/mistral');
625625 await processEndpoint('xai', '/api/backends/chat-completions/multimodal-models/xai');
626+ await processEndpoint('moonshot', '/api/backends/chat-completions/multimodal-models/moonshot');
626627 }
627628
628629 await addSettings();
public/scripts/extensions/caption/settings.html+1 -4
@@ -49,13 +49,10 @@
4949 </div>
5050 </label>
5151 <select id="caption_multimodal_model" class="flex1 text_pole">
5252 <!-- AI/ML API, OpenRouter, Pollinations, NanoGPT, Mistral, xAI, Moonshot are added externally by JavaScript -->
5353 <option data-type="cohere" value="c4ai-aya-vision-8b">c4ai-aya-vision-8b</option>
5454 <option data-type="cohere" value="c4ai-aya-vision-32b">c4ai-aya-vision-32b</option>
5555 <option data-type="cohere" value="command-a-vision-07-2025">command-a-vision-07-2025</option>
56- <option data-type="moonshot" value="moonshot-v1-8k-vision-preview">moonshot-v1-8k-vision-preview</option>
57- <option data-type="moonshot" value="moonshot-v1-32k-vision-preview">moonshot-v1-32k-vision-preview</option>
58- <option data-type="moonshot" value="moonshot-v1-128k-vision-preview">moonshot-v1-128k-vision-preview</option>
5956 <option data-type="openai" value="gpt-5.2">gpt-5.2</option>
6057 <option data-type="openai" value="gpt-5.2-2025-12-11">gpt-5.2-2025-12-11</option>
6158 <option data-type="openai" value="gpt-5.2-chat-latest">gpt-5.2-chat-latest</option>
public/scripts/openai.js+9 -2
@@ -4909,8 +4909,13 @@ function getMoonshotMaxContext(model, isUnlocked) {
49094909 'moonshot-v1-32k-vision-preview': max_32k,
49104910 'moonshot-v1-128k-vision-preview': max_128k,
49114911 'kimi-k2-0711-preview': max_32k,
49124912 'kimi-latest': max_32kmax_256k,
49134913 'kimi-thinking-preview': max_32k,
4914+ 'kimi-k2.5': max_256k,
4915+ 'kimi-k2-0905-preview': max_256k,
4916+ 'kimi-k2-turbo-preview': max_256k,
4917+ 'kimi-k2-thinking': max_256k,
4918+ 'kimi-k2-thinking-turbo': max_256k,
49144919 };
49154920
49164921 // Return context size if model found, otherwise default to 32k
@@ -5837,6 +5842,8 @@ export function isImageInliningSupported() {
58375842 'moonshot-v1-8k-vision-preview',
58385843 'moonshot-v1-32k-vision-preview',
58395844 'moonshot-v1-128k-vision-preview',
5845+ 'kimi-k2.5',
5846+ 'kimi-latest',
58405847 // Z.AI (GLM)
58415848 'glm-4.5v',
58425849 'glm-4.6v',
@@ -5888,7 +5895,7 @@ export function isImageInliningSupported() {
58885895 case chat_completion_sources.COMETAPI:
58895896 return true;
58905897 case chat_completion_sources.MOONSHOT:
5891- return visionSupportedModels.some(model => oai_settings.moonshot_model.includes(model));
5898+ return (Array.isArray(model_list) && model_list.find(m => m.id === oai_settings.moonshot_model)?.supports_image_in);
58925899 case chat_completion_sources.NANOGPT:
58935900 return (Array.isArray(model_list) && model_list.find(m => m.id === oai_settings.nanogpt_model)?.capabilities?.vision);
58945901 case chat_completion_sources.ZAI:
src/endpoints/backends/chat-completions.js+29 -0
@@ -2615,6 +2615,35 @@ multimodalModels.post('/xai', async (req, res) => {
26152615 }
26162616});
26172617
2618+multimodalModels.post('/moonshot', async (req, res) => {
2619+ try {
2620+ const key = readSecret(req.user.directories, SECRET_KEYS.MOONSHOT);
2621+
2622+ if (!key) {
2623+ return res.json([]);
2624+ }
2625+
2626+ const response = await fetch('https://api.moonshot.ai/v1/models', {
2627+ headers: {
2628+ 'Authorization': `Bearer ${key}`,
2629+ },
2630+ });
2631+
2632+ if (!response.ok) {
2633+ return res.json([]);
2634+ }
2635+
2636+ /** @type {any} */
2637+ const data = await response.json();
2638+
2639+ const multimodalModels = data.data.filter(m => m.supports_image_in).map(m => m.id);
2640+ return res.json(multimodalModels);
2641+ } catch (error) {
2642+ console.error(error);
2643+ return res.sendStatus(500);
2644+ }
2645+});
2646+
26182647router.use('/multimodal-models', multimodalModels);
26192648
26202649router.post('/process', async function (request, response) {