enhanced core functionalities

This commit is contained in:
Saifeddine ALOUI 2024-05-08 18:36:49 +02:00
parent ce121276f0
commit 7ebb58cf2a
4 changed files with 16 additions and 12 deletions

View File

@ -165,9 +165,13 @@ class LollmsApplication(LoLLMsCom):
messages = client.discussion.get_messages()
# Extract relevant information from messages
def cb(str, MSG_TYPE, dict, list):
self.ShowBlockingMessage(f"Learning\n{str}")
def cb(str, MSG_TYPE_=MSG_TYPE.MSG_TYPE_FULL, dict=None, list=None):
if MSG_TYPE_!=MSG_TYPE.MSG_TYPE_CHUNK:
self.ShowBlockingMessage(f"Learning\n{str}")
bk_cb = self.tasks_library.callback
self.tasks_library.callback = cb
content = self._extract_content(messages, cb)
self.tasks_library.callback = bk_cb
# Generate title
title_prompt = "\n".join([
@ -707,7 +711,7 @@ class LollmsApplication(LoLLMsCom):
docs, sorted_similarities, document_ids = self.personality.internet_search_with_vectorization(query, self.config.internet_quick_search)
for doc, infos,document_id in zip(docs, sorted_similarities, document_ids):
internet_search_infos.append(document_id)
internet_search_results += f"search result chunk:\nchunk_infos:{document_id['url']}\nchunk_title:{document_id['title']}\ncontent:{doc}"
internet_search_results += f"!@>search result chunk:\nchunk_infos:{document_id['url']}\nchunk_title:{document_id['title']}\ncontent:{doc}\n"
if self.config.internet_quick_search:
self.personality.step_end("Performing Internet search (quick mode)")
else:

View File

@ -12,7 +12,7 @@ from lollms.com import LoLLMsCom
from safe_store import TextVectorizer, VisualizationMethod, GenericDataLoader
import json
import shutil
from lollms.tasks import TasksLibrary
__author__ = "parisneo"
__github__ = "https://github.com/ParisNeo/lollms-webui"
__copyright__ = "Copyright 2023, "
@ -626,6 +626,7 @@ class Message:
class Discussion:
def __init__(self, lollms:LoLLMsCom, discussion_id, discussions_db:DiscussionsDB):
self.lollms = lollms
self.current_message = None
self.discussion_id = discussion_id
self.discussions_db = discussions_db
self.discussion_folder = self.discussions_db.discussion_db_path/f"{discussion_id}"
@ -643,6 +644,7 @@ class Discussion:
self.discussion_rag_folder.mkdir(exist_ok=True)
self.discussion_view_images_folder.mkdir(exist_ok=True)
self.messages = self.get_messages()
self.whisper= None
if len(self.messages)>0:
self.current_message = self.messages[-1]
@ -721,14 +723,14 @@ class Discussion:
self.image_files.clear()
self.audio_files.clear()
def add_file(self, path, client, callback=None, process=True):
def add_file(self, path, client, tasks_library:TasksLibrary, callback=None, process=True):
output = ""
path = Path(path)
if path.suffix in [".wav",".mp3"]:
self.audio_files.append(path)
if process:
self.lollms.new_messagenew_message(client.client_id if client is not None else 0, content = "", message_type = MSG_TYPE.MSG_TYPE_FULL)
self.lollms.new_message(client.client_id if client is not None else 0, content = "", message_type = MSG_TYPE.MSG_TYPE_FULL)
self.lollms.info(f"Transcribing ... ")
if self.whisper is None:
if not PackageManager.check_package_installed("whisper"):
@ -745,10 +747,8 @@ class Discussion:
transcription_fn = str(path)+".txt"
with open(transcription_fn, "w", encoding="utf-8") as f:
f.write(result["text"])
tasks_library.info(f"Transcription saved to {transcription_fn}")
self.info(f"File saved to {transcription_fn}")
self.full(result["text"])
self.step_end("Transcribing ... ")
elif path.suffix in [".png",".jpg",".jpeg",".gif",".bmp",".svg",".webp"]:
self.image_files.append(path)
if process:

View File

@ -91,7 +91,7 @@ def edit_skill(skillInfos:SkillUpdateInfos):
def add_discussion_to_skills_library(discussionInfos:ClientInfos):
lollmsElfServer.ShowBlockingMessage("Learning...")
try:
client = lollmsElfServer.session.get_client(discussionInfos.client_id)
client = check_access(lollmsElfServer, discussionInfos.client_id)
category, title, content = lollmsElfServer.add_discussion_to_skills_library(client)
lollmsElfServer.InfoMessage(f"Discussion skill added to skills library:\nTitle: {title}\nCategory: {category}")
except Exception as ex:

View File

@ -108,9 +108,9 @@ def add_events(sio:socketio):
lollmsElfServer.ShowBlockingMessage(f"File received {file_path.name}.\nVectorizing the data ...")
if lollmsElfServer.personality.processor:
result = client.discussion.add_file(file_path, client, partial(lollmsElfServer.process_chunk, client_id=client_id))
result = client.discussion.add_file(file_path, client, lollmsElfServer.tasks_library, partial(lollmsElfServer.process_chunk, client_id=client_id))
else:
result = client.discussion.add_file(file_path, client, partial(lollmsElfServer.process_chunk, client_id=client_id))
result = client.discussion.add_file(file_path, client, lollmsElfServer.tasks_library, partial(lollmsElfServer.process_chunk, client_id=client_id))
ASCIIColors.success('File processed successfully')
run_async(partial(sio.emit,'file_received', {'status': True, 'filename': filename}))