Add koboldcpp API key/password support

This commit is contained in:
Cohee 2024-03-14 00:34:09 +02:00
parent 46993384a3
commit acf36b6107
5 changed files with 39 additions and 37 deletions

View File

@ -2144,6 +2144,15 @@
LostRuins/koboldcpp
</a>
</div>
<h4 data-i18n="koboldcpp API key (optional)">koboldcpp API key (optional)</h4>
<div class="flex-container">
<input id="api_key_koboldcpp" name="api_key_koboldcpp" class="text_pole flex1 wide100p" maxlength="500" size="35" type="text" autocomplete="off">
<div title="Clear your API key" data-i18n="[title]Clear your API key" class="menu_button fa-solid fa-circle-xmark clear-api-key" data-key="api_key_koboldcpp">
</div>
</div>
<div data-for="api_key_koboldcpp" 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>
<div class="flex1">
<h4 data-i18n="API url">API URL</h4>
<small data-i18n="Example: 127.0.0.1:5001">Example: http://127.0.0.1:5001</small>

View File

@ -8727,44 +8727,23 @@ jQuery(async function () {
});
$('#api_button_textgenerationwebui').on('click', async function (e) {
const mancerKey = String($('#api_key_mancer').val()).trim();
if (mancerKey.length) {
await writeSecret(SECRET_KEYS.MANCER, mancerKey);
}
const keys = [
{ id: 'api_key_mancer', secret: SECRET_KEYS.MANCER },
{ id: 'api_key_aphrodite', secret: SECRET_KEYS.APHRODITE },
{ id: 'api_key_tabby', secret: SECRET_KEYS.TABBY },
{ id: 'api_key_togetherai', secret: SECRET_KEYS.TOGETHERAI },
{ id: 'api_key_ooba', secret: SECRET_KEYS.OOBA },
{ id: 'api_key_infermaticai', secret: SECRET_KEYS.INFERMATICAI },
{ id: 'api_key_dreamgen', secret: SECRET_KEYS.DREAMGEN },
{ id: 'api_key_openrouter-tg', secret: SECRET_KEYS.OPENROUTER },
{ id: 'api_key_koboldcpp', secret: SECRET_KEYS.KOBOLDCPP },
];
const aphroditeKey = String($('#api_key_aphrodite').val()).trim();
if (aphroditeKey.length) {
await writeSecret(SECRET_KEYS.APHRODITE, aphroditeKey);
}
const tabbyKey = String($('#api_key_tabby').val()).trim();
if (tabbyKey.length) {
await writeSecret(SECRET_KEYS.TABBY, tabbyKey);
}
const togetherKey = String($('#api_key_togetherai').val()).trim();
if (togetherKey.length) {
await writeSecret(SECRET_KEYS.TOGETHERAI, togetherKey);
}
const oobaKey = String($('#api_key_ooba').val()).trim();
if (oobaKey.length) {
await writeSecret(SECRET_KEYS.OOBA, oobaKey);
}
const infermaticAIKey = String($('#api_key_infermaticai').val()).trim();
if (infermaticAIKey.length) {
await writeSecret(SECRET_KEYS.INFERMATICAI, infermaticAIKey);
}
const dreamgenKey = String($('#api_key_dreamgen').val()).trim();
if (dreamgenKey.length) {
await writeSecret(SECRET_KEYS.DREAMGEN, dreamgenKey);
}
const openRouterKey = String($('#api_key_openrouter-tg').val()).trim();
if (openRouterKey.length) {
await writeSecret(SECRET_KEYS.OPENROUTER, openRouterKey);
for (const key of keys) {
const keyValue = String($(`#${key.id}`).val()).trim();
if (keyValue.length) {
await writeSecret(key.secret, keyValue);
}
}
validateTextGenUrl();

View File

@ -21,6 +21,7 @@ export const SECRET_KEYS = {
CUSTOM: 'api_key_custom',
OOBA: 'api_key_ooba',
NOMICAI: 'api_key_nomicai',
KOBOLDCPP: 'api_key_koboldcpp',
};
const INPUT_MAP = {
@ -43,6 +44,7 @@ const INPUT_MAP = {
[SECRET_KEYS.INFERMATICAI]: '#api_key_infermaticai',
[SECRET_KEYS.DREAMGEN]: '#api_key_dreamgen',
[SECRET_KEYS.NOMICAI]: '#api_key_nomicai',
[SECRET_KEYS.KOBOLDCPP]: '#api_key_koboldcpp',
};
async function clearSecret() {

View File

@ -68,6 +68,14 @@ function getOobaHeaders() {
}) : {};
}
function getKoboldCppHeaders() {
const apiKey = readSecret(SECRET_KEYS.KOBOLDCPP);
return apiKey ? ({
'Authorization': `Bearer ${apiKey}`,
}) : {};
}
function getOverrideHeaders(urlHost) {
const requestOverrides = getConfigValue('requestOverrides', []);
const overrideHeaders = requestOverrides?.find((e) => e.hosts?.includes(urlHost))?.headers;
@ -112,6 +120,9 @@ function setAdditionalHeaders(request, args, server) {
case TEXTGEN_TYPES.OPENROUTER:
headers = getOpenRouterHeaders();
break;
case TEXTGEN_TYPES.KOBOLDCPP:
headers = getKoboldCppHeaders();
break;
default:
headers = server ? getOverrideHeaders((new URL(server))?.host) : {};
break;

View File

@ -33,6 +33,7 @@ const SECRET_KEYS = {
INFERMATICAI: 'api_key_infermaticai',
DREAMGEN: 'api_key_dreamgen',
NOMICAI: 'api_key_nomicai',
KOBOLDCPP: 'api_key_koboldcpp',
};
// These are the keys that are safe to expose, even if allowKeysExposure is false