Add xAI for image captioning

This commit is contained in:
Cohee
2025-04-11 19:05:03 +03:00
parent 1c52099ed6
commit 17cdc78a91
5 changed files with 17 additions and 1 deletions

View File

@ -1987,7 +1987,7 @@
<code><i class="fa-solid fa-wand-magic-sparkles"></i></code> <code><i class="fa-solid fa-wand-magic-sparkles"></i></code>
<span data-i18n="image_inlining_hint_3">menu to attach an image file to the chat.</span> <span data-i18n="image_inlining_hint_3">menu to attach an image file to the chat.</span>
</div> </div>
<div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom"> <div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom,xai">
<div class="flex-container oneline-dropdown"> <div class="flex-container oneline-dropdown">
<label for="openai_inline_image_quality" data-i18n="Inline Image Quality"> <label for="openai_inline_image_quality" data-i18n="Inline Image Quality">
Inline Image Quality Inline Image Quality

View File

@ -428,6 +428,7 @@ jQuery(async function () {
'zerooneai': SECRET_KEYS.ZEROONEAI, 'zerooneai': SECRET_KEYS.ZEROONEAI,
'groq': SECRET_KEYS.GROQ, 'groq': SECRET_KEYS.GROQ,
'cohere': SECRET_KEYS.COHERE, 'cohere': SECRET_KEYS.COHERE,
'xai': SECRET_KEYS.XAI,
}; };
if (chatCompletionApis[api] && secret_state[chatCompletionApis[api]]) { if (chatCompletionApis[api] && secret_state[chatCompletionApis[api]]) {

View File

@ -31,6 +31,7 @@
<option value="openrouter">OpenRouter</option> <option value="openrouter">OpenRouter</option>
<option value="ooba" data-i18n="Text Generation WebUI (oobabooga)">Text Generation WebUI (oobabooga)</option> <option value="ooba" data-i18n="Text Generation WebUI (oobabooga)">Text Generation WebUI (oobabooga)</option>
<option value="vllm">vLLM</option> <option value="vllm">vLLM</option>
<option value="xai">xAI (Grok)</option>
</select> </select>
</div> </div>
<div class="flex1 flex-container flexFlowColumn flexNoGap"> <div class="flex1 flex-container flexFlowColumn flexNoGap">
@ -134,6 +135,8 @@
<option data-type="koboldcpp" value="koboldcpp_current" data-i18n="currently_loaded">[Currently loaded]</option> <option data-type="koboldcpp" value="koboldcpp_current" data-i18n="currently_loaded">[Currently loaded]</option>
<option data-type="vllm" value="vllm_current" data-i18n="currently_selected">[Currently selected]</option> <option data-type="vllm" value="vllm_current" data-i18n="currently_selected">[Currently selected]</option>
<option data-type="custom" value="custom_current" data-i18n="currently_selected">[Currently selected]</option> <option data-type="custom" value="custom_current" data-i18n="currently_selected">[Currently selected]</option>
<option data-type="xai" value="grok-2-vision-1212">grok-2-vision-1212</option>
<option data-type="xai" value="grok-vision-beta">grok-vision-beta</option>
</select> </select>
</div> </div>
<div data-type="ollama"> <div data-type="ollama">

View File

@ -153,6 +153,10 @@ function throwIfInvalidModel(useReverseProxy) {
throw new Error('Cohere API key is not set.'); throw new Error('Cohere API key is not set.');
} }
if (extension_settings.caption.multimodal_api === 'xai' && !secret_state[SECRET_KEYS.XAI]) {
throw new Error('xAI API key is not set.');
}
if (extension_settings.caption.multimodal_api === 'ollama' && !textgenerationwebui_settings.server_urls[textgen_types.OLLAMA]) { if (extension_settings.caption.multimodal_api === 'ollama' && !textgenerationwebui_settings.server_urls[textgen_types.OLLAMA]) {
throw new Error('Ollama server URL is not set.'); throw new Error('Ollama server URL is not set.');
} }

View File

@ -65,6 +65,10 @@ router.post('/caption-image', async (request, response) => {
key = readSecret(request.user.directories, SECRET_KEYS.COHERE); key = readSecret(request.user.directories, SECRET_KEYS.COHERE);
} }
if (request.body.api === 'xai') {
key = readSecret(request.user.directories, SECRET_KEYS.XAI);
}
if (!key && !request.body.reverse_proxy && ['custom', 'ooba', 'koboldcpp', 'vllm'].includes(request.body.api) === false) { if (!key && !request.body.reverse_proxy && ['custom', 'ooba', 'koboldcpp', 'vllm'].includes(request.body.api) === false) {
console.warn('No key found for API', request.body.api); console.warn('No key found for API', request.body.api);
return response.sendStatus(400); return response.sendStatus(400);
@ -134,6 +138,10 @@ router.post('/caption-image', async (request, response) => {
apiUrl = 'https://api.cohere.ai/v2/chat'; apiUrl = 'https://api.cohere.ai/v2/chat';
} }
if (request.body.api === 'xai') {
apiUrl = 'https://api.x.ai/v1/chat/completions';
}
if (request.body.api === 'ooba') { if (request.body.api === 'ooba') {
apiUrl = `${trimV1(request.body.server_url)}/v1/chat/completions`; apiUrl = `${trimV1(request.body.server_url)}/v1/chat/completions`;
const imgMessage = body.messages.pop(); const imgMessage = body.messages.pop();