Caption - allow custom endpoint for xAI

57b81be9ce28f92cba7e50dc238204f1e48c889d

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

4 files changed, +14 -14Ignore whitespace
public/scripts/extensions/caption/index.js+1 -1
@@ -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 };
420421
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 };
434434
435 if (chatCompletionApis[api] && secret_state[chatCompletionApis[api]]) {435 if (chatCompletionApis[api] && secret_state[chatCompletionApis[api]]) {
public/scripts/extensions/caption/settings.html+1 -1
@@ -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>
public/scripts/extensions/shared.js+2 -2
@@ -15,7 +15,7 @@ import { createThumbnail, isValidUrl } from '../utils.js';
15 */15 */
16export async function getMultimodalCaption(base64Img, prompt) {16export 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_proxy19 && extension_settings.caption.allow_reverse_proxy
20 && oai_settings.reverse_proxy20 && 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 }
159159
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 }
163163
src/endpoints/openai.js+10 -10
@@ -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 }
2424
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 }
2832
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 }
3842
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 }
5967
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 }
7175
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);