Merge pull request #615 from BlipRanger/feature/stats

Feature/stats
This commit is contained in:
Cohee
2023-07-19 17:40:03 +03:00
committed by GitHub
9 changed files with 937 additions and 59 deletions

View File

@@ -1,4 +1,5 @@
import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile } from "./scripts/RossAscends-mods.js";
import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, } from "./scripts/RossAscends-mods.js";
import { userStatsHandler, statMesProcess } from './scripts/stats.js';
import { encode } from "../scripts/gpt-2-3-tokenizer/mod.js";
import { GPT3BrowserTokenizer } from "../scripts/gpt-3-tokenizer/gpt3-tokenizer.js";
import {
@@ -326,6 +327,7 @@ let is_delete_mode = false;
let fav_ch_checked = false;
let scrollLock = false;
//initialize global var for future cropped blobs
let currentCroppedAvatar = '';
@@ -949,8 +951,11 @@ async function getCharacters() {
if (this_chid != undefined && this_chid != "invalid-safety-id") {
$("#avatar_url_pole").val(characters[this_chid].avatar);
}
await getGroups();
await printCharacters();
updateCharacterCount('#rm_print_characters_block > div');
}
}
@@ -1310,6 +1315,8 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true
const timestamp = momentDate.isValid() ? momentDate.format('LL LT') : '';
if (mes?.extra?.display_text) {
messageText = mes.extra.display_text;
}
@@ -3045,7 +3052,7 @@ export async function sendMessageAsUser(textareaText, messageBias) {
console.debug('checking bias');
chat[chat.length - 1]['extra']['bias'] = messageBias;
}
statMesProcess(chat[chat.length - 1], 'user', characters, this_chid, '');
addOneMessage(chat[chat.length - 1]);
// Wait for all handlers to finish before continuing with the prompt
await eventSource.emit(event_types.MESSAGE_SENT, (chat.length - 1));
@@ -3730,16 +3737,21 @@ function cleanUpMessage(getMessage, isImpersonate, isContinue, displayIncomplete
return getMessage;
}
function saveReply(type, getMessage, this_mes_is_name, title) {
if (type != 'append' && type != 'continue' && type != 'appendFinal' && chat.length && (chat[chat.length - 1]['swipe_id'] === undefined ||
chat[chat.length - 1]['is_user'])) {
type = 'normal';
}
let oldMessage = ''
const generationFinished = new Date();
const img = extractImageFromMessage(getMessage);
getMessage = img.getMessage;
if (type === 'swipe') {
oldMessage = chat[chat.length - 1]['mes'];
chat[chat.length - 1]['swipes'].length++;
if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) {
chat[chat.length - 1]['title'] = title;
@@ -3755,6 +3767,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
}
} else if (type === 'append' || type === 'continue') {
console.debug("Trying to append.")
oldMessage = chat[chat.length - 1]['mes'];
chat[chat.length - 1]['title'] = title;
chat[chat.length - 1]['mes'] += getMessage;
chat[chat.length - 1]['gen_started'] = generation_started;
@@ -3764,6 +3777,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
chat[chat.length - 1]["extra"]["model"] = getGeneratingModel();
addOneMessage(chat[chat.length - 1], { type: 'swipe' });
} else if (type === 'appendFinal') {
oldMessage = chat[chat.length - 1]['mes'];
console.debug("Trying to appendFinal.")
chat[chat.length - 1]['title'] = title;
chat[chat.length - 1]['mes'] = getMessage;
@@ -3831,6 +3845,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
extra: JSON.parse(JSON.stringify(chat[chat.length - 1]["extra"])),
};
}
statMesProcess(chat[chat.length - 1], type, characters, this_chid, oldMessage);
return { type, getMessage };
}
@@ -4205,12 +4220,15 @@ async function getChat() {
chat.push(...response);
chat_create_date = chat[0]['create_date'];
chat_metadata = chat[0]['chat_metadata'] ?? {};
chat.shift();
} else {
chat_create_date = humanizedDateTime();
}
await getChatResult();
await saveChat();
setTimeout(function () {
$('#send_textarea').click();
$('#send_textarea').focus();
@@ -4866,7 +4884,6 @@ async function getSettings(type) {
}
const data = await response.json();
if (data.result != "file not find" && data.settings) {
settings = JSON.parse(data.settings);
if (settings.username !== undefined) {
@@ -5058,7 +5075,7 @@ async function saveSettings(type) {
extension_settings: extension_settings,
context_settings: context_settings,
tags: tags,
tag_map: tag_map,
tag_map: tag_map,
...nai_settings,
...kai_settings,
...oai_settings,
@@ -5092,6 +5109,8 @@ async function saveSettings(type) {
});
}
function setCharacterBlockHeight() {
const $children = $("#rm_print_characters_block").children();
const originalHeight = $children.length * $children.find(':visible').first().outerHeight();
@@ -8582,6 +8601,10 @@ $(document).ready(function () {
restoreCaretPosition($(this).get(0), caretPosition);
});
$(".user_stats_button").on('click', function () {
userStatsHandler();
});
$('#external_import_button').on('click', async () => {
const html = `<h3>Enter the URL of the content to import</h3>
Supported sources:<br>
@@ -8720,4 +8743,4 @@ $(document).ready(function () {
$("#charListGridToggle").on('click', async () => {
doCharListDisplaySwitch();
});
})
});