#1991 Add API key for llama.cpp
This commit is contained in:
parent
4d0cef7516
commit
a96bb40505
|
@ -2151,6 +2151,15 @@
|
|||
ggerganov/llama.cpp (inference server)
|
||||
</a>
|
||||
</div>
|
||||
<h4 data-i18n="API key (optional)">API key (optional)</h4>
|
||||
<div class="flex-container">
|
||||
<input id="api_key_llamacpp" name="api_key_llamacpp" 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_llamacpp">
|
||||
</div>
|
||||
</div>
|
||||
<div data-for="api_key_llamacpp" 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:8080">Example: http://127.0.0.1:8080</small>
|
||||
|
|
|
@ -8991,6 +8991,7 @@ jQuery(async function () {
|
|||
{ 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 },
|
||||
{ id: 'api_key_llamacpp', secret: SECRET_KEYS.LLAMACPP },
|
||||
];
|
||||
|
||||
for (const key of keys) {
|
||||
|
|
|
@ -22,6 +22,7 @@ export const SECRET_KEYS = {
|
|||
OOBA: 'api_key_ooba',
|
||||
NOMICAI: 'api_key_nomicai',
|
||||
KOBOLDCPP: 'api_key_koboldcpp',
|
||||
LLAMACPP: 'api_key_llamacpp',
|
||||
};
|
||||
|
||||
const INPUT_MAP = {
|
||||
|
@ -45,6 +46,7 @@ const INPUT_MAP = {
|
|||
[SECRET_KEYS.DREAMGEN]: '#api_key_dreamgen',
|
||||
[SECRET_KEYS.NOMICAI]: '#api_key_nomicai',
|
||||
[SECRET_KEYS.KOBOLDCPP]: '#api_key_koboldcpp',
|
||||
[SECRET_KEYS.LLAMACPP]: '#api_key_llamacpp',
|
||||
};
|
||||
|
||||
async function clearSecret() {
|
||||
|
|
|
@ -60,6 +60,14 @@ function getTabbyHeaders() {
|
|||
}) : {};
|
||||
}
|
||||
|
||||
function getLlamaCppHeaders() {
|
||||
const apiKey = readSecret(SECRET_KEYS.LLAMACPP);
|
||||
|
||||
return apiKey ? ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
}) : {};
|
||||
}
|
||||
|
||||
function getOobaHeaders() {
|
||||
const apiKey = readSecret(SECRET_KEYS.OOBA);
|
||||
|
||||
|
@ -93,40 +101,21 @@ function getOverrideHeaders(urlHost) {
|
|||
* @param {string|null} server API server for new request
|
||||
*/
|
||||
function setAdditionalHeaders(request, args, server) {
|
||||
let headers;
|
||||
const headerGetters = {
|
||||
[TEXTGEN_TYPES.MANCER]: getMancerHeaders,
|
||||
[TEXTGEN_TYPES.APHRODITE]: getAphroditeHeaders,
|
||||
[TEXTGEN_TYPES.TABBY]: getTabbyHeaders,
|
||||
[TEXTGEN_TYPES.TOGETHERAI]: getTogetherAIHeaders,
|
||||
[TEXTGEN_TYPES.OOBA]: getOobaHeaders,
|
||||
[TEXTGEN_TYPES.INFERMATICAI]: getInfermaticAIHeaders,
|
||||
[TEXTGEN_TYPES.DREAMGEN]: getDreamGenHeaders,
|
||||
[TEXTGEN_TYPES.OPENROUTER]: getOpenRouterHeaders,
|
||||
[TEXTGEN_TYPES.KOBOLDCPP]: getKoboldCppHeaders,
|
||||
[TEXTGEN_TYPES.LLAMACPP]: getLlamaCppHeaders,
|
||||
};
|
||||
|
||||
switch (request.body.api_type) {
|
||||
case TEXTGEN_TYPES.MANCER:
|
||||
headers = getMancerHeaders();
|
||||
break;
|
||||
case TEXTGEN_TYPES.APHRODITE:
|
||||
headers = getAphroditeHeaders();
|
||||
break;
|
||||
case TEXTGEN_TYPES.TABBY:
|
||||
headers = getTabbyHeaders();
|
||||
break;
|
||||
case TEXTGEN_TYPES.TOGETHERAI:
|
||||
headers = getTogetherAIHeaders();
|
||||
break;
|
||||
case TEXTGEN_TYPES.OOBA:
|
||||
headers = getOobaHeaders();
|
||||
break;
|
||||
case TEXTGEN_TYPES.INFERMATICAI:
|
||||
headers = getInfermaticAIHeaders();
|
||||
break;
|
||||
case TEXTGEN_TYPES.DREAMGEN:
|
||||
headers = getDreamGenHeaders();
|
||||
break;
|
||||
case TEXTGEN_TYPES.OPENROUTER:
|
||||
headers = getOpenRouterHeaders();
|
||||
break;
|
||||
case TEXTGEN_TYPES.KOBOLDCPP:
|
||||
headers = getKoboldCppHeaders();
|
||||
break;
|
||||
default:
|
||||
headers = {};
|
||||
break;
|
||||
}
|
||||
const getHeaders = headerGetters[request.body.api_type];
|
||||
const headers = getHeaders ? getHeaders() : {};
|
||||
|
||||
if (typeof server === 'string' && server.length > 0) {
|
||||
try {
|
||||
|
|
|
@ -34,6 +34,7 @@ const SECRET_KEYS = {
|
|||
DREAMGEN: 'api_key_dreamgen',
|
||||
NOMICAI: 'api_key_nomicai',
|
||||
KOBOLDCPP: 'api_key_koboldcpp',
|
||||
LLAMACPP: 'api_key_llamacpp',
|
||||
};
|
||||
|
||||
// These are the keys that are safe to expose, even if allowKeysExposure is false
|
||||
|
|
Loading…
Reference in New Issue