This commit is contained in:
RossAscends
2023-06-14 17:17:39 +09:00
4 changed files with 1 additions and 146 deletions

View File

@ -1924,16 +1924,8 @@
<div id="world_popup_export" class="menu_button">Export</div> <div id="world_popup_export" class="menu_button">Export</div>
<div id="world_popup_delete" class="menu_button">Delete World</div> <div id="world_popup_delete" class="menu_button">Delete World</div>
</div> </div>
</div> </div>
</div> </div>
<div id="softprompt_block">
<h4>Soft Prompt</h4>
<h5>About soft prompts <a href="https://docs.sillytavern.app/usage/api-connections/koboldai/#soft-prompts" class="notes-link" target="_blank"><span class="note-link-span">?</span></a></h5>
<select id="softprompt">
<option value="">None</option>
</select>
</div>
</div> </div>
</div> </div>

View File

@ -777,63 +777,6 @@ function resultCheckStatus() {
$("#api_button_textgenerationwebui").css("display", "inline-block"); $("#api_button_textgenerationwebui").css("display", "inline-block");
} }
async function getSoftPromptsList() {
if (!api_server) {
return;
}
const response = await fetch("/getsoftprompts", {
method: "POST",
headers: getRequestHeaders(),
body: JSON.stringify({ api_server: api_server }),
});
if (response.ok) {
const data = await response.json();
updateSoftPromptsList(data.soft_prompts);
}
}
function clearSoftPromptsList() {
$('#softprompt option[value!=""]').each(function () {
$(this).remove();
});
}
function updateSoftPromptsList(soft_prompts) {
// Delete SPs removed from Kobold
$("#softprompt option").each(function () {
const value = $(this).attr("value");
if (value == "") {
return;
}
const prompt = soft_prompts.find((x) => x.name === value);
if (!prompt) {
$(this).remove();
}
});
// Add SPs added to Kobold
soft_prompts.forEach((prompt) => {
if ($(`#softprompt option[value="${prompt.name}"]`).length === 0) {
$("#softprompt").append(
`<option value="${prompt.name}">${prompt.name}</option>`
);
if (prompt.selected) {
$("#softprompt").val(prompt.name);
}
}
});
// No SP selected or no SPs
if (soft_prompts.length === 0 || !soft_prompts.some((x) => x.selected)) {
$("#softprompt").val("");
}
}
async function printCharacters() { async function printCharacters() {
$("#rm_print_characters_block").empty(); $("#rm_print_characters_block").empty();
characters.forEach(function (item, i, arr) { characters.forEach(function (item, i, arr) {
@ -3770,7 +3713,6 @@ function changeMainAPI() {
apiRanges: $("#range_block"), apiRanges: $("#range_block"),
maxContextElem: $("#max_context_block"), maxContextElem: $("#max_context_block"),
amountGenElem: $("#amount_gen_block"), amountGenElem: $("#amount_gen_block"),
softPromptElem: $("#softprompt_block")
}, },
"kobold": { "kobold": {
apiSettings: $("#kobold_api-settings"), apiSettings: $("#kobold_api-settings"),
@ -3779,7 +3721,6 @@ function changeMainAPI() {
apiRanges: $("#range_block"), apiRanges: $("#range_block"),
maxContextElem: $("#max_context_block"), maxContextElem: $("#max_context_block"),
amountGenElem: $("#amount_gen_block"), amountGenElem: $("#amount_gen_block"),
softPromptElem: $("#softprompt_block")
}, },
"textgenerationwebui": { "textgenerationwebui": {
apiSettings: $("#textgenerationwebui_api-settings"), apiSettings: $("#textgenerationwebui_api-settings"),
@ -3788,7 +3729,6 @@ function changeMainAPI() {
apiRanges: $("#range_block_textgenerationwebui"), apiRanges: $("#range_block_textgenerationwebui"),
maxContextElem: $("#max_context_block"), maxContextElem: $("#max_context_block"),
amountGenElem: $("#amount_gen_block"), amountGenElem: $("#amount_gen_block"),
softPromptElem: $("#softprompt_block")
}, },
"novel": { "novel": {
apiSettings: $("#novel_api-settings"), apiSettings: $("#novel_api-settings"),
@ -3797,7 +3737,6 @@ function changeMainAPI() {
apiRanges: $("#range_block_novel"), apiRanges: $("#range_block_novel"),
maxContextElem: $("#max_context_block"), maxContextElem: $("#max_context_block"),
amountGenElem: $("#amount_gen_block"), amountGenElem: $("#amount_gen_block"),
softPromptElem: $("#softprompt_block")
}, },
"openai": { "openai": {
apiSettings: $("#openai_settings"), apiSettings: $("#openai_settings"),
@ -3806,7 +3745,6 @@ function changeMainAPI() {
apiRanges: $("#range_block_openai"), apiRanges: $("#range_block_openai"),
maxContextElem: $("#max_context_block"), maxContextElem: $("#max_context_block"),
amountGenElem: $("#amount_gen_block"), amountGenElem: $("#amount_gen_block"),
softPromptElem: $("#softprompt_block"),
}, },
"poe": { "poe": {
apiSettings: $("#poe_settings"), apiSettings: $("#poe_settings"),
@ -3815,7 +3753,6 @@ function changeMainAPI() {
apiRanges: $("#range_block_poe"), apiRanges: $("#range_block_poe"),
maxContextElem: $("#max_context_block"), maxContextElem: $("#max_context_block"),
amountGenElem: $("#amount_gen_block"), amountGenElem: $("#amount_gen_block"),
softPromptElem: $("#softprompt_block"),
} }
}; };
//console.log('--- apiElements--- '); //console.log('--- apiElements--- ');
@ -3847,11 +3784,6 @@ function changeMainAPI() {
activeItem.apiPresets.css("display", "flex"); activeItem.apiPresets.css("display", "flex");
} }
if (selectedVal === "kobold" || selectedVal === 'koboldhorde') {
//console.log("enabling SP for kobold");
$("#softprompt_block").css("display", "block");
}
if (selectedVal === "textgenerationwebui" || selectedVal === "novel") { if (selectedVal === "textgenerationwebui" || selectedVal === "novel") {
console.log("enabling amount_gen for ooba/novel"); console.log("enabling amount_gen for ooba/novel");
activeItem.amountGenElem.find('input').prop("disabled", false); activeItem.amountGenElem.find('input').prop("disabled", false);
@ -6478,8 +6410,6 @@ $(document).ready(function () {
is_get_status = true; is_get_status = true;
is_api_button_press = true; is_api_button_press = true;
getStatus(); getStatus();
clearSoftPromptsList();
getSoftPromptsList();
} }
}); });
@ -6710,29 +6640,11 @@ $(document).ready(function () {
setOpenAIOnlineStatus(false); setOpenAIOnlineStatus(false);
setPoeOnlineStatus(false); setPoeOnlineStatus(false);
online_status = "no_connection"; online_status = "no_connection";
clearSoftPromptsList();
checkOnlineStatus(); checkOnlineStatus();
changeMainAPI(); changeMainAPI();
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$("#softprompt").change(async function () {
if (!api_server) {
return;
}
const selected = $("#softprompt").find(":selected").val();
const response = await fetch("/setsoftprompt", {
method: "POST",
headers: getRequestHeaders(),
body: JSON.stringify({ name: selected, api_server: api_server }),
});
if (!response.ok) {
console.error("Couldn't change soft prompt");
}
});
////////////////// OPTIMIZED RANGE SLIDER LISTENERS//////////////// ////////////////// OPTIMIZED RANGE SLIDER LISTENERS////////////////
const sliders = [ const sliders = [

View File

@ -1864,16 +1864,6 @@ input[type=search]:focus::-webkit-search-cancel-button {
column-gap: 20px; column-gap: 20px;
} }
#softprompt {
margin-bottom: 10px;
}
/* hidden until we find out a way to handle it better */
#softprompt_block {
display: none;
}
.world_info_select_block { .world_info_select_block {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
@ -4654,4 +4644,4 @@ body.waifuMode #avatar_zoom_popup {
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
} }
} }

View File

@ -661,45 +661,6 @@ const formatApiUrl = (url) => (url.indexOf('localhost') !== -1)
? url.replace('localhost', '127.0.0.1') ? url.replace('localhost', '127.0.0.1')
: url; : url;
app.post('/getsoftprompts', jsonParser, async function (request, response) {
if (!request.body || !request.body.api_server) {
return response.sendStatus(400);
}
const baseUrl = formatApiUrl(request.body.api_server);
let soft_prompts = [];
try {
const softPromptsList = (await getAsync(`${baseUrl}/v1/config/soft_prompts_list`, baseRequestArgs)).values.map(x => x.value);
const softPromptSelected = (await getAsync(`${baseUrl}/v1/config/soft_prompt`, baseRequestArgs)).value;
soft_prompts = softPromptsList.map(x => ({ name: x, selected: x === softPromptSelected }));
} catch (err) {
soft_prompts = [];
}
return response.send({ soft_prompts });
});
app.post("/setsoftprompt", jsonParser, async function (request, response) {
if (!request.body || !request.body.api_server) {
return response.sendStatus(400);
}
const baseUrl = formatApiUrl(request.body.api_server);
const args = {
headers: { "Content-Type": "application/json" },
data: { value: request.body.name ?? '' },
};
try {
await putAsync(`${baseUrl}/v1/config/soft_prompt`, args);
} catch {
return response.sendStatus(500);
}
return response.sendStatus(200);
});
function getVersion() { function getVersion() {
let pkgVersion = 'UNKNOWN'; let pkgVersion = 'UNKNOWN';
let gitRevision = null; let gitRevision = null;