diff --git a/public/index.html b/public/index.html index 41eaedc62..a4d459e67 100644 --- a/public/index.html +++ b/public/index.html @@ -37,6 +37,7 @@ + @@ -1946,7 +1947,10 @@
-
+
+ +
+
@@ -1969,9 +1973,7 @@
-
-
diff --git a/public/script.js b/public/script.js index b9a1c0b69..904c34a0a 100644 --- a/public/script.js +++ b/public/script.js @@ -213,6 +213,7 @@ const default_ch_mes = "Hello"; let count_view_mes = 0; let mesStr = ""; let generatedPromtCache = ""; +let generation_started = new Date(); let characters = []; let this_chid; let backgrounds = []; @@ -972,13 +973,14 @@ function messageFormating(mes, ch_name, isSystem, forceAvatar) { return mes; } -function getMessageFromTemplate(mesId, characterName, isUser, avatarImg, bias, isSystem, title) { +function getMessageFromTemplate({ mesId, characterName, isUser, avatarImg, bias, isSystem, title, timerValue, timerTitle } = {}) { const mes = $('#message_template .mes').clone(); mes.attr({ 'mesid': mesId, 'ch_name': characterName, 'is_user': isUser, 'is_system': !!isSystem }); mes.find('.avatar img').attr('src', avatarImg); mes.find('.ch_name .name_text').text(characterName); mes.find('.mes_bias').html(bias); title && mes.attr('title', title); + timerValue && mes.find('.mes_timer').attr('title', timerTitle).text(timerValue); return mes; } @@ -1053,7 +1055,18 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true ); const bias = messageFormating(mes.extra?.bias ?? ""); - var HTMLForEachMes = getMessageFromTemplate(count_view_mes, characterName, mes.is_user, avatarImg, bias, isSystem, title); + let params = { + mesId: count_view_mes, + characterName: characterName, + isUser: mes.is_user, + avatarImg: avatarImg, + bias: bias, + isSystem: isSystem, + title: title, + ...formatGenerationTimer(mes.gen_started, mes.gen_finished), + }; + + const HTMLForEachMes = getMessageFromTemplate(params); if (type !== 'swipe') { if (!insertAfter) { @@ -1083,13 +1096,18 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true }); if (type === 'swipe') { - $("#chat").children().filter(`[mesid="${count_view_mes - 1}"]`).children('.mes_block').children('.mes_text').html(''); - $("#chat").children().filter(`[mesid="${count_view_mes - 1}"]`).children('.mes_block').children('.mes_text').append(messageText); - $("#chat").children().filter(`[mesid="${count_view_mes - 1}"]`).attr('title', title); + $("#chat").find(`[mesid="${count_view_mes - 1}"]`).find('.mes_text').html(''); + $("#chat").find(`[mesid="${count_view_mes - 1}"]`).find('.mes_text').append(messageText); + $("#chat").find(`[mesid="${count_view_mes - 1}"]`).attr('title', title); - //console.log(mes); + if (mes.swipe_id == mes.swipes.length - 1) { + $("#chat").find(`[mesid="${count_view_mes - 1}"]`).find('.mes_timer').text(params.timerValue); + $("#chat").find(`[mesid="${count_view_mes - 1}"]`).find('.mes_timer').attr('title', params.timerTitle); + } else { + $("#chat").find(`[mesid="${count_view_mes - 1}"]`).find('.mes_timer').html(''); + } } else { - $("#chat").children().filter(`[mesid="${count_view_mes}"]`).children('.mes_block').children('.mes_text').append(messageText); + $("#chat").find(`[mesid="${count_view_mes}"]`).find('.mes_text').append(messageText); hideSwipeButtons(); count_view_mes++; } @@ -1107,6 +1125,25 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true } } +function formatGenerationTimer(gen_started, gen_finished) { + if (!gen_started || !gen_finished) { + return {}; + } + + const dateFormat = 'HH:mm:ss D MMM YYYY'; + const start = moment(gen_started); + const finish = moment(gen_finished); + const seconds = finish.diff(start, 'seconds', true); + const timerValue = `${seconds.toFixed(1)}s`; + const timerTitle = [ + `Generation queued: ${start.format(dateFormat)}`, + `Reply received: ${finish.format(dateFormat)}`, + `Time to generate: ${seconds} seconds`, + ].join('\n'); + + return { timerValue, timerTitle }; +} + function scrollChatToBottom() { if (power_user.auto_scroll_chat_to_bottom) { var $textchat = $("#chat"); @@ -1340,8 +1377,12 @@ class StreamingProcessor { $('#send_textarea').val(processedText).trigger('input'); } else { + let currentTime = new Date(); + const timePassed = formatGenerationTimer(this.timeStarted, currentTime); chat[messageId]['is_name'] = isName; chat[messageId]['mes'] = processedText; + chat[messageId]['gen_started'] = this.timeStarted; + chat[messageId]['gen_finished'] = currentTime; if (this.type == 'swipe' && Array.isArray(chat[messageId]['swipes'])) { chat[messageId]['swipes'][chat[messageId]['swipe_id']] = processedText; @@ -1350,6 +1391,7 @@ class StreamingProcessor { let formattedText = messageFormating(processedText, chat[messageId].name, chat[messageId].is_system, chat[messageId].force_avatar); const mesText = $(`#chat .mes[mesid="${messageId}"] .mes_text`); mesText.html(formattedText); + $(`#chat .mes[mesid="${messageId}"] .mes_timer`).text(timePassed.timerValue).attr('title', timePassed.timerTitle); this.setFirstSwipe(messageId); } @@ -1404,6 +1446,7 @@ class StreamingProcessor { this.generator = this.nullStreamingGeneration; this.abortController = new AbortController(); this.firstMessageText = '...'; + this.timeStarted = new Date(); } async generate() { @@ -1435,10 +1478,11 @@ class StreamingProcessor { } } -async function Generate(type, automatic_trigger, force_name2) { +async function Generate(type, { automatic_trigger, force_name2, quiet, quiet_prompt } = {}) { //console.log('Generate entered'); setGenerationProgress(0); tokens_already_generated = 0; + generation_started = new Date(); const isImpersonate = type == "impersonate"; message_already_generated = isImpersonate ? `${name1}: ` : `${name2}: `; @@ -2128,7 +2172,7 @@ async function Generate(type, automatic_trigger, force_name2) { let newType = type == "swipe" ? "swipe" : "force_name2"; newType = isImpersonate ? type : newType; - Generate(newType, automatic_trigger = false, force_name2 = true); + Generate(newType, { automatic_trigger: false, force_name2: true }); }, generate_loop_counter * 1000); } } else { @@ -2374,6 +2418,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) { type = 'normal'; } + const generationFinished = new Date(); const img = extractImageFromMessage(getMessage); getMessage = img.getMessage; @@ -2382,6 +2427,8 @@ function saveReply(type, getMessage, this_mes_is_name, title) { if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) { chat[chat.length - 1]['title'] = title; chat[chat.length - 1]['mes'] = getMessage; + chat[chat.length - 1]['gen_started'] = generation_started; + chat[chat.length - 1]['gen_finished'] = generationFinished; addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else { chat[chat.length - 1]['mes'] = getMessage; @@ -2390,11 +2437,15 @@ function saveReply(type, getMessage, this_mes_is_name, title) { console.log("Trying to append.") chat[chat.length - 1]['title'] = title; chat[chat.length - 1]['mes'] += getMessage; + chat[chat.length - 1]['gen_started'] = generation_started; + chat[chat.length - 1]['gen_finished'] = generationFinished; addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else if (type === 'appendFinal') { console.log("Trying to appendFinal.") chat[chat.length - 1]['title'] = title; chat[chat.length - 1]['mes'] = getMessage; + chat[chat.length - 1]['gen_started'] = generation_started; + chat[chat.length - 1]['gen_finished'] = generationFinished; addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else { @@ -2408,6 +2459,8 @@ function saveReply(type, getMessage, this_mes_is_name, title) { getMessage = $.trim(getMessage); chat[chat.length - 1]['mes'] = getMessage; chat[chat.length - 1]['title'] = title; + chat[chat.length - 1]['gen_started'] = generation_started; + chat[chat.length - 1]['gen_finished'] = generationFinished; if (selected_group) { console.log('entering chat update for groups'); @@ -3780,7 +3833,8 @@ $(document).ready(function () { } //console.log(chat[chat.length-1]['swipes']); if (parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length) { //if swipe id of last message is the same as the length of the 'swipes' array - + delete chat[chat.length - 1].gen_started; + delete chat[chat.length - 1].gen_finished; run_generate = true; } else if (parseInt(chat[chat.length - 1]['swipe_id']) < chat[chat.length - 1]['swipes'].length) { //otherwise, if the id is less than the number of swipes chat[chat.length - 1]['mes'] = chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipe_id']]; //load the last mes box with the latest generation @@ -3792,7 +3846,6 @@ $(document).ready(function () { } if (run_generate) { //hide swipe arrows while generating $(this).css('display', 'none'); - } if (run_generate || run_swipe_right) { // handles animated transitions when swipe right, specifically height transitions between messages @@ -3821,11 +3874,13 @@ $(document).ready(function () { /* if (!selected_group) { } else { */ $("#chat") - .children() - .filter('[mesid="' + (count_view_mes - 1) + '"]') - .children('.mes_block') - .children('.mes_text') + .find('[mesid="' + (count_view_mes - 1) + '"]') + .find('.mes_text') .html('...'); //shows "..." while generating + $("#chat") + .find('[mesid="' + (count_view_mes - 1) + '"]') + .find('.mes_timer') + .html(''); // resets the timer /* } */ } else { //console.log('showing previously generated swipe candidate, or "..."'); diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 3ea7b9881..f47859d2f 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -462,7 +462,7 @@ async function generateGroupWrapper(by_auto_mode, type = null) { setCharacterId(chId); setCharacterName(characters[chId].name) - await Generate(generateType, by_auto_mode); + await Generate(generateType, { automatic_trigger: by_auto_mode }); if (type !== "swipe" && type !== "impersonate") { // update indicator and scroll down diff --git a/public/scripts/moment.min.js b/public/scripts/moment.min.js new file mode 100644 index 000000000..3427886d1 --- /dev/null +++ b/public/scripts/moment.min.js @@ -0,0 +1,2 @@ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.moment=t()}(this,function(){"use strict";var H;function f(){return H.apply(null,arguments)}function a(e){return e instanceof Array||"[object Array]"===Object.prototype.toString.call(e)}function F(e){return null!=e&&"[object Object]"===Object.prototype.toString.call(e)}function c(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function L(e){if(Object.getOwnPropertyNames)return 0===Object.getOwnPropertyNames(e).length;for(var t in e)if(c(e,t))return;return 1}function o(e){return void 0===e}function u(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function V(e){return e instanceof Date||"[object Date]"===Object.prototype.toString.call(e)}function G(e,t){for(var n=[],s=e.length,i=0;i>>0,s=0;sAe(e)?(r=e+1,t-Ae(e)):(r=e,t);return{year:r,dayOfYear:n}}function qe(e,t,n){var s,i,r=ze(e.year(),t,n),r=Math.floor((e.dayOfYear()-r-1)/7)+1;return r<1?s=r+P(i=e.year()-1,t,n):r>P(e.year(),t,n)?(s=r-P(e.year(),t,n),i=e.year()+1):(i=e.year(),s=r),{week:s,year:i}}function P(e,t,n){var s=ze(e,t,n),t=ze(e+1,t,n);return(Ae(e)-s+t)/7}s("w",["ww",2],"wo","week"),s("W",["WW",2],"Wo","isoWeek"),t("week","w"),t("isoWeek","W"),n("week",5),n("isoWeek",5),v("w",p),v("ww",p,w),v("W",p),v("WW",p,w),Te(["w","ww","W","WW"],function(e,t,n,s){t[s.substr(0,1)]=g(e)});function Be(e,t){return e.slice(t,7).concat(e.slice(0,t))}s("d",0,"do","day"),s("dd",0,0,function(e){return this.localeData().weekdaysMin(this,e)}),s("ddd",0,0,function(e){return this.localeData().weekdaysShort(this,e)}),s("dddd",0,0,function(e){return this.localeData().weekdays(this,e)}),s("e",0,0,"weekday"),s("E",0,0,"isoWeekday"),t("day","d"),t("weekday","e"),t("isoWeekday","E"),n("day",11),n("weekday",11),n("isoWeekday",11),v("d",p),v("e",p),v("E",p),v("dd",function(e,t){return t.weekdaysMinRegex(e)}),v("ddd",function(e,t){return t.weekdaysShortRegex(e)}),v("dddd",function(e,t){return t.weekdaysRegex(e)}),Te(["dd","ddd","dddd"],function(e,t,n,s){s=n._locale.weekdaysParse(e,s,n._strict);null!=s?t.d=s:m(n).invalidWeekday=e}),Te(["d","e","E"],function(e,t,n,s){t[s]=g(e)});var Je="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),Qe="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),Xe="Su_Mo_Tu_We_Th_Fr_Sa".split("_"),Ke=k,et=k,tt=k;function nt(){function e(e,t){return t.length-e.length}for(var t,n,s,i=[],r=[],a=[],o=[],u=0;u<7;u++)s=l([2e3,1]).day(u),t=M(this.weekdaysMin(s,"")),n=M(this.weekdaysShort(s,"")),s=M(this.weekdays(s,"")),i.push(t),r.push(n),a.push(s),o.push(t),o.push(n),o.push(s);i.sort(e),r.sort(e),a.sort(e),o.sort(e),this._weekdaysRegex=new RegExp("^("+o.join("|")+")","i"),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp("^("+a.join("|")+")","i"),this._weekdaysShortStrictRegex=new RegExp("^("+r.join("|")+")","i"),this._weekdaysMinStrictRegex=new RegExp("^("+i.join("|")+")","i")}function st(){return this.hours()%12||12}function it(e,t){s(e,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)})}function rt(e,t){return t._meridiemParse}s("H",["HH",2],0,"hour"),s("h",["hh",2],0,st),s("k",["kk",2],0,function(){return this.hours()||24}),s("hmm",0,0,function(){return""+st.apply(this)+r(this.minutes(),2)}),s("hmmss",0,0,function(){return""+st.apply(this)+r(this.minutes(),2)+r(this.seconds(),2)}),s("Hmm",0,0,function(){return""+this.hours()+r(this.minutes(),2)}),s("Hmmss",0,0,function(){return""+this.hours()+r(this.minutes(),2)+r(this.seconds(),2)}),it("a",!0),it("A",!1),t("hour","h"),n("hour",13),v("a",rt),v("A",rt),v("H",p),v("h",p),v("k",p),v("HH",p,w),v("hh",p,w),v("kk",p,w),v("hmm",ge),v("hmmss",we),v("Hmm",ge),v("Hmmss",we),D(["H","HH"],x),D(["k","kk"],function(e,t,n){e=g(e);t[x]=24===e?0:e}),D(["a","A"],function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e}),D(["h","hh"],function(e,t,n){t[x]=g(e),m(n).bigHour=!0}),D("hmm",function(e,t,n){var s=e.length-2;t[x]=g(e.substr(0,s)),t[T]=g(e.substr(s)),m(n).bigHour=!0}),D("hmmss",function(e,t,n){var s=e.length-4,i=e.length-2;t[x]=g(e.substr(0,s)),t[T]=g(e.substr(s,2)),t[N]=g(e.substr(i)),m(n).bigHour=!0}),D("Hmm",function(e,t,n){var s=e.length-2;t[x]=g(e.substr(0,s)),t[T]=g(e.substr(s))}),D("Hmmss",function(e,t,n){var s=e.length-4,i=e.length-2;t[x]=g(e.substr(0,s)),t[T]=g(e.substr(s,2)),t[N]=g(e.substr(i))});k=de("Hours",!0);var at,ot={calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},longDateFormat:{LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},invalidDate:"Invalid date",ordinal:"%d",dayOfMonthOrdinalParse:/\d{1,2}/,relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",ss:"%d seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",w:"a week",ww:"%d weeks",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},months:Ce,monthsShort:Ue,week:{dow:0,doy:6},weekdays:Je,weekdaysMin:Xe,weekdaysShort:Qe,meridiemParse:/[ap]\.?m?\.?/i},R={},ut={};function lt(e){return e&&e.toLowerCase().replace("_","-")}function ht(e){for(var t,n,s,i,r=0;r=t&&function(e,t){for(var n=Math.min(e.length,t.length),s=0;s=t-1)break;t--}r++}return at}function dt(t){var e;if(void 0===R[t]&&"undefined"!=typeof module&&module&&module.exports&&null!=t.match("^[^/\\\\]*$"))try{e=at._abbr,require("./locale/"+t),ct(e)}catch(e){R[t]=null}return R[t]}function ct(e,t){return e&&((t=o(t)?mt(e):ft(e,t))?at=t:"undefined"!=typeof console&&console.warn&&console.warn("Locale "+e+" not found. Did you forget to load it?")),at._abbr}function ft(e,t){if(null===t)return delete R[e],null;var n,s=ot;if(t.abbr=e,null!=R[e])Q("defineLocaleOverride","use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info."),s=R[e]._config;else if(null!=t.parentLocale)if(null!=R[t.parentLocale])s=R[t.parentLocale]._config;else{if(null==(n=dt(t.parentLocale)))return ut[t.parentLocale]||(ut[t.parentLocale]=[]),ut[t.parentLocale].push({name:e,config:t}),null;s=n._config}return R[e]=new K(X(s,t)),ut[e]&&ut[e].forEach(function(e){ft(e.name,e.config)}),ct(e),R[e]}function mt(e){var t;if(!(e=e&&e._locale&&e._locale._abbr?e._locale._abbr:e))return at;if(!a(e)){if(t=dt(e))return t;e=[e]}return ht(e)}function _t(e){var t=e._a;return t&&-2===m(e).overflow&&(t=t[O]<0||11We(t[Y],t[O])?b:t[x]<0||24P(r,u,l)?m(s)._overflowWeeks=!0:null!=h?m(s)._overflowWeekday=!0:(d=$e(r,a,o,u,l),s._a[Y]=d.year,s._dayOfYear=d.dayOfYear)),null!=e._dayOfYear&&(i=bt(e._a[Y],n[Y]),(e._dayOfYear>Ae(i)||0===e._dayOfYear)&&(m(e)._overflowDayOfYear=!0),h=Ze(i,0,e._dayOfYear),e._a[O]=h.getUTCMonth(),e._a[b]=h.getUTCDate()),t=0;t<3&&null==e._a[t];++t)e._a[t]=c[t]=n[t];for(;t<7;t++)e._a[t]=c[t]=null==e._a[t]?2===t?1:0:e._a[t];24===e._a[x]&&0===e._a[T]&&0===e._a[N]&&0===e._a[Ne]&&(e._nextDay=!0,e._a[x]=0),e._d=(e._useUTC?Ze:je).apply(null,c),r=e._useUTC?e._d.getUTCDay():e._d.getDay(),null!=e._tzm&&e._d.setUTCMinutes(e._d.getUTCMinutes()-e._tzm),e._nextDay&&(e._a[x]=24),e._w&&void 0!==e._w.d&&e._w.d!==r&&(m(e).weekdayMismatch=!0)}}function Tt(e){if(e._f===f.ISO_8601)St(e);else if(e._f===f.RFC_2822)Ot(e);else{e._a=[],m(e).empty=!0;for(var t,n,s,i,r,a=""+e._i,o=a.length,u=0,l=ae(e._f,e._locale).match(te)||[],h=l.length,d=0;de.valueOf():e.valueOf()"}),i.toJSON=function(){return this.isValid()?this.toISOString():null},i.toString=function(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")},i.unix=function(){return Math.floor(this.valueOf()/1e3)},i.valueOf=function(){return this._d.valueOf()-6e4*(this._offset||0)},i.creationData=function(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}},i.eraName=function(){for(var e,t=this.localeData().eras(),n=0,s=t.length;nthis.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()},i.isLocal=function(){return!!this.isValid()&&!this._isUTC},i.isUtcOffset=function(){return!!this.isValid()&&this._isUTC},i.isUtc=At,i.isUTC=At,i.zoneAbbr=function(){return this._isUTC?"UTC":""},i.zoneName=function(){return this._isUTC?"Coordinated Universal Time":""},i.dates=e("dates accessor is deprecated. Use date instead.",ke),i.months=e("months accessor is deprecated. Use month instead",Ge),i.years=e("years accessor is deprecated. Use year instead",Ie),i.zone=e("moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/",function(e,t){return null!=e?(this.utcOffset(e="string"!=typeof e?-e:e,t),this):-this.utcOffset()}),i.isDSTShifted=e("isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information",function(){if(!o(this._isDSTShifted))return this._isDSTShifted;var e,t={};return $(t,this),(t=Nt(t))._a?(e=(t._isUTC?l:W)(t._a),this._isDSTShifted=this.isValid()&&0