Added option to use secondary API URL in vector extension
| @@ -55,6 +55,8 @@ const getBatchSize = () => ['transformers', 'palm', 'ollama'].includes(settings. | ||
| 55 | 55 | const settings = { |
| 56 | 56 | // For both |
| 57 | 57 | source: 'transformers', |
| 58 | + alt_endpoint_url: '', | |
| 59 | + use_alt_endpoint: false, | |
| 58 | 60 | include_wi: false, |
| 59 | 61 | togetherai_model: 'togethercomputer/m2-bert-80M-32k-retrieval', |
| 60 | 62 | openai_model: 'text-embedding-ada-002', |
| @@ -109,6 +111,7 @@ const settings = { | ||
| 109 | 111 | const moduleWorker = new ModuleWorkerWrapper(synchronizeChat); |
| 110 | 112 | const webllmProvider = new WebLlmVectorProvider(); |
| 111 | 113 | const cachedSummaries = new Map(); |
| 114 | +const vector_api_requires_url = ['llamacpp', 'vllm', 'ollama', 'koboldcpp']; | |
| 112 | 115 | |
| 113 | 116 | /** |
| 114 | 117 | * Gets the Collection ID for a file embedded in the chat. |
| @@ -777,14 +780,14 @@ function getVectorsRequestBody(args = {}) { | ||
| 777 | 780 | break; |
| 778 | 781 | case 'ollama': |
| 779 | 782 | body.model = extension_settings.vectors.ollama_model; |
| 780 | 783 | body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.OLLAMA]; |
| 781 | 784 | body.keep = !!extension_settings.vectors.ollama_keep; |
| 782 | 785 | break; |
| 783 | 786 | case 'llamacpp': |
| 784 | 787 | body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP]; |
| 785 | 788 | break; |
| 786 | 789 | case 'vllm': |
| 787 | 790 | body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.VLLM]; |
| 788 | 791 | body.model = extension_settings.vectors.vllm_model; |
| 789 | 792 | break; |
| 790 | 793 | case 'webllm': |
| @@ -1087,6 +1090,7 @@ function toggleSettings() { | ||
| 1087 | 1090 | $('#webllm_vectorsModel').toggle(settings.source === 'webllm'); |
| 1088 | 1091 | $('#koboldcpp_vectorsModel').toggle(settings.source === 'koboldcpp'); |
| 1089 | 1092 | $('#google_vectorsModel').toggle(settings.source === 'palm'); |
| 1093 | + $('#altEndpointUrl').toggle(vector_api_requires_url.includes(settings.source)); | |
| 1090 | 1094 | if (settings.source === 'webllm') { |
| 1091 | 1095 | loadWebLlmModels(); |
| 1092 | 1096 | } |
| @@ -1165,7 +1169,7 @@ async function createKoboldCppEmbeddings(items) { | ||
| 1165 | 1169 | headers: getRequestHeaders(), |
| 1166 | 1170 | body: JSON.stringify({ |
| 1167 | 1171 | items: items, |
| 1168 | 1172 | server: settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.KOBOLDCPP], |
| 1169 | 1173 | }), |
| 1170 | 1174 | }); |
| 1171 | 1175 | |
| @@ -1467,6 +1471,16 @@ jQuery(async () => { | ||
| 1467 | 1471 | saveSettingsDebounced(); |
| 1468 | 1472 | toggleSettings(); |
| 1469 | 1473 | }); |
| 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 | + }) | |
| 1470 | 1484 | $('#api_key_nomicai').on('click', async () => { |
| 1471 | 1485 | const popupText = 'NomicAI API Key:'; |
| 1472 | 1486 | const key = await callGenericPopup(popupText, POPUP_TYPE.INPUT, '', { |
| @@ -25,6 +25,16 @@ | ||
| 25 | 25 | <option value="webllm" data-i18n="WebLLM Extension">WebLLM Extension</option> |
| 26 | 26 | </select> |
| 27 | 27 | </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> | |
| 28 | 38 | <div class="flex-container flexFlowColumn" id="webllm_vectorsModel"> |
| 29 | 39 | <label for="vectors_webllm_model" data-i18n="Vectorization Model"> |
| 30 | 40 | Vectorization Model |