code review adjustments part 1

This commit is contained in:
50h100a 2023-08-03 06:07:54 -04:00
parent 61c0e3b08b
commit 2fc6813e66
4 changed files with 23 additions and 7 deletions

View File

@ -1541,7 +1541,7 @@
<div id="textgenerationwebui_api" style="display: none;position: relative;">
<form action="javascript:void(null);" method="post" enctype="multipart/form-data">
If you are using:
<div class="flex-container" style="margin-left:20px;">
<div class="flex-container indent20p">
<a href="https://github.com/oobabooga/text-generation-webui" target="_blank">
oobabooga/text-generation-webui
</a>,
@ -1549,7 +1549,7 @@
Make sure you run it with <tt>--api</tt> flag
</span>
</div>
<div class="flex-container" style="margin-left:20px;">
<div class="flex-container indent20p">
<a href="https://mancer.tech/" target="_blank">
Mancer AI
</a>,

View File

@ -17,6 +17,7 @@ import {
loadTextGenSettings,
generateTextGenWithStreaming,
getTextGenGenerationData,
formatTextGenURL,
} from "./scripts/textgen-settings.js";
import {
@ -7687,24 +7688,24 @@ $(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");
$("#mancer-api-ui").toggle(enabled);
api_use_mancer_webui = enabled;
saveSettingsDebounced();
getStatus();
});
$("#api_button_textgenerationwebui").click(function (e) {
$("#api_button_textgenerationwebui").click(async function (e) {
e.stopPropagation();
if ($("#textgenerationwebui_api_url_text").val() != "") {
let value = $("#textgenerationwebui_api_url_text").val().trim();
if (!value || !value.endsWith('/api')) {
let value = formatTextGenURL($("#textgenerationwebui_api_url_text").val().trim())
if (!value) {
callPopup('Please enter a valid URL.<br/>WebUI URLs should end with <tt>/api</tt>', 'text');
return;
}
const mancer_key = $("#api_key_mancer").val().trim();
if (mancer_key.length) {
writeSecret(SECRET_KEYS.MANCER, mancer_key);
await writeSecret(SECRET_KEYS.MANCER, mancer_key);
}
$("#textgenerationwebui_api_url_text").val(value);

View File

@ -10,6 +10,7 @@ export {
textgenerationwebui_settings,
loadTextGenSettings,
generateTextGenWithStreaming,
formatTextGenURL,
}
const textgenerationwebui_settings = {
@ -94,6 +95,16 @@ function selectPreset(name) {
saveSettingsDebounced();
}
function formatTextGenURL(value) {
try {
const url = new URL(value);
if (url.pathname.endsWith('/api')) {
return url.toString();
}
} catch { } // Try and Catch both fall through to the same return.
return null;
}
function convertPresets(presets) {
return Array.isArray(presets) ? presets.map(JSON.parse) : [];
}

View File

@ -4409,6 +4409,10 @@ toolcool-color-picker {
width: 50px;
}
.indent20p {
margin-left: 20px;
}
.wi-enter-footer-text {
font-size: calc(var(--mainFontSize) * 0.8);
color: var(--SmartThemeBodyColor);