This commit is contained in:
RossAscends
2023-04-18 02:33:04 +09:00
4 changed files with 59 additions and 8 deletions

View File

@@ -6,6 +6,7 @@ import {
loadKoboldSettings, loadKoboldSettings,
formatKoboldUrl, formatKoboldUrl,
getKoboldGenerationData, getKoboldGenerationData,
canUseKoboldStopSequence,
} from "./scripts/kai-settings.js"; } from "./scripts/kai-settings.js";
import { import {
@@ -518,6 +519,11 @@ async function getStatus() {
is_pygmalion = false; is_pygmalion = false;
} }
// determine if we can use stop sequence
if (main_api == "kobold") {
kai_settings.use_stop_sequence = canUseKoboldStopSequence(data.version);
}
// determine if streaming is enabled for ooba // determine if streaming is enabled for ooba
if (main_api == 'textgenerationwebui' && typeof data.gradio_config == 'string') { if (main_api == 'textgenerationwebui' && typeof data.gradio_config == 'string') {
try { try {
@@ -2196,6 +2202,9 @@ function saveReply(type, getMessage, this_mes_is_name) {
type = 'normal'; type = 'normal';
} }
const img = extractImageFromMessage(getMessage);
getMessage = img.getMessage;
if (type === 'swipe') { if (type === 'swipe') {
chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipes'].length] = getMessage; chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipes'].length] = getMessage;
if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) { if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) {
@@ -2225,12 +2234,32 @@ function saveReply(type, getMessage, this_mes_is_name) {
chat[chat.length - 1]['is_name'] = true; chat[chat.length - 1]['is_name'] = true;
chat[chat.length - 1]['force_avatar'] = avatarImg; chat[chat.length - 1]['force_avatar'] = avatarImg;
} }
//console.log('runGenerate calls addOneMessage');
saveImageToMessage(img, chat[chat.length - 1]);
addOneMessage(chat[chat.length - 1]); addOneMessage(chat[chat.length - 1]);
} }
return { type, getMessage }; return { type, getMessage };
} }
function saveImageToMessage(img, mes) {
if (mes && img.image) {
if (typeof mes.extra !== 'object') {
mes.extra = {};
}
mes.extra.image = img.image;
mes.title = img.title;
}
}
function extractImageFromMessage(getMessage) {
const regex = /<img src="(.*?)".*?alt="(.*?)".*?>/g;
const results = regex.exec(getMessage);
const image = results ? results[1] : '';
const title = results ? results[2] : '';
getMessage = getMessage.replace(regex, '');
return { getMessage, image, title };
}
function isMultigenEnabled() { function isMultigenEnabled() {
return power_user.multigen && (main_api == 'textgenerationwebui' || main_api == 'kobold' || main_api == 'novel'); return power_user.multigen && (main_api == 'textgenerationwebui' || main_api == 'kobold' || main_api == 'novel');
} }

View File

