Vector Storage: change NomicAI key input

This commit is contained in:
Cohee 2024-08-13 20:50:41 +03:00
parent 1842a8ee6d
commit d0b368f29c
2 changed files with 30 additions and 16 deletions

View File

@ -30,6 +30,7 @@ import { textgen_types, textgenerationwebui_settings } from '../../textgen-setti
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
import { callGenericPopup, POPUP_RESULT, POPUP_TYPE } from '../../popup.js';
const MODULE_NAME = 'vectors';
@ -1299,11 +1300,30 @@ jQuery(async () => {
saveSettingsDebounced();
toggleSettings();
});
$('#api_key_nomicai').on('change', () => {
const nomicKey = String($('#api_key_nomicai').val()).trim();
if (nomicKey.length) {
writeSecret(SECRET_KEYS.NOMICAI, nomicKey);
$('#api_key_nomicai').on('click', async () => {
const popupText = 'NomicAI API Key:';
const key = await callGenericPopup(popupText, POPUP_TYPE.INPUT, '', {
customButtons: [{
text: 'Remove Key',
appendAtEnd: true,
result: POPUP_RESULT.NEGATIVE,
action: async () => {
await writeSecret(SECRET_KEYS.NOMICAI, '');
toastr.success('API Key removed');
$('#api_key_nomicai').toggleClass('success', !!secret_state[SECRET_KEYS.NOMICAI]);
saveSettingsDebounced();
},
}],
});
if (!key) {
return;
}
await writeSecret(SECRET_KEYS.NOMICAI, String(key));
$('#api_key_nomicai').toggleClass('success', !!secret_state[SECRET_KEYS.NOMICAI]);
toastr.success('API Key saved');
saveSettingsDebounced();
});
$('#vectors_togetherai_model').val(settings.togetherai_model).on('change', () => {
@ -1531,9 +1551,7 @@ jQuery(async () => {
$('#dialogue_popup_input').val(presetModel);
});
const validSecret = !!secret_state[SECRET_KEYS.NOMICAI];
const placeholder = validSecret ? '✔️ Key saved' : '❌ Missing key';
$('#api_key_nomicai').attr('placeholder', placeholder);
$('#api_key_nomicai').toggleClass('success', !!secret_state[SECRET_KEYS.NOMICAI]);
toggleSettings();
eventSource.on(event_types.MESSAGE_DELETED, onChatEvent);

View File

@ -103,17 +103,13 @@
</span>
</small>
<div class="flex-container flexFlowColumn" id="nomicai_apiKey">
<label for="api_key_nomicai">
<div class="flex-container alignItemsCenter" id="nomicai_apiKey">
<label for="api_key_nomicai" class="flex1">
<span data-i18n="NomicAI API Key">NomicAI API Key</span>
</label>
<div class="flex-container">
<input id="api_key_nomicai" name="api_key_nomicai" class="text_pole flex1 wide100p" maxlength="500" size="35" type="text" autocomplete="off">
<div title="Clear your API key" class="menu_button fa-solid fa-circle-xmark clear-api-key" data-key="api_key_nomicai">
</div>
</div>
<div data-for="api_key_nomicai" class="neutral_warning" data-i18n="For privacy reasons, your API key will be hidden after you reload the page.">
For privacy reasons, your API key will be hidden after you reload the page.
<div id="api_key_nomicai" class="menu_button menu_button_icon">
<i class="fa-solid fa-key"></i>
<span data-i18n="Click to set">Click to set</span>
</div>
</div>