Added option to use secondary API URL in vector extension

5cf3198da13f158aed20f13ba9a0b0ed5b78b6ea

pl752 <maximpl752@gmail.com>

2 files changed, +28 -4Showing whitespace changes
public/scripts/extensions/vectors/index.js+18 -4
@@ -55,6 +55,8 @@ const getBatchSize = () => ['transformers', 'palm', 'ollama'].includes(settings.
5555const settings = {
5656 // For both
5757 source: 'transformers',
58+ alt_endpoint_url: '',
59+ use_alt_endpoint: false,
5860 include_wi: false,
5961 togetherai_model: 'togethercomputer/m2-bert-80M-32k-retrieval',
6062 openai_model: 'text-embedding-ada-002',
@@ -109,6 +111,7 @@ const settings = {
109111const moduleWorker = new ModuleWorkerWrapper(synchronizeChat);
110112const webllmProvider = new WebLlmVectorProvider();
111113const cachedSummaries = new Map();
114+const vector_api_requires_url = ['llamacpp', 'vllm', 'ollama', 'koboldcpp'];
112115
113116/**
114117 * Gets the Collection ID for a file embedded in the chat.
@@ -777,14 +780,14 @@ function getVectorsRequestBody(args = {}) {
777780 break;
778781 case 'ollama':
779782 body.model = extension_settings.vectors.ollama_model;
780783 body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.OLLAMA];
781784 body.keep = !!extension_settings.vectors.ollama_keep;
782785 break;
783786 case 'llamacpp':
784787 body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP];
785788 break;
786789 case 'vllm':
787790 body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.VLLM];
788791 body.model = extension_settings.vectors.vllm_model;
789792 break;
790793 case 'webllm':
@@ -1087,6 +1090,7 @@ function toggleSettings() {
10871090 $('#webllm_vectorsModel').toggle(settings.source === 'webllm');
10881091 $('#koboldcpp_vectorsModel').toggle(settings.source === 'koboldcpp');
10891092 $('#google_vectorsModel').toggle(settings.source === 'palm');
1093+ $('#altEndpointUrl').toggle(vector_api_requires_url.includes(settings.source));
10901094 if (settings.source === 'webllm') {
10911095 loadWebLlmModels();
10921096 }
@@ -1165,7 +1169,7 @@ async function createKoboldCppEmbeddings(items) {
11651169 headers: getRequestHeaders(),
11661170 body: JSON.stringify({
11671171 items: items,
11681172 server: settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.KOBOLDCPP],
11691173 }),
11701174 });
11711175
@@ -1467,6 +1471,16 @@ jQuery(async () => {
14671471 saveSettingsDebounced();
14681472 toggleSettings();
14691473 });
1474+ $('#altEndpointUrl_enabled').prop('checked', settings.use_alt_endpoint).on('input', () => {
1475+ settings.use_alt_endpoint = $('#altEndpointUrl_enabled').prop('checked');
1476+ Object.assign(extension_settings.vectors, settings);
1477+ saveSettingsDebounced();
1478+ })
1479+ $('#altEndpoint_address').val(settings.alt_endpoint_url).on('change', () => {
1480+ settings.alt_endpoint_url = String($('#altEndpoint_address').val());
1481+ Object.assign(extension_settings.vectors, settings);
1482+ saveSettingsDebounced();
1483+ })
14701484 $('#api_key_nomicai').on('click', async () => {
14711485 const popupText = 'NomicAI API Key:';
14721486 const key = await callGenericPopup(popupText, POPUP_TYPE.INPUT, '', {
public/scripts/extensions/vectors/settings.html+10 -0
@@ -25,6 +25,16 @@
2525 <option value="webllm" data-i18n="WebLLM Extension">WebLLM Extension</option>
2626 </select>
2727 </div>
28+ <div class="flex-container flexFlowColumn" id="altEndpointUrl">
29+ <label class="checkbox_label" for="altEndpointUrl_enabled" title="Enable secondary endpoint URL usage, instead of the main one.">
30+ <input id="altEndpointUrl_enabled" type="checkbox" class="checkbox">
31+ <span data-i18n="Use secondary URL">Use secondary URL</span>
32+ </label>
33+ <label for="altEndpoint_address" data-i18n="Secondary Embedding endpoint URL">
34+ Secondary Embedding endpoint URL
35+ </label>
36+ <input id="altEndpoint_address" class="text_pole" type="text" placeholder="URL for secondary endpoint" />
37+ </div>
2838 <div class="flex-container flexFlowColumn" id="webllm_vectorsModel">
2939 <label for="vectors_webllm_model" data-i18n="Vectorization Model">
3040 Vectorization Model