Caption: Add custom model input field (#4956)
Signed| @@ -699,6 +699,10 @@ jQuery(async function () { | ||
| 699 | 699 | extension_settings.caption.ollama_custom_model = String($('#caption_ollama_custom_model').val()).trim(); |
| 700 | 700 | saveSettingsDebounced(); |
| 701 | 701 | }); |
| 702 | + $('#caption_custom_model').val(extension_settings.caption.custom_model || '').on('input', () => { | |
| 703 | + extension_settings.caption.custom_model = String($('#caption_custom_model').val()).trim(); | |
| 704 | + saveSettingsDebounced(); | |
| 705 | + }); | |
| 702 | 706 | $('#caption_refresh_models').on('click', async () => { |
| 703 | 707 | extension_settings.caption.multimodal_model = ''; |
| 704 | 708 | await switchMultimodalBlocks(); |
| @@ -177,8 +177,16 @@ | ||
| 177 | 177 | <option data-type="koboldcpp" value="koboldcpp_current" data-i18n="currently_loaded">[Currently loaded]</option> |
| 178 | 178 | <option data-type="vllm" value="vllm_current" data-i18n="currently_selected">[Currently selected]</option> |
| 179 | 179 | <option data-type="custom" value="custom_current" data-i18n="currently_selected">[Currently selected]</option> |
| 180 | + <option data-type="custom" value="custom_custom" data-i18n="[Custom model]">[Custom model]</option> | |
| 180 | 181 | </select> |
| 181 | 182 | </div> |
| 183 | + <div data-type="custom"> | |
| 184 | + <label for="caption_custom_model"> | |
| 185 | + <span data-i18n="Model Id">Model Id</span> | |
| 186 | + <small data-i18n="(for [Custom model] option)">(for [Custom model] option)</small> | |
| 187 | + </label> | |
| 188 | + <input id="caption_custom_model" class="text_pole" type="text" placeholder="e.g. gpt-4o" /> | |
| 189 | + </div> | |
| 182 | 190 | <div data-type="ollama"> |
| 183 | 191 | <div> |
| 184 | 192 | 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>. |
| @@ -108,8 +108,15 @@ export async function getMultimodalCaption(base64Img, prompt) { | ||
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | if (isCustom) { |
| 111 | + if (extension_settings.caption.multimodal_model === 'custom_current') { | |
| 112 | + requestBody.model = oai_settings.custom_model || ''; | |
| 113 | + } | |
| 114 | + | |
| 115 | + if (extension_settings.caption.multimodal_model === 'custom_custom') { | |
| 116 | + requestBody.model = extension_settings.caption.custom_model || ''; | |
| 117 | + } | |
| 118 | + | |
| 111 | 119 | requestBody.server_url = oai_settings.custom_url; |
| 112 | - requestBody.model = oai_settings.custom_model || 'gpt-4-turbo'; | |
| 113 | 120 | requestBody.custom_include_headers = oai_settings.custom_include_headers; |
| 114 | 121 | requestBody.custom_include_body = oai_settings.custom_include_body; |
| 115 | 122 | requestBody.custom_exclude_body = oai_settings.custom_exclude_body; |
| @@ -245,6 +252,10 @@ function throwIfInvalidModel(useReverseProxy) { | ||
| 245 | 252 | throw new Error('Custom API URL is not set.'); |
| 246 | 253 | } |
| 247 | 254 | |
| 255 | + if (multimodalApi === 'custom' && multimodalModel === 'custom_custom' && !extension_settings.caption.custom_model) { | |
| 256 | + throw new Error('Custom OpenAI-compatible Model ID is not set.'); | |
| 257 | + } | |
| 258 | + | |
| 248 | 259 | if (multimodalApi === 'aimlapi' && !secret_state[SECRET_KEYS.AIMLAPI]) { |
| 249 | 260 | throw new Error('AI/ML API key is not set.'); |
| 250 | 261 | } |