Caption - allow custom endpoint for xAI

57b81be9ce28f92cba7e50dc238204f1e48c889d

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

4 files changed, +14 -14Showing whitespace changes
public/scripts/extensions/caption/index.js+1 -1
@@ -416,6 +416,7 @@ jQuery(async function () {
416416 'google': SECRET_KEYS.MAKERSUITE,
417417 'vertexai': SECRET_KEYS.VERTEXAI,
418418 'anthropic': SECRET_KEYS.CLAUDE,
419+ 'xai': SECRET_KEYS.XAI,
419420 };
420421
421422 if (reverseProxyApis[api]) {
@@ -429,7 +430,6 @@ jQuery(async function () {
429430 'zerooneai': SECRET_KEYS.ZEROONEAI,
430431 'groq': SECRET_KEYS.GROQ,
431432 'cohere': SECRET_KEYS.COHERE,
432- 'xai': SECRET_KEYS.XAI,
433433 };
434434
435435 if (chatCompletionApis[api] && secret_state[chatCompletionApis[api]]) {
public/scripts/extensions/caption/settings.html+1 -1
@@ -181,7 +181,7 @@
181181 <div data-type="ollama">
182182 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>.
183183 </div>
184184 <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.">
185185 <input id="caption_allow_reverse_proxy" type="checkbox" class="checkbox">
186186 <span data-i18n="Allow reverse proxy">Allow reverse proxy</span>
187187 </label>
public/scripts/extensions/shared.js+2 -2
@@ -15,7 +15,7 @@ import { createThumbnail, isValidUrl } from '../utils.js';
1515 */
1616export async function getMultimodalCaption(base64Img, prompt) {
1717 const useReverseProxy =
1818 (['openai', 'anthropic', 'google', 'mistral', 'vertexai', 'xai'].includes(extension_settings.caption.multimodal_api))
1919 && extension_settings.caption.allow_reverse_proxy
2020 && oai_settings.reverse_proxy
2121 && isValidUrl(oai_settings.reverse_proxy);
@@ -157,7 +157,7 @@ function throwIfInvalidModel(useReverseProxy) {
157157 throw new Error('Cohere API key is not set.');
158158 }
159159
160160 if (extension_settings.caption.multimodal_api === 'xai' && !secret_state[SECRET_KEYS.XAI] && !useReverseProxy) {
161161 throw new Error('xAI API key is not set.');
162162 }
163163
src/endpoints/openai.js+10 -10
@@ -22,8 +22,12 @@ router.post('/caption-image', async (request, response) => {
2222 key = readSecret(request.user.directories, SECRET_KEYS.OPENAI);
2323 }
2424
2525 if (request.body.api === 'openrouterxai' && !request.body.reverse_proxy) {
2626 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);
2731 }
2832
2933 if (request.body.reverse_proxy && request.body.proxy_password) {
@@ -36,6 +40,10 @@ router.post('/caption-image', async (request, response) => {
3640 mergeObjectWithYaml(headers, request.body.custom_include_headers);
3741 }
3842
43+ if (request.body.api === 'openrouter') {
44+ key = readSecret(request.user.directories, SECRET_KEYS.OPENROUTER);
45+ }
46+
3947 if (request.body.api === 'ooba') {
4048 key = readSecret(request.user.directories, SECRET_KEYS.OOBA);
4149 bodyParams.temperature = 0.1;
@@ -57,10 +65,6 @@ router.post('/caption-image', async (request, response) => {
5765 key = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI);
5866 }
5967
60- if (request.body.api === 'mistral') {
61- key = readSecret(request.user.directories, SECRET_KEYS.MISTRALAI);
62- }
63-
6468 if (request.body.api === 'groq') {
6569 key = readSecret(request.user.directories, SECRET_KEYS.GROQ);
6670 }
@@ -69,10 +73,6 @@ router.post('/caption-image', async (request, response) => {
6973 key = readSecret(request.user.directories, SECRET_KEYS.COHERE);
7074 }
7175
72- if (request.body.api === 'xai') {
73- key = readSecret(request.user.directories, SECRET_KEYS.XAI);
74- }
75-
7676 const noKeyTypes = ['custom', 'ooba', 'koboldcpp', 'vllm', 'llamacpp', 'pollinations'];
7777 if (!key && !request.body.reverse_proxy && !noKeyTypes.includes(request.body.api)) {
7878 console.warn('No key found for API', request.body.api);