diff --git a/public/index.html b/public/index.html index d81d6ef45..cb706453e 100644 --- a/public/index.html +++ b/public/index.html @@ -2144,6 +2144,15 @@ LostRuins/koboldcpp +

koboldcpp API key (optional)

+
+ + +
+
+ For privacy reasons, your API key will be hidden after you reload the page. +

API URL

Example: http://127.0.0.1:5001 diff --git a/public/script.js b/public/script.js index 3a686e9c1..202e4f2de 100644 --- a/public/script.js +++ b/public/script.js @@ -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(); diff --git a/public/scripts/secrets.js b/public/scripts/secrets.js index 7c587d876..9ba9dcedd 100644 --- a/public/scripts/secrets.js +++ b/public/scripts/secrets.js @@ -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() { diff --git a/src/additional-headers.js b/src/additional-headers.js index 60933c4d6..e7480f03e 100644 --- a/src/additional-headers.js +++ b/src/additional-headers.js @@ -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; diff --git a/src/endpoints/secrets.js b/src/endpoints/secrets.js index a68181936..10ba9e556 100644 --- a/src/endpoints/secrets.js +++ b/src/endpoints/secrets.js @@ -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