This commit is contained in:
Saifeddine ALOUI 2024-04-21 00:13:15 +02:00
parent 7251b6d557
commit 0948f2ca6e
10 changed files with 335 additions and 237 deletions

View File

@ -25,6 +25,7 @@ from pathlib import Path
from typing import List
import socketio
import threading
from datetime import datetime
import os
router = APIRouter()
@ -60,6 +61,11 @@ def add_events(sio:socketio):
lollmsElfServer.session.get_client(client_id).discussion = lollmsElfServer.db.load_last_discussion()
prompt = data["prompt"]
try:
nb_tokens = len(lollmsElfServer.model.tokenize(prompt))
except:
nb_tokens = None
created_at = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
ump = lollmsElfServer.config.discussion_prompt_separator +lollmsElfServer.config.user_name.strip() if lollmsElfServer.config.use_user_name_in_discussions else lollmsElfServer.personality.user_message_prefix
message = lollmsElfServer.session.get_client(client_id).discussion.add_message(
message_type = MSG_TYPE.MSG_TYPE_FULL.value,
@ -67,7 +73,9 @@ def add_events(sio:socketio):
sender = ump.replace(lollmsElfServer.config.discussion_prompt_separator,"").replace(":",""),
content=prompt,
metadata=None,
parent_message_id=lollmsElfServer.message_id
parent_message_id=lollmsElfServer.message_id,
created_at=created_at,
nb_tokens=nb_tokens
)
ASCIIColors.green("Starting message generation by "+lollmsElfServer.personality.name)
@ -107,6 +115,11 @@ def add_events(sio:socketio):
lollmsElfServer.session.get_client(client_id).discussion = lollmsElfServer.db.load_last_discussion()
prompt = data["prompt"]
try:
nb_tokens = len(lollmsElfServer.model.tokenize(prompt))
except:
nb_tokens = None
created_at = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
ump = lollmsElfServer.config.discussion_prompt_separator +lollmsElfServer.config.user_name.strip() if lollmsElfServer.config.use_user_name_in_discussions else lollmsElfServer.personality.user_message_prefix
message = lollmsElfServer.session.get_client(client_id).discussion.add_message(
message_type = MSG_TYPE.MSG_TYPE_FULL.value,
@ -114,7 +127,9 @@ def add_events(sio:socketio):
sender = ump.replace(lollmsElfServer.config.discussion_prompt_separator,"").replace(":",""),
content=prompt,
metadata=None,
parent_message_id=lollmsElfServer.message_id
parent_message_id=lollmsElfServer.message_id,
created_at=created_at,
nb_tokens=nb_tokens
)
ASCIIColors.green("Starting message generation by "+lollmsElfServer.personality.name)

@ -1 +1 @@
Subproject commit 71287d0406cb33151eef3dcd5e943dd6815b0bf4
Subproject commit 27748309141a73db171a1015b499914cc6fce9ec

View File

@ -845,7 +845,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
)
)
if msg_type != MSG_TYPE.MSG_TYPE_INFO:
client.discussion.update_message(client.generated_text, new_metadata=mtdt, new_ui=ui)
client.discussion.update_message(client.generated_text, new_metadata=mtdt, new_ui=ui, nb_tokens=client.discussion.current_message.nb_tokens)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
web/dist/index.html vendored
View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-4d3aae9e.js"></script>
<link rel="stylesheet" href="/assets/index-908cb263.css">
<script type="module" crossorigin src="/assets/index-80bb9b98.js"></script>
<link rel="stylesheet" href="/assets/index-49ced084.css">
</head>
<body>
<div id="app"></div>

View File

