Add xAI for image captioning

17cdc78a9194450902101b0f8dcd38d7fc5eb677

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

5 files changed, +17 -1Showing whitespace changes
public/index.html+1 -1
@@ -1987,7 +1987,7 @@
19871987 <code><i class="fa-solid fa-wand-magic-sparkles"></i></code>
19881988 <span data-i18n="image_inlining_hint_3">menu to attach an image file to the chat.</span>
19891989 </div>
19901990 <div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom,xai">
19911991 <div class="flex-container oneline-dropdown">
19921992 <label for="openai_inline_image_quality" data-i18n="Inline Image Quality">
19931993 Inline Image Quality
public/scripts/extensions/caption/index.js+1 -0
@@ -428,6 +428,7 @@ jQuery(async function () {
428428 'zerooneai': SECRET_KEYS.ZEROONEAI,
429429 'groq': SECRET_KEYS.GROQ,
430430 'cohere': SECRET_KEYS.COHERE,
431+ 'xai': SECRET_KEYS.XAI,
431432 };
432433
433434 if (chatCompletionApis[api] && secret_state[chatCompletionApis[api]]) {
public/scripts/extensions/caption/settings.html+3 -0
@@ -31,6 +31,7 @@
3131 <option value="openrouter">OpenRouter</option>
3232 <option value="ooba" data-i18n="Text Generation WebUI (oobabooga)">Text Generation WebUI (oobabooga)</option>
3333 <option value="vllm">vLLM</option>
34+ <option value="xai">xAI (Grok)</option>
3435 </select>
3536 </div>
3637 <div class="flex1 flex-container flexFlowColumn flexNoGap">
@@ -134,6 +135,8 @@
134135 <option data-type="koboldcpp" value="koboldcpp_current" data-i18n="currently_loaded">[Currently loaded]</option>
135136 <option data-type="vllm" value="vllm_current" data-i18n="currently_selected">[Currently selected]</option>
136137 <option data-type="custom" value="custom_current" data-i18n="currently_selected">[Currently selected]</option>
138+ <option data-type="xai" value="grok-2-vision-1212">grok-2-vision-1212</option>
139+ <option data-type="xai" value="grok-vision-beta">grok-vision-beta</option>
137140 </select>
138141 </div>
139142 <div data-type="ollama">
public/scripts/extensions/shared.js+4 -0
@@ -153,6 +153,10 @@ function throwIfInvalidModel(useReverseProxy) {
153153 throw new Error('Cohere API key is not set.');
154154 }
155155
156+ if (extension_settings.caption.multimodal_api === 'xai' && !secret_state[SECRET_KEYS.XAI]) {
157+ throw new Error('xAI API key is not set.');
158+ }
159+
156160 if (extension_settings.caption.multimodal_api === 'ollama' && !textgenerationwebui_settings.server_urls[textgen_types.OLLAMA]) {
157161 throw new Error('Ollama server URL is not set.');
158162 }
src/endpoints/openai.js+8 -0
@@ -65,6 +65,10 @@ router.post('/caption-image', async (request, response) => {
6565 key = readSecret(request.user.directories, SECRET_KEYS.COHERE);
6666 }
6767
68+ if (request.body.api === 'xai') {
69+ key = readSecret(request.user.directories, SECRET_KEYS.XAI);
70+ }
71+
6872 if (!key && !request.body.reverse_proxy && ['custom', 'ooba', 'koboldcpp', 'vllm'].includes(request.body.api) === false) {
6973 console.warn('No key found for API', request.body.api);
7074 return response.sendStatus(400);
@@ -134,6 +138,10 @@ router.post('/caption-image', async (request, response) => {
134138 apiUrl = 'https://api.cohere.ai/v2/chat';
135139 }
136140
141+ if (request.body.api === 'xai') {
142+ apiUrl = 'https://api.x.ai/v1/chat/completions';
143+ }
144+
137145 if (request.body.api === 'ooba') {
138146 apiUrl = `${trimV1(request.body.server_url)}/v1/chat/completions`;
139147 const imgMessage = body.messages.pop();