From c940d0abf631dfcc8f00fcffe738758173b25cb1 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Wed, 9 Apr 2025 08:49:11 +0200 Subject: [PATCH] upgraded core --- lollms/app.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lollms/app.py b/lollms/app.py index 3455ffc..3c94b5f 100644 --- a/lollms/app.py +++ b/lollms/app.py @@ -712,11 +712,19 @@ class LollmsApplication(LoLLMsCom): message_type: MSG_OPERATION_TYPE = MSG_OPERATION_TYPE.MSG_OPERATION_TYPE_SET_CONTENT, sender_type: SENDER_TYPES = SENDER_TYPES.SENDER_TYPES_AI, open=False, + compute_nb_tokens=False ): client = self.session.get_client(client_id) # self.close_message(client_id) if sender == None: sender = self.personality.name + try: + if compute_nb_tokens: + nb_tokens = self.model.count_tokens(content) + else: + nb_tokens = 0 + except: + nb_tokens = 0 msg = client.discussion.add_message( message_type=message_type.value, sender_type=sender_type.value, @@ -737,6 +745,7 @@ class LollmsApplication(LoLLMsCom): self.config["active_personality_id"] ], created_at=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + nb_tokens = nb_tokens ) # first the content is empty, but we'll fill it at the end await self.sio.emit( "new_message", @@ -1078,9 +1087,7 @@ class LollmsApplication(LoLLMsCom): datetime.now().strftime("%Y-%m-%d %H:%M:%S") ) try: - client.discussion.current_message.nb_tokens = len( - self.model.tokenize(client.generated_text) - ) + client.discussion.current_message.nb_tokens = self.model.count_tokens(client.generated_text) except: client.discussion.current_message.nb_tokens = None await self.sio.emit(