enhanced backend

This commit is contained in:
Saifeddine ALOUI 2024-01-24 20:30:12 +01:00
parent f4e5aa3d7a
commit a1ffac42b6
2 changed files with 48 additions and 11 deletions

View File

@ -36,11 +36,12 @@ class NotificationDisplayType(Enum):
class LoLLMsCom:
def __init__(self, sio:socketio.AsyncServer=None) -> None:
def __init__(self, sio:socketio.AsyncServer=None, verbose:bool=False) -> None:
self.sio= sio
self.verbose = verbose
def InfoMessage(self, content, client_id=None, verbose:bool=True):
def InfoMessage(self, content, client_id=None, verbose:bool=None):
self.notify(
content,
notification_type=NotificationType.NOTIF_SUCCESS,
@ -49,7 +50,7 @@ class LoLLMsCom:
display_type=NotificationDisplayType.MESSAGE_BOX,
verbose=verbose
)
def ShowBlockingMessage(self, content, client_id=None, verbose:bool=True):
def ShowBlockingMessage(self, content, client_id=None, verbose:bool=None):
self.notify(
content,
notification_type=NotificationType.NOTIF_SUCCESS,
@ -59,7 +60,7 @@ class LoLLMsCom:
verbose=verbose
)
def HideBlockingMessage(self, client_id=None, verbose:bool=True):
def HideBlockingMessage(self, client_id=None, verbose:bool=None):
self.notify(
"",
notification_type=NotificationType.NOTIF_SUCCESS,
@ -71,7 +72,7 @@ class LoLLMsCom:
def YesNoMessage(self, content, duration:int=4, client_id=None, verbose:bool=True):
def YesNoMessage(self, content, duration:int=4, client_id=None, verbose:bool=None):
infos={
"wait":True,
"result":False
@ -95,7 +96,7 @@ class LoLLMsCom:
self.sio.sleep(1)
return infos["result"]
def info(self, content, duration:int=4, client_id=None, verbose:bool=True):
def info(self, content, duration:int=4, client_id=None, verbose:bool=None):
self.notify(
content,
notification_type=NotificationType.NOTIF_SUCCESS,
@ -105,7 +106,7 @@ class LoLLMsCom:
verbose=verbose
)
def warning(self, content, duration:int=4, client_id=None, verbose:bool=True):
def warning(self, content, duration:int=4, client_id=None, verbose:bool=None):
self.notify(
content,
notification_type=NotificationType.NOTIF_WARNING,
@ -115,7 +116,7 @@ class LoLLMsCom:
verbose=verbose
)
def success(self, content, duration:int=4, client_id=None, verbose:bool=True):
def success(self, content, duration:int=4, client_id=None, verbose:bool=None):
self.notify(
content,
notification_type=NotificationType.NOTIF_SUCCESS,
@ -125,7 +126,7 @@ class LoLLMsCom:
verbose=verbose
)
def error(self, content, duration:int=4, client_id=None, verbose:bool=True):
def error(self, content, duration:int=4, client_id=None, verbose:bool=None):
self.notify(
content,
notification_type=NotificationType.NOTIF_ERROR,
@ -143,8 +144,11 @@ class LoLLMsCom:
duration:int=4,
client_id=None,
display_type:NotificationDisplayType=NotificationDisplayType.TOAST,
verbose=True
verbose:bool|None=None
):
if verbose is None:
verbose = self.verbose
if verbose:
if notification_type==NotificationType.NOTIF_SUCCESS:
ASCIIColors.success(content)

View File

@ -37,6 +37,26 @@ from lollms.com import LoLLMsCom
from lollms.helpers import trace_exception
from lollms.utilities import PackageManager
import requests
from bs4 import BeautifulSoup
def get_element_id(url, text):
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
element = soup.find('span', text=text)
if element:
return element['id']
else:
return None
def craft_a_tag_to_specific_text(url, text):
element_id = get_element_id(url, text)
if element_id:
return f'<a href="{url}#{element_id}">Click me to go to {text}</a>'
else:
return None
def is_package_installed(package_name):
try:
dist = pkg_resources.get_distribution(package_name)
@ -1916,7 +1936,20 @@ class APScript(StateMachine):
print(f"Error retrieving webpage content for {result['href']}: {str(e)}")
return answer_list
def translate(self, text_chunk, output_language="french", max_generation_size=3000):
translated = self.remove_backticks(
f"```markdown\n"+ self.fast_gen(
"\n".join([
f"!@>system:",
f"Translate the following text to {output_language}.",
"Be faithful to the original text and do not add or remove any information.",
f"!@>text to translate:",
f"{text_chunk}",
f"!@>Translation:",
f"```markdown\n"
]),
max_generation_size=max_generation_size))
return translated
def summerize(self, chunks, summary_instruction="summerize", chunk_name="chunk", answer_start="", max_generation_size=3000):
summeries = []
for i, chunk in enumerate(chunks):