mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2025-04-13 22:02:58 +00:00
fix
This commit is contained in:
parent
41e9f9fa70
commit
8a2541b2a5
@ -45,7 +45,10 @@ def add_events(sio: socketio):
|
||||
lollmsElfServer.cancel_gen = True
|
||||
#kill thread
|
||||
ASCIIColors.error(f'Client {sid} requested cancelling generation')
|
||||
client.generation_routine.cancel()
|
||||
try:
|
||||
client.generation_routine.cancel()
|
||||
except Exception as ex:
|
||||
pass
|
||||
lollmsElfServer.busy=False
|
||||
if lollmsElfServer.tts:
|
||||
lollmsElfServer.tts.stop()
|
||||
@ -59,7 +62,7 @@ def add_events(sio: socketio):
|
||||
client = lollmsElfServer.session.get_client(client_id)
|
||||
client.requested_stop=True
|
||||
print(f"Client {client_id} requested canceling generation")
|
||||
lollmsElfServer.sio.emit("generation_canceled", {"message":"Generation is canceled."}, to=client_id)
|
||||
await lollmsElfServer.sio.emit("generation_canceled", {"message":"Generation is canceled."}, to=client_id)
|
||||
lollmsElfServer.busy = False
|
||||
|
||||
|
||||
@ -102,11 +105,6 @@ def add_events(sio: socketio):
|
||||
)
|
||||
|
||||
await lollmsElfServer.start_message_generation(message, message.id, client_id)
|
||||
|
||||
# lollmsElfServer.sio.sleep(0.01)
|
||||
lollmsElfServer.busy = True
|
||||
# tpe = threading.Thread(target=lollmsElfServer.start_message_generation, args=(message, message_id, client_id))
|
||||
# tpe.start()
|
||||
else:
|
||||
lollmsElfServer.error("I am busy. Come back later.", client_id=client_id)
|
||||
|
||||
@ -154,10 +152,6 @@ def add_events(sio: socketio):
|
||||
|
||||
await lollmsElfServer.start_message_generation(message, message.id, client_id, force_using_internet=True)
|
||||
|
||||
# lollmsElfServer.sio.sleep(0.01)
|
||||
lollmsElfServer.busy = True
|
||||
# tpe = threading.Thread(target=lollmsElfServer.start_message_generation, args=(message, message_id, client_id))
|
||||
# tpe.start()
|
||||
else:
|
||||
lollmsElfServer.error("I am busy. Come back later.", client_id=client_id)
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit e5cd49c9c4deed4afe958e8c410876f29ae4f838
|
||||
Subproject commit 0c21805e55c06faed7b2db3d23d9cd0494617ded
|
@ -450,79 +450,6 @@ class LOLLMSWebUI(LOLLMSElfServer):
|
||||
cleaned_string = re.sub(pattern, "", cleaned_string)
|
||||
return cleaned_string
|
||||
|
||||
def make_discussion_title(self, discussion, client_id=None):
|
||||
"""
|
||||
Builds a title for a discussion
|
||||
"""
|
||||
|
||||
# Get the list of messages
|
||||
messages = discussion.get_messages()
|
||||
discussion_messages = f"{self.system_full_header}Create a short title to this discussion\n--- discussion ---\n"
|
||||
discussion_title = f"\n{self.ai_custom_header('assistant')}"
|
||||
|
||||
available_space = (
|
||||
self.config.ctx_size
|
||||
- 150
|
||||
- self.model.count_tokens(discussion_messages)
|
||||
- self.model.count_tokens(discussion_title)
|
||||
)
|
||||
# Initialize a list to store the full messages
|
||||
full_message_list = []
|
||||
# Accumulate messages until the cumulative number of tokens exceeds available_space
|
||||
tokens_accumulated = 0
|
||||
# Accumulate messages starting from message_index
|
||||
for message in messages:
|
||||
# Check if the message content is not empty and visible to the AI
|
||||
if message.content != "" and (
|
||||
message.message_type
|
||||
<= MSG_OPERATION_TYPE.MSG_OPERATION_TYPE_SET_CONTENT_INVISIBLE_TO_USER.value
|
||||
and message.message_type
|
||||
!= MSG_OPERATION_TYPE.MSG_OPERATION_TYPE_SET_CONTENT_INVISIBLE_TO_AI.value
|
||||
):
|
||||
|
||||
# Tokenize the message content
|
||||
message_tokenized = self.model.tokenize(
|
||||
"\n"
|
||||
+ self.config.discussion_prompt_separator
|
||||
+ message.sender
|
||||
+ ": "
|
||||
+ message.content.strip()
|
||||
)
|
||||
|
||||
# Check if adding the message will exceed the available space
|
||||
if tokens_accumulated + len(message_tokenized) > available_space:
|
||||
break
|
||||
|
||||
# Add the tokenized message to the full_message_list
|
||||
full_message_list.insert(0, message_tokenized)
|
||||
|
||||
# Update the cumulative number of tokens
|
||||
tokens_accumulated += len(message_tokenized)
|
||||
|
||||
# Build the final discussion messages by detokenizing the full_message_list
|
||||
|
||||
for message_tokens in full_message_list:
|
||||
discussion_messages += self.model.detokenize(message_tokens)
|
||||
discussion_messages +"\n--- ---\n"
|
||||
discussion_messages +f"\n{self.user_custom_header('user')}Your response should only contain the title without any comments or thoughts.\n"
|
||||
discussion_messages += discussion_title
|
||||
title = [""]
|
||||
|
||||
def receive(chunk: str, message_type: MSG_OPERATION_TYPE):
|
||||
if chunk:
|
||||
title[0] += chunk
|
||||
antiprompt = self.personality.detect_antiprompt(title[0])
|
||||
if antiprompt:
|
||||
ASCIIColors.warning(f"\n{antiprompt} detected. Stopping generation")
|
||||
title[0] = self.remove_text_from_string(title[0], antiprompt)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
self._generate(discussion_messages, 1024, client_id, receive)
|
||||
title[0] = self.personality.remove_thinking_blocks(title[0])
|
||||
ASCIIColors.info(f"TITLE:{title[0]}")
|
||||
return title[0]
|
||||
|
||||
def get_discussion_to(self, client_id, message_id=-1):
|
||||
messages = self.session.get_client(client_id).discussion.get_messages()
|
||||
|
Loading…
x
Reference in New Issue
Block a user