Caption - allow custom endpoint for xAI
| @@ -416,6 +416,7 @@ jQuery(async function () { | ||
| 416 | 416 | 'google': SECRET_KEYS.MAKERSUITE, |
| 417 | 417 | 'vertexai': SECRET_KEYS.VERTEXAI, |
| 418 | 418 | 'anthropic': SECRET_KEYS.CLAUDE, |
| 419 | + 'xai': SECRET_KEYS.XAI, | |
| 419 | 420 | }; |
| 420 | 421 | |
| 421 | 422 | if (reverseProxyApis[api]) { |
| @@ -429,7 +430,6 @@ jQuery(async function () { | ||
| 429 | 430 | 'zerooneai': SECRET_KEYS.ZEROONEAI, |
| 430 | 431 | 'groq': SECRET_KEYS.GROQ, |
| 431 | 432 | 'cohere': SECRET_KEYS.COHERE, |
| 432 | - 'xai': SECRET_KEYS.XAI, | |
| 433 | 433 | }; |
| 434 | 434 | |
| 435 | 435 | if (chatCompletionApis[api] && secret_state[chatCompletionApis[api]]) { |
| @@ -181,7 +181,7 @@ | ||
| 181 | 181 | <div data-type="ollama"> |
| 182 | 182 | The model must be downloaded first! Do it with the <code>ollama pull</code> command or <a href="#" id="caption_ollama_pull">click here</a>. |
| 183 | 183 | </div> |
| 184 | 184 | <label data-type="openai,anthropic,google,vertexai,mistral,xai" class="checkbox_label flexBasis100p" for="caption_allow_reverse_proxy" title="Allow using reverse proxy if defined and valid."> |
| 185 | 185 | <input id="caption_allow_reverse_proxy" type="checkbox" class="checkbox"> |
| 186 | 186 | <span data-i18n="Allow reverse proxy">Allow reverse proxy</span> |
| 187 | 187 | </label> |
| @@ -15,7 +15,7 @@ import { createThumbnail, isValidUrl } from '../utils.js'; | ||
| 15 | 15 | */ |
| 16 | 16 | export async function getMultimodalCaption(base64Img, prompt) { |
| 17 | 17 | const useReverseProxy = |
| 18 | 18 | (['openai', 'anthropic', 'google', 'mistral', 'vertexai', 'xai'].includes(extension_settings.caption.multimodal_api)) |
| 19 | 19 | && extension_settings.caption.allow_reverse_proxy |
| 20 | 20 | && oai_settings.reverse_proxy |
| 21 | 21 | && isValidUrl(oai_settings.reverse_proxy); |
| @@ -157,7 +157,7 @@ function throwIfInvalidModel(useReverseProxy) { | ||
| 157 | 157 | throw new Error('Cohere API key is not set.'); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | if (extension_settings.caption.multimodal_api === 'xai' && !secret_state[SECRET_KEYS.XAI] && !useReverseProxy) { |
| 161 | 161 | throw new Error('xAI API key is not set.'); |
| 162 | 162 | } |
| 163 | 163 | |
| @@ -22,8 +22,12 @@ router.post('/caption-image', async (request, response) => { | ||
| 22 | 22 | key = readSecret(request.user.directories, SECRET_KEYS.OPENAI); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if (request.body.api === 'openrouterxai' && !request.body.reverse_proxy) { |
| 26 | 26 | key = readSecret(request.user.directories, SECRET_KEYS.OPENROUTERXAI); |
| 27 | + } | |
| 28 | + | |
| 29 | + if (request.body.api === 'mistral' && !request.body.reverse_proxy) { | |
| 30 | + key = readSecret(request.user.directories, SECRET_KEYS.MISTRALAI); | |
| 27 | 31 | } |
| 28 | 32 | |
| 29 | 33 | if (request.body.reverse_proxy && request.body.proxy_password) { |
| @@ -36,6 +40,10 @@ router.post('/caption-image', async (request, response) => { | ||
| 36 | 40 | mergeObjectWithYaml(headers, request.body.custom_include_headers); |
| 37 | 41 | } |
| 38 | 42 | |
| 43 | + if (request.body.api === 'openrouter') { | |
| 44 | + key = readSecret(request.user.directories, SECRET_KEYS.OPENROUTER); | |
| 45 | + } | |
| 46 | + | |
| 39 | 47 | if (request.body.api === 'ooba') { |
| 40 | 48 | key = readSecret(request.user.directories, SECRET_KEYS.OOBA); |
| 41 | 49 | bodyParams.temperature = 0.1; |
| @@ -57,10 +65,6 @@ router.post('/caption-image', async (request, response) => { | ||
| 57 | 65 | key = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI); |
| 58 | 66 | } |
| 59 | 67 | |
| 60 | - if (request.body.api === 'mistral') { | |
| 61 | - key = readSecret(request.user.directories, SECRET_KEYS.MISTRALAI); | |
| 62 | - } | |
| 63 | - | |
| 64 | 68 | if (request.body.api === 'groq') { |
| 65 | 69 | key = readSecret(request.user.directories, SECRET_KEYS.GROQ); |
| 66 | 70 | } |
| @@ -69,10 +73,6 @@ router.post('/caption-image', async (request, response) => { | ||
| 69 | 73 | key = readSecret(request.user.directories, SECRET_KEYS.COHERE); |
| 70 | 74 | } |
| 71 | 75 | |
| 72 | - if (request.body.api === 'xai') { | |
| 73 | - key = readSecret(request.user.directories, SECRET_KEYS.XAI); | |
| 74 | - } | |
| 75 | - | |
| 76 | 76 | const noKeyTypes = ['custom', 'ooba', 'koboldcpp', 'vllm', 'llamacpp', 'pollinations']; |
| 77 | 77 | if (!key && !request.body.reverse_proxy && !noKeyTypes.includes(request.body.api)) { |
| 78 | 78 | console.warn('No key found for API', request.body.api); |