mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Added option to use secondary API URL in vector extension
This commit is contained in:
@ -55,6 +55,8 @@ const getBatchSize = () => ['transformers', 'palm', 'ollama'].includes(settings.
|
|||||||
const settings = {
|
const settings = {
|
||||||
// For both
|
// For both
|
||||||
source: 'transformers',
|
source: 'transformers',
|
||||||
|
alt_endpoint_url: '',
|
||||||
|
use_alt_endpoint: false,
|
||||||
include_wi: false,
|
include_wi: false,
|
||||||
togetherai_model: 'togethercomputer/m2-bert-80M-32k-retrieval',
|
togetherai_model: 'togethercomputer/m2-bert-80M-32k-retrieval',
|
||||||
openai_model: 'text-embedding-ada-002',
|
openai_model: 'text-embedding-ada-002',
|
||||||
@ -109,6 +111,7 @@ const settings = {
|
|||||||
const moduleWorker = new ModuleWorkerWrapper(synchronizeChat);
|
const moduleWorker = new ModuleWorkerWrapper(synchronizeChat);
|
||||||
const webllmProvider = new WebLlmVectorProvider();
|
const webllmProvider = new WebLlmVectorProvider();
|
||||||
const cachedSummaries = new Map();
|
const cachedSummaries = new Map();
|
||||||
|
const vector_api_requires_url = ['llamacpp', 'vllm', 'ollama', 'koboldcpp'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Collection ID for a file embedded in the chat.
|
* Gets the Collection ID for a file embedded in the chat.
|
||||||
@ -777,14 +780,14 @@ function getVectorsRequestBody(args = {}) {
|
|||||||
break;
|
break;
|
||||||
case 'ollama':
|
case 'ollama':
|
||||||
body.model = extension_settings.vectors.ollama_model;
|
body.model = extension_settings.vectors.ollama_model;
|
||||||
body.apiUrl = textgenerationwebui_settings.server_urls[textgen_types.OLLAMA];
|
body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.OLLAMA];
|
||||||
body.keep = !!extension_settings.vectors.ollama_keep;
|
body.keep = !!extension_settings.vectors.ollama_keep;
|
||||||
break;
|
break;
|
||||||
case 'llamacpp':
|
case 'llamacpp':
|
||||||
body.apiUrl = textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP];
|
body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP];
|
||||||
break;
|
break;
|
||||||
case 'vllm':
|
case 'vllm':
|
||||||
body.apiUrl = textgenerationwebui_settings.server_urls[textgen_types.VLLM];
|
body.apiUrl = settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.VLLM];
|
||||||
body.model = extension_settings.vectors.vllm_model;
|
body.model = extension_settings.vectors.vllm_model;
|
||||||
break;
|
break;
|
||||||
case 'webllm':
|
case 'webllm':
|
||||||
@ -1087,6 +1090,7 @@ function toggleSettings() {
|
|||||||
$('#webllm_vectorsModel').toggle(settings.source === 'webllm');
|
$('#webllm_vectorsModel').toggle(settings.source === 'webllm');
|
||||||
$('#koboldcpp_vectorsModel').toggle(settings.source === 'koboldcpp');
|
$('#koboldcpp_vectorsModel').toggle(settings.source === 'koboldcpp');
|
||||||
$('#google_vectorsModel').toggle(settings.source === 'palm');
|
$('#google_vectorsModel').toggle(settings.source === 'palm');
|
||||||
|
$('#altEndpointUrl').toggle(vector_api_requires_url.includes(settings.source));
|
||||||
if (settings.source === 'webllm') {
|
if (settings.source === 'webllm') {
|
||||||
loadWebLlmModels();
|
loadWebLlmModels();
|
||||||
}
|
}
|
||||||
@ -1165,7 +1169,7 @@ async function createKoboldCppEmbeddings(items) {
|
|||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
items: items,
|
items: items,
|
||||||
server: textgenerationwebui_settings.server_urls[textgen_types.KOBOLDCPP],
|
server: settings.use_alt_endpoint ? settings.alt_endpoint_url : textgenerationwebui_settings.server_urls[textgen_types.KOBOLDCPP],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1467,6 +1471,16 @@ jQuery(async () => {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
toggleSettings();
|
toggleSettings();
|
||||||
});
|
});
|
||||||
|
$('#altEndpointUrl_enabled').prop('checked', settings.use_alt_endpoint).on('input', () => {
|
||||||
|
settings.use_alt_endpoint = $('#altEndpointUrl_enabled').prop('checked');
|
||||||
|
Object.assign(extension_settings.vectors, settings);
|
||||||
|
saveSettingsDebounced();
|
||||||
|
})
|
||||||
|
$('#altEndpoint_address').val(settings.alt_endpoint_url).on('change', () => {
|
||||||
|
settings.alt_endpoint_url = String($('#altEndpoint_address').val());
|
||||||
|
Object.assign(extension_settings.vectors, settings);
|
||||||
|
saveSettingsDebounced();
|
||||||
|
})
|
||||||
$('#api_key_nomicai').on('click', async () => {
|
$('#api_key_nomicai').on('click', async () => {
|
||||||
const popupText = 'NomicAI API Key:';
|
const popupText = 'NomicAI API Key:';
|
||||||
const key = await callGenericPopup(popupText, POPUP_TYPE.INPUT, '', {
|
const key = await callGenericPopup(popupText, POPUP_TYPE.INPUT, '', {
|
||||||
|
@ -25,6 +25,16 @@
|
|||||||
<option value="webllm" data-i18n="WebLLM Extension">WebLLM Extension</option>
|
<option value="webllm" data-i18n="WebLLM Extension">WebLLM Extension</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex-container flexFlowColumn" id="altEndpointUrl">
|
||||||
|
<label class="checkbox_label" for="altEndpointUrl_enabled" title="Enable secondary endpoint URL usage, instead of the main one.">
|
||||||
|
<input id="altEndpointUrl_enabled" type="checkbox" class="checkbox">
|
||||||
|
<span data-i18n="Use secondary URL">Use secondary URL</span>
|
||||||
|
</label>
|
||||||
|
<label for="altEndpoint_address" data-i18n="Secondary Embedding endpoint URL">
|
||||||
|
Secondary Embedding endpoint URL
|
||||||
|
</label>
|
||||||
|
<input id="altEndpoint_address" class="text_pole" type="text" placeholder="URL for secondary endpoint" />
|
||||||
|
</div>
|
||||||
<div class="flex-container flexFlowColumn" id="webllm_vectorsModel">
|
<div class="flex-container flexFlowColumn" id="webllm_vectorsModel">
|
||||||
<label for="vectors_webllm_model" data-i18n="Vectorization Model">
|
<label for="vectors_webllm_model" data-i18n="Vectorization Model">
|
||||||
Vectorization Model
|
Vectorization Model
|
||||||
|
Reference in New Issue
Block a user