Added authentication variant to WebUI API.
This commit is contained in:
parent
aac7525204
commit
2fdec7eb03
|
@ -688,6 +688,7 @@ let is_get_status = false;
|
||||||
let is_get_status_novel = false;
|
let is_get_status_novel = false;
|
||||||
let is_api_button_press = false;
|
let is_api_button_press = false;
|
||||||
let is_api_button_press_novel = false;
|
let is_api_button_press_novel = false;
|
||||||
|
let api_use_mancer_webui = false;
|
||||||
|
|
||||||
let is_send_press = false; //Send generation
|
let is_send_press = false; //Send generation
|
||||||
let add_mes_without_animation = false;
|
let add_mes_without_animation = false;
|
||||||
|
@ -810,9 +811,9 @@ async function getStatus() {
|
||||||
type: "POST", //
|
type: "POST", //
|
||||||
url: "/getstatus", //
|
url: "/getstatus", //
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
api_server:
|
api_server: main_api == "kobold" ? api_server : api_server_textgenerationwebui,
|
||||||
main_api == "kobold" ? api_server : api_server_textgenerationwebui,
|
|
||||||
main_api: main_api,
|
main_api: main_api,
|
||||||
|
use_mancer: main_api == "textgenerationwebui" ? api_use_mancer_webui : false,
|
||||||
}),
|
}),
|
||||||
beforeSend: function () { },
|
beforeSend: function () { },
|
||||||
cache: false,
|
cache: false,
|
||||||
|
@ -2672,6 +2673,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
||||||
}
|
}
|
||||||
else if (main_api == 'textgenerationwebui') {
|
else if (main_api == 'textgenerationwebui') {
|
||||||
generate_data = getTextGenGenerationData(finalPromt, this_amount_gen, isImpersonate);
|
generate_data = getTextGenGenerationData(finalPromt, this_amount_gen, isImpersonate);
|
||||||
|
generate_data.use_mancer = api_use_mancer_webui;
|
||||||
}
|
}
|
||||||
else if (main_api == 'novel') {
|
else if (main_api == 'novel') {
|
||||||
const this_settings = novelai_settings[novelai_setting_names[nai_settings.preset_settings_novel]];
|
const this_settings = novelai_settings[novelai_setting_names[nai_settings.preset_settings_novel]];
|
||||||
|
@ -2933,6 +2935,14 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
||||||
activateSendButtons();
|
activateSendButtons();
|
||||||
//console.log('runGenerate calling showSwipeBtns');
|
//console.log('runGenerate calling showSwipeBtns');
|
||||||
showSwipeButtons();
|
showSwipeButtons();
|
||||||
|
|
||||||
|
if (main_api == 'textgenerationwebui' && api_use_mancer_webui) {
|
||||||
|
const errorText = `<h3>Inferencer endpoint is unhappy!</h3>
|
||||||
|
Check you have credits available on your
|
||||||
|
<a href="https://mancer.tech/dashboard.html" target="_blank">Mancer account</a>.<br>
|
||||||
|
If you have sufficient credits, please try again later.`;
|
||||||
|
callPopup(errorText, 'text');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.debug('/savechat called by /Generate');
|
console.debug('/savechat called by /Generate');
|
||||||
|
|
||||||
|
@ -5015,11 +5025,13 @@ async function getSettings(type) {
|
||||||
|
|
||||||
setWorldInfoSettings(settings, data);
|
setWorldInfoSettings(settings, data);
|
||||||
|
|
||||||
api_server_textgenerationwebui =
|
api_server_textgenerationwebui = settings.api_server_textgenerationwebui;
|
||||||
settings.api_server_textgenerationwebui;
|
|
||||||
$("#textgenerationwebui_api_url_text").val(
|
$("#textgenerationwebui_api_url_text").val(
|
||||||
api_server_textgenerationwebui
|
api_server_textgenerationwebui
|
||||||
);
|
);
|
||||||
|
api_use_mancer_webui = settings.api_use_mancer_webui
|
||||||
|
$('#use-mancer-api-checkbox').prop("checked", api_use_mancer_webui);
|
||||||
|
$('#use-mancer-api-checkbox').trigger("change");
|
||||||
|
|
||||||
selected_button = settings.selected_button;
|
selected_button = settings.selected_button;
|
||||||
|
|
||||||
|
@ -5051,6 +5063,7 @@ async function saveSettings(type) {
|
||||||
username: name1,
|
username: name1,
|
||||||
api_server: api_server,
|
api_server: api_server,
|
||||||
api_server_textgenerationwebui: api_server_textgenerationwebui,
|
api_server_textgenerationwebui: api_server_textgenerationwebui,
|
||||||
|
api_use_mancer_webui: api_use_mancer_webui,
|
||||||
preset_settings: preset_settings,
|
preset_settings: preset_settings,
|
||||||
user_avatar: user_avatar,
|
user_avatar: user_avatar,
|
||||||
amount_gen: amount_gen,
|
amount_gen: amount_gen,
|
||||||
|
@ -7611,16 +7624,28 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#use-mancer-api-checkbox").on("change", function (e) {
|
||||||
|
const enabled = $("#use-mancer-api-checkbox").prop("checked");
|
||||||
|
$("#mancer-api-ui").css("display", enabled?"block":"none");
|
||||||
|
api_use_mancer_webui = enabled;
|
||||||
|
saveSettingsDebounced();
|
||||||
|
getStatus();
|
||||||
|
});
|
||||||
|
|
||||||
$("#api_button_textgenerationwebui").click(function (e) {
|
$("#api_button_textgenerationwebui").click(function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if ($("#textgenerationwebui_api_url_text").val() != "") {
|
if ($("#textgenerationwebui_api_url_text").val() != "") {
|
||||||
let value = formatKoboldUrl($("#textgenerationwebui_api_url_text").val().trim());
|
let value = $("#textgenerationwebui_api_url_text").val().trim();
|
||||||
|
if (!value || !value.endsWith('/api')) {
|
||||||
if (!value) {
|
callPopup('Please enter a valid URL.<br/>WebUI URLs should end with <tt>/api</tt>', 'text');
|
||||||
callPopup('Please enter a valid URL.', 'text');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mancer_key = $("#api_key_mancer").val().trim();
|
||||||
|
if (mancer_key.length) {
|
||||||
|
writeSecret(SECRET_KEYS.MANCER, mancer_key);
|
||||||
|
}
|
||||||
|
|
||||||
$("#textgenerationwebui_api_url_text").val(value);
|
$("#textgenerationwebui_api_url_text").val(value);
|
||||||
$("#api_loading_textgenerationwebui").css("display", "inline-block");
|
$("#api_loading_textgenerationwebui").css("display", "inline-block");
|
||||||
$("#api_button_textgenerationwebui").css("display", "none");
|
$("#api_button_textgenerationwebui").css("display", "none");
|
||||||
|
|
29
server.js
29
server.js
|
@ -146,6 +146,14 @@ let response_getstatus;
|
||||||
let first_run = true;
|
let first_run = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function get_mancer_headers() {
|
||||||
|
const api_key_mancer = readSecret(SECRET_KEYS.MANCER);
|
||||||
|
return api_key_mancer ? { "X-API-KEY": api_key_mancer} : {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//RossAscends: Added function to format dates used in files and chat timestamps to a humanized format.
|
//RossAscends: Added function to format dates used in files and chat timestamps to a humanized format.
|
||||||
//Mostly I wanted this to be for file names, but couldn't figure out exactly where the filename save code was as everything seemed to be connected.
|
//Mostly I wanted this to be for file names, but couldn't figure out exactly where the filename save code was as everything seemed to be connected.
|
||||||
//During testing, this performs the same as previous date.now() structure.
|
//During testing, this performs the same as previous date.now() structure.
|
||||||
|
@ -621,17 +629,21 @@ app.post("/generate_textgenerationwebui", jsonParser, async function (request, r
|
||||||
else {
|
else {
|
||||||
const args = {
|
const args = {
|
||||||
body: JSON.stringify(request.body),
|
body: JSON.stringify(request.body),
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json"},
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (request.body.use_mancer) {
|
||||||
|
args.headers = Object.assign(args.headers, get_mancer_headers());
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await postAsync(api_server + "/v1/generate", args);
|
const data = await postAsync(api_server + "/v1/generate", args);
|
||||||
console.log(data);
|
console.log(data);
|
||||||
return response_generate.send(data);
|
return response_generate.send(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log("Error: %o", error);
|
||||||
return response_generate.send({ error: true });
|
return response_generate.send({ error: true});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -685,6 +697,7 @@ app.post("/getchat", jsonParser, function (request, response) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.post("/getstatus", jsonParser, async function (request, response_getstatus = response) {
|
app.post("/getstatus", jsonParser, async function (request, response_getstatus = response) {
|
||||||
if (!request.body) return response_getstatus.sendStatus(400);
|
if (!request.body) return response_getstatus.sendStatus(400);
|
||||||
api_server = request.body.api_server;
|
api_server = request.body.api_server;
|
||||||
|
@ -695,6 +708,11 @@ app.post("/getstatus", jsonParser, async function (request, response_getstatus =
|
||||||
var args = {
|
var args = {
|
||||||
headers: { "Content-Type": "application/json" }
|
headers: { "Content-Type": "application/json" }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (main_api == 'textgenerationwebui' && request.body.use_mancer) {
|
||||||
|
args.headers = Object.assign(args.headers, get_mancer_headers());
|
||||||
|
}
|
||||||
|
|
||||||
var url = api_server + "/v1/model";
|
var url = api_server + "/v1/model";
|
||||||
let version = '';
|
let version = '';
|
||||||
let koboldVersion = {};
|
let koboldVersion = {};
|
||||||
|
@ -3404,6 +3422,10 @@ app.post("/tokenize_via_api", jsonParser, async function (request, response) {
|
||||||
headers: { "Content-Type": "application/json" }
|
headers: { "Content-Type": "application/json" }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (main_api == 'textgenerationwebui' && request.body.use_mancer) {
|
||||||
|
args.headers = Object.assign(args.headers, get_mancer_headers());
|
||||||
|
}
|
||||||
|
|
||||||
const data = await postAsync(api_server + "/v1/token-count", args);
|
const data = await postAsync(api_server + "/v1/token-count", args);
|
||||||
console.log(data);
|
console.log(data);
|
||||||
return response.send({ count: data['results'][0]['tokens'] });
|
return response.send({ count: data['results'][0]['tokens'] });
|
||||||
|
@ -3609,6 +3631,7 @@ const SECRETS_FILE = './secrets.json';
|
||||||
const SETTINGS_FILE = './public/settings.json';
|
const SETTINGS_FILE = './public/settings.json';
|
||||||
const SECRET_KEYS = {
|
const SECRET_KEYS = {
|
||||||
HORDE: 'api_key_horde',
|
HORDE: 'api_key_horde',
|
||||||
|
MANCER: 'api_key_mancer',
|
||||||
OPENAI: 'api_key_openai',
|
OPENAI: 'api_key_openai',
|
||||||
NOVEL: 'api_key_novel',
|
NOVEL: 'api_key_novel',
|
||||||
CLAUDE: 'api_key_claude',
|
CLAUDE: 'api_key_claude',
|
||||||
|
|
Loading…
Reference in New Issue