Merge pull request #3858 from pl752/staging Added option to use secondary API URL in vector extension
Signed| @@ -55,6 +55,8 @@ const getBatchSize = () => ['transformers', 'palm', 'ollama'].includes(settings. | |||
| 55 | const settings = { | 55 | const settings = { |
| 56 | // For both | 56 | // For both |
| 57 | source: 'transformers', | 57 | source: 'transformers', |
| 58 | alt_endpoint_url: '', | ||
| 59 | use_alt_endpoint: false, | ||
| 58 | include_wi: false, | 60 | include_wi: false, |
| 59 | togetherai_model: 'togethercomputer/m2-bert-80M-32k-retrieval', | 61 | togetherai_model: 'togethercomputer/m2-bert-80M-32k-retrieval', |
| 60 | openai_model: 'text-embedding-ada-002', | 62 | openai_model: 'text-embedding-ada-002', |
| @@ -109,6 +111,7 @@ const settings = { | |||
| 109 | const moduleWorker = new ModuleWorkerWrapper(synchronizeChat); | 111 | const moduleWorker = new ModuleWorkerWrapper(synchronizeChat); |
| 110 | const webllmProvider = new WebLlmVectorProvider(); | 112 | const webllmProvider = new WebLlmVectorProvider(); |
| 111 | const cachedSummaries = new Map(); | 113 | const cachedSummaries = new Map(); |
| 114 | const vectorApiRequiresUrl = ['llamacpp', 'vllm', 'ollama', 'koboldcpp']; | ||
| 112 | 115 | ||
| 113 | /** | 116 | /** |
| 114 | * Gets the Collection ID for a file embedded in the chat. | 117 | * Gets the Collection ID for a file embedded in the chat. |
| @@ -777,14 +780,14 @@ function getVectorsRequestBody(args = {}) { | |||
| 777 | break; | 780 | break; |
| 778 | case 'ollama': | 781 | case 'ollama': |
| 779 | body.model = extension_settings.vectors.ollama_model; | 782 | body.model = extension_settings.vectors.ollama_model; |
| 780 | body.apiUrl = textgenerationwebui_settings.server_urls[textgen_types.OLLAMA]; | 783 | body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.OLLAMA]; |
| 781 | body.keep = !!extension_settings.vectors.ollama_keep; | 784 | body.keep = !!extension_settings.vectors.ollama_keep; |
| 782 | break; | 785 | break; |
| 783 | case 'llamacpp': | 786 | case 'llamacpp': |
| 784 | body.apiUrl = textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP]; | 787 | body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP]; |
| 785 | break; | 788 | break; |
| 786 | case 'vllm': | 789 | case 'vllm': |
| 787 | body.apiUrl = textgenerationwebui_settings.server_urls[textgen_types.VLLM]; | 790 | body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.VLLM]; |
| 788 | body.model = extension_settings.vectors.vllm_model; | 791 | body.model = extension_settings.vectors.vllm_model; |
| 789 | break; | 792 | break; |
| 790 | case 'webllm': | 793 | case 'webllm': |
| @@ -883,12 +886,19 @@ function throwIfSourceInvalid() { | |||
| 883 | throw new Error('Vectors: API key missing', { cause: 'api_key_missing' }); | 886 | throw new Error('Vectors: API key missing', { cause: 'api_key_missing' }); |
| 884 | } | 887 | } |
| 885 | 888 | ||
| 889 | if (vectorApiRequiresUrl.includes(settings.source) && settings.use_alt_endpoint) { | ||
| 890 | if (!settings.alt_endpoint_url) { | ||
| 891 | throw new Error('Vectors: API URL missing', { cause: 'api_url_missing' }); | ||
| 892 | } | ||
| 893 | } | ||
| 894 | else { | ||
| 886 | if (settings.source === 'ollama' && !textgenerationwebui_settings.server_urls[textgen_types.OLLAMA] || | 895 | if (settings.source === 'ollama' && !textgenerationwebui_settings.server_urls[textgen_types.OLLAMA] || |
| 887 | settings.source === 'vllm' && !textgenerationwebui_settings.server_urls[textgen_types.VLLM] || | 896 | settings.source === 'vllm' && !textgenerationwebui_settings.server_urls[textgen_types.VLLM] || |
| 888 | settings.source === 'koboldcpp' && !textgenerationwebui_settings.server_urls[textgen_types.KOBOLDCPP] || | 897 | settings.source === 'koboldcpp' && !textgenerationwebui_settings.server_urls[textgen_types.KOBOLDCPP] || |
| 889 | settings.source === 'llamacpp' && !textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP]) { | 898 | settings.source === 'llamacpp' && !textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP]) { |
| 890 | throw new Error('Vectors: API URL missing', { cause: 'api_url_missing' }); | 899 | throw new Error('Vectors: API URL missing', { cause: 'api_url_missing' }); |
| 891 | } | 900 | } |
| 901 | } | ||
| 892 | 902 | ||
| 893 | if (settings.source === 'ollama' && !settings.ollama_model || settings.source === 'vllm' && !settings.vllm_model) { | 903 | if (settings.source === 'ollama' && !settings.ollama_model || settings.source === 'vllm' && !settings.vllm_model) { |
| 894 | throw new Error('Vectors: API model missing', { cause: 'api_model_missing' }); | 904 | throw new Error('Vectors: API model missing', { cause: 'api_model_missing' }); |
| @@ -1087,6 +1097,7 @@ function toggleSettings() { | |||
| 1087 | $('#webllm_vectorsModel').toggle(settings.source === 'webllm'); | 1097 | $('#webllm_vectorsModel').toggle(settings.source === 'webllm'); |
| 1088 | $('#koboldcpp_vectorsModel').toggle(settings.source === 'koboldcpp'); | 1098 | $('#koboldcpp_vectorsModel').toggle(settings.source === 'koboldcpp'); |
| 1089 | $('#google_vectorsModel').toggle(settings.source === 'palm'); | 1099 | $('#google_vectorsModel').toggle(settings.source === 'palm'); |
| 1100 | $('#vector_altEndpointUrl').toggle(vectorApiRequiresUrl.includes(settings.source)); | ||
| 1090 | if (settings.source === 'webllm') { | 1101 | if (settings.source === 'webllm') { |
| 1091 | loadWebLlmModels(); | 1102 | loadWebLlmModels(); |
| 1092 | } | 1103 | } |
| @@ -1165,7 +1176,7 @@ async function createKoboldCppEmbeddings(items) { | |||
| 1165 | headers: getRequestHeaders(), | 1176 | headers: getRequestHeaders(), |
| 1166 | body: JSON.stringify({ | 1177 | body: JSON.stringify({ |
| 1167 | items: items, | 1178 | items: items, |
| 1168 | server: textgenerationwebui_settings.server_urls[textgen_types.KOBOLDCPP], | 1179 | server: settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.KOBOLDCPP], |
| 1169 | }), | 1180 | }), |
| 1170 | }); | 1181 | }); |
| 1171 | 1182 | ||
| @@ -1467,6 +1478,16 @@ jQuery(async () => { | |||
| 1467 | saveSettingsDebounced(); | 1478 | saveSettingsDebounced(); |
| 1468 | toggleSettings(); | 1479 | toggleSettings(); |
| 1469 | }); | 1480 | }); |
| 1481 | $('#vector_altEndpointUrl_enabled').prop('checked', settings.use_alt_endpoint).on('input', () => { | ||
| 1482 | settings.use_alt_endpoint = $('#vector_altEndpointUrl_enabled').prop('checked'); | ||
| 1483 | Object.assign(extension_settings.vectors, settings); | ||
| 1484 | saveSettingsDebounced(); | ||
| 1485 | }); | ||
| 1486 | $('#vector_altEndpoint_address').val(settings.alt_endpoint_url).on('change', () => { | ||
| 1487 | settings.alt_endpoint_url = String($('#vector_altEndpoint_address').val()); | ||
| 1488 | Object.assign(extension_settings.vectors, settings); | ||
| 1489 | saveSettingsDebounced(); | ||
| 1490 | }); | ||
| 1470 | $('#api_key_nomicai').on('click', async () => { | 1491 | $('#api_key_nomicai').on('click', async () => { |
| 1471 | const popupText = 'NomicAI API Key:'; | 1492 | const popupText = 'NomicAI API Key:'; |
| 1472 | const key = await callGenericPopup(popupText, POPUP_TYPE.INPUT, '', { | 1493 | const key = await callGenericPopup(popupText, POPUP_TYPE.INPUT, '', { |
| @@ -25,6 +25,16 @@ | |||
| 25 | <option value="webllm" data-i18n="WebLLM Extension">WebLLM Extension</option> | 25 | <option value="webllm" data-i18n="WebLLM Extension">WebLLM Extension</option> |
| 26 | </select> | 26 | </select> |
| 27 | </div> | 27 | </div> |
| 28 | <div class="flex-container flexFlowColumn" id="vector_altEndpointUrl"> | ||
| 29 | <label class="checkbox_label" for="vector_altEndpointUrl_enabled" title="Enable secondary endpoint URL usage, instead of the main one."> | ||
| 30 | <input id="vector_altEndpointUrl_enabled" type="checkbox" class="checkbox"> | ||
| 31 | <span data-i18n="Use secondary URL">Use secondary URL</span> | ||
| 32 | </label> | ||
| 33 | <label for="vector_altEndpoint_address" data-i18n="Secondary Embedding endpoint URL"> | ||
| 34 | Secondary Embedding endpoint URL | ||
| 35 | </label> | ||
| 36 | <input id="vector_altEndpoint_address" class="text_pole" type="text" placeholder="e.g. http://localhost:5001" /> | ||
| 37 | </div> | ||
| 28 | <div class="flex-container flexFlowColumn" id="webllm_vectorsModel"> | 38 | <div class="flex-container flexFlowColumn" id="webllm_vectorsModel"> |
| 29 | <label for="vectors_webllm_model" data-i18n="Vectorization Model"> | 39 | <label for="vectors_webllm_model" data-i18n="Vectorization Model"> |
| 30 | Vectorization Model | 40 | Vectorization Model |