Vector Storage: change NomicAI key input

d0b368f29cc4f11b3c2dd4d6c2a896f0b70f42de

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +30 -16Showing whitespace changes
public/scripts/extensions/vectors/index.js+25 -7
@@ -30,6 +30,7 @@ import { textgen_types, textgenerationwebui_settings } from '../../textgen-setti
3030import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
3131import { SlashCommand } from '../../slash-commands/SlashCommand.js';
3232import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
33+import { callGenericPopup, POPUP_RESULT, POPUP_TYPE } from '../../popup.js';
3334
3435const MODULE_NAME = 'vectors';
3536
@@ -1299,11 +1300,30 @@ jQuery(async () => {
12991300 saveSettingsDebounced();
13001301 toggleSettings();
13011302 });
13021303 $('#api_key_nomicai').on('changeclick', async () => {
1303- const nomicKey = String($('#api_key_nomicai').val()).trim();
1304+ const popupText = 'NomicAI API Key:';
1304- if (nomicKey.length) {
1305+ const key = await callGenericPopup(popupText, POPUP_TYPE.INPUT, '', {
1305- writeSecret(SECRET_KEYS.NOMICAI, nomicKey);
1306+ customButtons: [{
1307+ text: 'Remove Key',
1308+ appendAtEnd: true,
1309+ result: POPUP_RESULT.NEGATIVE,
1310+ action: async () => {
1311+ await writeSecret(SECRET_KEYS.NOMICAI, '');
1312+ toastr.success('API Key removed');
1313+ $('#api_key_nomicai').toggleClass('success', !!secret_state[SECRET_KEYS.NOMICAI]);
1314+ saveSettingsDebounced();
1315+ },
1316+ }],
1317+ });
1318+
1319+ if (!key) {
1320+ return;
13061321 }
1322+
1323+ await writeSecret(SECRET_KEYS.NOMICAI, String(key));
1324+ $('#api_key_nomicai').toggleClass('success', !!secret_state[SECRET_KEYS.NOMICAI]);
1325+
1326+ toastr.success('API Key saved');
13071327 saveSettingsDebounced();
13081328 });
13091329 $('#vectors_togetherai_model').val(settings.togetherai_model).on('change', () => {
@@ -1531,9 +1551,7 @@ jQuery(async () => {
15311551 $('#dialogue_popup_input').val(presetModel);
15321552 });
15331553
15341554 const validSecret =$('#api_key_nomicai').toggleClass('success', !!secret_state[SECRET_KEYS.NOMICAI]);
1535- const placeholder = validSecret ? '✔️ Key saved' : '❌ Missing key';
1536- $('#api_key_nomicai').attr('placeholder', placeholder);
15371555
15381556 toggleSettings();
15391557 eventSource.on(event_types.MESSAGE_DELETED, onChatEvent);
public/scripts/extensions/vectors/settings.html+5 -9
@@ -103,17 +103,13 @@
103103 </span>
104104 </small>
105105
106106 <div class="flex-container flexFlowColumnalignItemsCenter" id="nomicai_apiKey">
107107 <label for="api_key_nomicai" class="flex1">
108108 <span data-i18n="NomicAI API Key">NomicAI API Key</span>
109109 </label>
110110 <div id="api_key_nomicai" class="flex-containermenu_button menu_button_icon">
111- <input id="api_key_nomicai" name="api_key_nomicai" class="text_pole flex1 wide100p" maxlength="500" size="35" type="text" autocomplete="off">
111+ <i class="fa-solid fa-key"></i>
112- <div title="Clear your API key" class="menu_button fa-solid fa-circle-xmark clear-api-key" data-key="api_key_nomicai">
112+ <span data-i18n="Click to set">Click to set</span>
113- </div>
114- </div>
115- <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.">
116- For privacy reasons, your API key will be hidden after you reload the page.
117113 </div>
118114 </div>
119115