Caption - allow custom endpoint for xAI
| @@ -416,6 +416,7 @@ jQuery(async function () { | |||
| 416 | 'google': SECRET_KEYS.MAKERSUITE, | 416 | 'google': SECRET_KEYS.MAKERSUITE, |
| 417 | 'vertexai': SECRET_KEYS.VERTEXAI, | 417 | 'vertexai': SECRET_KEYS.VERTEXAI, |
| 418 | 'anthropic': SECRET_KEYS.CLAUDE, | 418 | 'anthropic': SECRET_KEYS.CLAUDE, |
| 419 | 'xai': SECRET_KEYS.XAI, | ||
| 419 | }; | 420 | }; |
| 420 | 421 | ||
| 421 | if (reverseProxyApis[api]) { | 422 | if (reverseProxyApis[api]) { |
| @@ -429,7 +430,6 @@ jQuery(async function () { | |||
| 429 | 'zerooneai': SECRET_KEYS.ZEROONEAI, | 430 | 'zerooneai': SECRET_KEYS.ZEROONEAI, |
| 430 | 'groq': SECRET_KEYS.GROQ, | 431 | 'groq': SECRET_KEYS.GROQ, |
| 431 | 'cohere': SECRET_KEYS.COHERE, | 432 | 'cohere': SECRET_KEYS.COHERE, |
| 432 | 'xai': SECRET_KEYS.XAI, | ||
| 433 | }; | 433 | }; |
| 434 | 434 | ||
| 435 | if (chatCompletionApis[api] && secret_state[chatCompletionApis[api]]) { | 435 | if (chatCompletionApis[api] && secret_state[chatCompletionApis[api]]) { |
| @@ -181,7 +181,7 @@ | |||
| 181 | <div data-type="ollama"> | 181 | <div data-type="ollama"> |
| 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>. | 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 | </div> | 183 | </div> |
| 184 | <label data-type="openai,anthropic,google,vertexai,mistral" class="checkbox_label flexBasis100p" for="caption_allow_reverse_proxy" title="Allow using reverse proxy if defined and valid."> | 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 | <input id="caption_allow_reverse_proxy" type="checkbox" class="checkbox"> | 185 | <input id="caption_allow_reverse_proxy" type="checkbox" class="checkbox"> |
| 186 | <span data-i18n="Allow reverse proxy">Allow reverse proxy</span> | 186 | <span data-i18n="Allow reverse proxy">Allow reverse proxy</span> |
| 187 | </label> | 187 | </label> |
| @@ -15,7 +15,7 @@ import { createThumbnail, isValidUrl } from '../utils.js'; | |||
| 15 | */ | 15 | */ |
| 16 | export async function getMultimodalCaption(base64Img, prompt) { | 16 | export async function getMultimodalCaption(base64Img, prompt) { |
| 17 | const useReverseProxy = | 17 | const useReverseProxy = |
| 18 | (['openai', 'anthropic', 'google', 'mistral', 'vertexai'].includes(extension_settings.caption.multimodal_api)) | 18 | (['openai', 'anthropic', 'google', 'mistral', 'vertexai', 'xai'].includes(extension_settings.caption.multimodal_api)) |
| 19 | && extension_settings.caption.allow_reverse_proxy | 19 | && extension_settings.caption.allow_reverse_proxy |
| 20 | && oai_settings.reverse_proxy | 20 | && oai_settings.reverse_proxy |
| 21 | && isValidUrl(oai_settings.reverse_proxy); | 21 | && isValidUrl(oai_settings.reverse_proxy); |
| @@ -157,7 +157,7 @@ function throwIfInvalidModel(useReverseProxy) { | |||
| 157 | throw new Error('Cohere API key is not set.'); | 157 | throw new Error('Cohere API key is not set.'); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | if (extension_settings.caption.multimodal_api === 'xai' && !secret_state[SECRET_KEYS.XAI]) { | 160 | if (extension_settings.caption.multimodal_api === 'xai' && !secret_state[SECRET_KEYS.XAI] && !useReverseProxy) { |
| 161 | throw new Error('xAI API key is not set.'); | 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 | key = readSecret(request.user.directories, SECRET_KEYS.OPENAI); | 22 | key = readSecret(request.user.directories, SECRET_KEYS.OPENAI); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | if (request.body.api === 'openrouter' && !request.body.reverse_proxy) { | 25 | if (request.body.api === 'xai' && !request.body.reverse_proxy) { |
| 26 | key = readSecret(request.user.directories, SECRET_KEYS.OPENROUTER); | 26 | key = readSecret(request.user.directories, SECRET_KEYS.XAI); |
| 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 | if (request.body.reverse_proxy && request.body.proxy_password) { | 33 | if (request.body.reverse_proxy && request.body.proxy_password) { |
| @@ -36,6 +40,10 @@ router.post('/caption-image', async (request, response) => { | |||
| 36 | mergeObjectWithYaml(headers, request.body.custom_include_headers); | 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 | if (request.body.api === 'ooba') { | 47 | if (request.body.api === 'ooba') { |
| 40 | key = readSecret(request.user.directories, SECRET_KEYS.OOBA); | 48 | key = readSecret(request.user.directories, SECRET_KEYS.OOBA); |
| 41 | bodyParams.temperature = 0.1; | 49 | bodyParams.temperature = 0.1; |
| @@ -57,10 +65,6 @@ router.post('/caption-image', async (request, response) => { | |||
| 57 | key = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI); | 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 | if (request.body.api === 'groq') { | 68 | if (request.body.api === 'groq') { |
| 65 | key = readSecret(request.user.directories, SECRET_KEYS.GROQ); | 69 | key = readSecret(request.user.directories, SECRET_KEYS.GROQ); |
| 66 | } | 70 | } |
| @@ -69,10 +73,6 @@ router.post('/caption-image', async (request, response) => { | |||
| 69 | key = readSecret(request.user.directories, SECRET_KEYS.COHERE); | 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 | const noKeyTypes = ['custom', 'ooba', 'koboldcpp', 'vllm', 'llamacpp', 'pollinations']; | 76 | const noKeyTypes = ['custom', 'ooba', 'koboldcpp', 'vllm', 'llamacpp', 'pollinations']; |
| 77 | if (!key && !request.body.reverse_proxy && !noKeyTypes.includes(request.body.api)) { | 77 | if (!key && !request.body.reverse_proxy && !noKeyTypes.includes(request.body.api)) { |
| 78 | console.warn('No key found for API', request.body.api); | 78 | console.warn('No key found for API', request.body.api); |