@@ -8,6 +8,7 @@ export {
loadKoboldSettings, loadKoboldSettings,
formatKoboldUrl, formatKoboldUrl,
getKoboldGenerationData, getKoboldGenerationData,
canUseKoboldStopSequence,
}; };
const kai_settings = { const kai_settings = {
@@ -21,8 +22,11 @@ const kai_settings = {
tfs: 1, tfs: 1,
rep_pen_slope: 0.9, rep_pen_slope: 0.9,
single_line: false, single_line: false,
use_stop_sequence: false,
}; };
const MIN_STOP_SEQUENCE_VERSION = '1.2.2';
function formatKoboldUrl(value) { function formatKoboldUrl(value) {
try { try {
const url = new URL(value); const url = new URL(value);
@@ -81,7 +85,7 @@ function getKoboldGenerationData(finalPromt, this_settings, this_amount_gen, thi
s7: this_settings.sampler_order[6], s7: this_settings.sampler_order[6],
use_world_info: false, use_world_info: false,
singleline: kai_settings.single_line, singleline: kai_settings.single_line,
stop_sequence: [getStoppingStrings(isImpersonate, false)], stop_sequence: kai_settings.use_stop_sequence ? [getStoppingStrings(isImpersonate, false)] : undefined,
}; };
return generate_data; return generate_data;
} }
@@ -152,6 +156,10 @@ const sliders = [
}, },
]; ];
function canUseKoboldStopSequence(version) {
return version.localeCompare(MIN_STOP_SEQUENCE_VERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
}
$(document).ready(function () { $(document).ready(function () {
sliders.forEach(slider => { sliders.forEach(slider => {
$(document).on("input", slider.sliderId, function () { $(document).on("input", slider.sliderId, function () {

View File

@@ -344,7 +344,6 @@ code {
outline: none; outline: none;
border: none; border: none;
position: relative; position: relative;
display: inline;
opacity: 0.7; opacity: 0.7;
cursor: pointer; cursor: pointer;
z-index: 2001; z-index: 2001;
@@ -352,6 +351,8 @@ code {
padding-top: 0; padding-top: 0;
transition: 0.3s; transition: 0.3s;
font-size: 30px; font-size: 30px;
display: flex;
align-items: center;
} }
.font-family-reset { .font-family-reset {
@@ -407,6 +408,7 @@ code {
display: flex; display: flex;
align-items: center; align-items: center;
column-gap: 10px; column-gap: 10px;
cursor: pointer;
} }
.options-content a div:first-child { .options-content a div:first-child {

View File

@@ -270,8 +270,10 @@ app.post("/generate", jsonParser, async function (request, response_generate = r
typical: request.body.typical, typical: request.body.typical,
sampler_order: sampler_order, sampler_order: sampler_order,
singleline: !!request.body.singleline, singleline: !!request.body.singleline,
stop_sequence: request.body.stop_sequence || [],
}; };
if (!!request.body.stop_sequence) {
this_settings['stop_sequence'] = request.body.stop_sequence;
}
} }
console.log(this_settings); console.log(this_settings);
@@ -415,7 +417,7 @@ app.post("/generate_textgenerationwebui", jsonParser, async function (request, r
try { try {
for await (const text of readWebsocket()) { for await (const text of readWebsocket()) {
if (text == null) { if (text == null || typeof text !== 'string') {
break; break;
} }
@@ -536,7 +538,7 @@ app.post("/getchat", jsonParser, function (request, response) {
}); });
app.post("/getstatus", jsonParser, 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;
main_api = request.body.main_api; main_api = request.body.main_api;
@@ -547,10 +549,19 @@ app.post("/getstatus", jsonParser, function (request, response_getstatus = respo
headers: { "Content-Type": "application/json" } headers: { "Content-Type": "application/json" }
}; };
var url = api_server + "/v1/model"; var url = api_server + "/v1/model";
let version = '';
if (main_api == "textgenerationwebui") { if (main_api == "textgenerationwebui") {
url = api_server; url = api_server;
args = {} args = {}
} }
if (main_api == "kobold") {
try {
version = (await getAsync(api_server + "/v1/info/version")).result;
}
catch {
version = '0.0.0';
}
}
client.get(url, args, function (data, response) { client.get(url, args, function (data, response) {
if (response.statusCode == 200) { if (response.statusCode == 200) {
if (main_api == "textgenerationwebui") { if (main_api == "textgenerationwebui") {
@@ -568,8 +579,8 @@ app.post("/getstatus", jsonParser, function (request, response_getstatus = respo
data = { result: "no_connection" }; data = { result: "no_connection" };
} }
} else { } else {
data.version = version;
if (data.result != "ReadOnly") { if (data.result != "ReadOnly") {
//response_getstatus.send(data.result);
} else { } else {
data.result = "no_connection"; data.result = "no_connection";
} }
@@ -2106,8 +2117,9 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op
response_generate_openai.end(); response_generate_openai.end();
}); });
} else { } else {
console.log(response.data);
response_generate_openai.send(response.data); response_generate_openai.send(response.data);
console.log(response.data);
console.log(response.data?.choices[0]?.message);
} }
} else if (response.status == 400) { } else if (response.status == 400) {
console.log('Validation error'); console.log('Validation error');