@ -93,6 +93,12 @@
<b>Folder:&nbsp;</b>
{{ binding.folder }}
<div class="grow"></div>
<button
class="hover:text-secondary duration-75 active:scale-90 font-medium rounded-lg text-sm p-2 text-center inline-flex items-center "
title="Copy link to clipboard" @click.stop="copyToClipBoard(this.binding.folder)">
<i data-feather="clipboard" class="w-5"></i>
</button>
</div>
<div class="flex items-center">
<i data-feather="git-merge" class="w-5 m-1"></i>
@ -160,6 +166,10 @@ export default {
},
methods: {
copyToClipBoard(text){
console.log("Copying to clipboard :",text)
navigator.clipboard.writeText(text)
},
getImgUrl() {
return bUrl + this.binding.icon
},

View File

@ -228,8 +228,12 @@
<p v-if="message.seed">Seed: <span class="font-thin">{{ message.seed }}</span></p>
<p v-if="message.nb_tokens">Number of tokens: <span class="font-thin"
:title="'Number of Tokens: ' + message.nb_tokens">{{ message.nb_tokens }}</span></p>
<p v-if="time_spent">Time spent: <span class="font-thin"
:title="'Finished generating: ' + finished_generating_at_parsed">{{ time_spent }}</span></p>
<p v-if="wait_duration">Wait duration: <span class="font-thin"
:title="'Wait duration: ' + wait_duration">{{ wait_duration }}</span></p>
<p v-if="time_spent">Generation duration: <span class="font-thin"
:title="'Finished generating: ' + time_spent">{{ time_spent }}</span></p>
<p v-if="time_spent">Rate: <span class="font-thin"
:title="'Generation rate: ' + generation_rate">{{ generation_rate }}</span></p>
</div>
</div>
@ -381,6 +385,27 @@ export default {
}
}, methods: {
computeTimeDiff(startTime, endTime){
let timeDiff = endTime.getTime() - startTime.getTime();
const hours = Math.floor(timeDiff / (1000 * 60 * 60));
timeDiff -= hours * (1000 * 60 * 60);
const mins = Math.floor(timeDiff / (1000 * 60));
timeDiff -= mins * (1000 * 60);
const secs = Math.floor(timeDiff / 1000)
timeDiff -= secs * 1000;
return [hours, mins, secs]
},
insertTab(event) {
const textarea = event.target;
const start = textarea.selectionStart;
@ -736,8 +761,6 @@ export default {
})
},
},
computed: {
editMsgMode:{
@ -775,35 +798,18 @@ export default {
},
time_spent() {
const startTime = new Date(Date.parse(this.message.created_at))
const startTime = new Date(Date.parse(this.message.started_generating_at))
const endTime = new Date(Date.parse(this.message.finished_generating_at))
//const spentTime = new Date(endTime - startTime)
const same = endTime.getTime() === startTime.getTime();
if (same) {
return undefined
}
if (!endTime.getTime()) {
if (!startTime.getTime() || !endTime.getTime()) {
return undefined
}
let timeDiff = endTime.getTime() - startTime.getTime();
const hours = Math.floor(timeDiff / (1000 * 60 * 60));
timeDiff -= hours * (1000 * 60 * 60);
const mins = Math.floor(timeDiff / (1000 * 60));
timeDiff -= mins * (1000 * 60);
const secs = Math.floor(timeDiff / 1000)
timeDiff -= secs * 1000;
let [hours, mins, secs] = this.computeTimeDiff(startTime, endTime)
// let spentTime = Math.floor((endTime.getTime() - startTime.getTime()) / 1000);
// const result = spentTime.getSeconds();
@ -823,7 +829,67 @@ export default {
return time
},
wait_duration() {
const createdTime = new Date(Date.parse(this.message.created_at))
const endTime = new Date(Date.parse(this.message.finished_generating_at))
//const spentTime = new Date(endTime - startTime)
const same = endTime.getTime() === createdTime.getTime();
if (same) {
return undefined
}
if (!createdTime.getTime() || !endTime.getTime()) {
return undefined
}
let hours, mins, secs;
[hours, mins, secs] = this.computeTimeDiff(createdTime, endTime)
// let spentTime = Math.floor((endTime.getTime() - startTime.getTime()) / 1000);
// const result = spentTime.getSeconds();
function addZero(i) {
if (i < 10) { i = "0" + i }
return i;
}
// const d = new Date();
// let h = addZero(spentTime.getHours());
// let m = addZero(spentTime.getMinutes());
// let s = addZero(spentTime.getSeconds());
const time = addZero(hours) + "h:" + addZero(mins) + "m:" + addZero(secs) + 's';
return time
},
generation_rate() {
const startTime = new Date(Date.parse(this.message.started_generating_at))
const endTime = new Date(Date.parse(this.message.finished_generating_at))
const nb_tokens = this.message.nb_tokens
//const spentTime = new Date(endTime - startTime)
const same = endTime.getTime() === startTime.getTime();
if (same) {
return undefined
}
if (!nb_tokens){
return undefined
}
if (!startTime.getTime() || !endTime.getTime()) {
return undefined
}
let timeDiff = endTime.getTime() - startTime.getTime();
const secs = Math.floor(timeDiff / 1000)
const rate = nb_tokens/secs;
return Math.round(rate) + " t/s"
}
}

View File

@ -1344,11 +1344,18 @@ export default {
) {
this.isGenerating = true;
messageItem.content = msgObj.content
messageItem.created_at = msgObj.created_at
messageItem.started_generating_at = msgObj.started_generating_at
messageItem.nb_tokens = msgObj.nb_tokens
messageItem.finished_generating_at = msgObj.finished_generating_at
}
else if(messageItem && msgObj.message_type==this.msgTypes.MSG_TYPE_CHUNK){
this.isGenerating = true;
messageItem.content += msgObj.content
messageItem.created_at = msgObj.created_at
messageItem.started_generating_at = msgObj.started_generating_at
messageItem.nb_tokens = msgObj.nb_tokens
messageItem.finished_generating_at = msgObj.finished_generating_at
} else if (msgObj.message_type == this.msgTypes.MSG_TYPE_STEP){
messageItem.status_message = msgObj.content
messageItem.steps.push({"message":msgObj.content,"done":true, "status":true, "type": "instantanious" })

@ -1 +1 @@
Subproject commit 471fc77b42eaf7a04f6acbf64747fadfb3089186
Subproject commit 3a9aa13bd74be88caf9c083565c8b3ce05073687