upgraded code

This commit is contained in:
Saifeddine ALOUI 2024-03-17 03:25:46 +01:00
parent 5d4b5faa0f
commit ddba6ed364
2 changed files with 47 additions and 48 deletions

View File

@ -22,6 +22,7 @@ from typing import List
import socketio
from functools import partial
from datetime import datetime
import threading
import os
router = APIRouter()
@ -123,21 +124,21 @@ def add_events(sio:socketio):
client.cancel_generation=False
client.continuing=False
client.first_chunk=True
def do_generation():
if not lollmsElfServer.model:
ASCIIColors.error("Model not selected. Please select a model")
lollmsElfServer.error("Model not selected. Please select a model", client_id=client_id)
return
if not lollmsElfServer.busy:
if lollmsElfServer.session.get_client(client_id).discussion is None:
if client.discussion is None:
if lollmsElfServer.db.does_last_discussion_have_messages():
lollmsElfServer.session.get_client(client_id).discussion = lollmsElfServer.db.create_discussion()
client.discussion = lollmsElfServer.db.create_discussion()
else:
lollmsElfServer.session.get_client(client_id).discussion = lollmsElfServer.db.load_last_discussion()
client.discussion = lollmsElfServer.db.load_last_discussion()
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 = client.discussion.add_message(
message_type = MSG_TYPE.MSG_TYPE_FULL.value,
sender_type = SENDER_TYPES.SENDER_TYPES_USER.value,
sender = ump.replace(lollmsElfServer.config.discussion_prompt_separator,"").replace(":",""),
@ -146,10 +147,6 @@ def add_events(sio:socketio):
parent_message_id=lollmsElfServer.message_id
)
lollmsElfServer.busy=True
client_id = sid
client = lollmsElfServer.session.get_client(client_id)
command = data["command"]
parameters = data["parameters"]
lollmsElfServer.prepare_reception(client_id)
@ -169,4 +166,6 @@ def add_events(sio:socketio):
lollmsElfServer.busy=False
client.generation_thread = threading.Thread(target=do_generation)
client.generation_thread.start()
ASCIIColors.info("Started generation task")