synced with new safestore

This commit is contained in:
Saifeddine ALOUI 2024-02-10 21:35:27 +01:00
parent 526ab46c4d
commit b4c37b6983
13 changed files with 322 additions and 257 deletions

View File

@ -1,5 +1,5 @@
# =================== Lord Of Large Language Multimodal Systems Configuration file ===========================
version: 55
version: 56
binding_name: null
model_name: null
@ -125,7 +125,8 @@ internet_vectorization_chunk_size: 512 # chunk size
internet_vectorization_overlap_size: 128 # overlap between chunks size
internet_vectorization_nb_chunks: 2 # number of chunks to use
internet_nb_search_pages: 3 # number of pages to select
internet_quick_search: False # If active the search engine will not load and read the webpages
internet_activate_search_decision: False # If active the ai decides by itself if it needs to do search
# Helpers
pdf_latex_path: null

@ -1 +1 @@
Subproject commit eda4d02626106d36553c63b9837489e3fe567608
Subproject commit 7551e7fa021a9526239fda2ca0814583791c35c2

View File

@ -688,7 +688,8 @@ class LOLLMSWebUI(LOLLMSElfServer):
Returns:
Tuple[str, str, List[str]]: The prepared query, original message content, and tokenized query.
"""
if self.personality.callback is None:
self.personality.callback = partial(self.process_chunk, client_id=client_id)
# Get the list of messages
messages = self.connections[client_id]["current_discussion"].get_messages()
@ -706,8 +707,8 @@ class LOLLMSWebUI(LOLLMSElfServer):
conditionning = self.personality.personality_conditioning
# Check if there are document files to add to the prompt
internet_search_rsults = ""
internet_search_sources = []
internet_search_results = ""
internet_search_infos = []
documentation = ""
knowledge = ""
@ -745,19 +746,28 @@ class LOLLMSWebUI(LOLLMSElfServer):
if generation_type != "simple_question":
if self.config.activate_internet_search:
self.personality.callback = partial(self.process_chunk, client_id=client_id)
if discussion is None:
discussion = self.recover_discussion(client_id)[-512:]
self.personality.step_start("Crafting internet search query")
internet_search_rsults="!@>important information: Use the internet search results data to answer the user query. If the data is not present in the search, please tell the user that the information he is asking for was not found and he may need to increase the number of search pages from the settings. It is strictly forbidden to give the user an answer without having actual proof from the documentation.\n!@>Search results:\n"
query = self.personality.fast_gen(f"\n!@>instruction: Read the discussion and craft a web search query suited to recover needed information to answer the user.\nDo not answer the prompt. Do not add explanations.\n!@>discussion:\n{discussion}\n!@>websearch query: ", max_generation_size=256, show_progress=True)
self.personality.step_end("Crafting internet search query")
self.personality.step_start("Performing Internet search")
docs, sorted_similarities = self.personality.internet_search(query)
for doc, infos in zip(docs, sorted_similarities):
internet_search_sources.append(infos[0])
internet_search_rsults += f"search result chunk:\n{doc}"
self.personality.step_end("Performing INternet search")
discussion = self.recover_discussion(client_id)
if self.config.internet_activate_search_decision:
self.personality.step_start(f"Requesting if {self.personality.name} needs to search internet to answer the user")
need = not self.personality.yes_no(f"Are you able to fulfill {self.config.user_name}'s request without internet search?\nIf he is asking for information that can be found on internet please answer 0 (no).", discussion)
self.personality.step_end(f"Requesting if {self.personality.name} needs to search internet to answer the user")
self.personality.step("Yes" if need else "No")
else:
need=True
if need:
self.personality.step_start("Crafting internet search query")
query = self.personality.fast_gen(f"!@>discussion:\n{discussion[-2048:]}\n!@>instruction: Read the discussion and craft a web search query suited to recover needed information to reply to last {self.config.user_name} message.\nDo not answer the prompt. Do not add explanations.\n!@>websearch query: ", max_generation_size=256, show_progress=True)
self.personality.step_end("Crafting internet search query")
self.personality.step_start("Performing Internet search")
internet_search_results=f"!@>important information: Use the internet search results data to answer {self.config.user_name}'s last message. It is strictly forbidden to give the user an answer without having actual proof from the documentation.\n!@>Web search results:\n"
docs, sorted_similarities, document_ids = self.personality.internet_search(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}"
self.personality.step_end("Performing Internet search")
if self.personality.persona_data_vectorizer:
if documentation=="":
@ -765,15 +775,15 @@ class LOLLMSWebUI(LOLLMSElfServer):
if self.config.data_vectorization_build_keys_words:
if discussion is None:
discussion = self.recover_discussion(client_id)[-512:]
query = self.personality.fast_gen(f"\n!@>instruction: Read the discussion and rewrite the last prompt for someone who didn't read the entire discussion.\nDo not answer the prompt. Do not add explanations.\n!@>discussion:\n{discussion}\n!@>enhanced query: ", max_generation_size=256, show_progress=True)
discussion = self.recover_discussion(client_id)
query = self.personality.fast_gen(f"\n!@>instruction: Read the discussion and rewrite the last prompt for someone who didn't read the entire discussion.\nDo not answer the prompt. Do not add explanations.\n!@>discussion:\n{discussion[-2048:]}\n!@>enhanced query: ", max_generation_size=256, show_progress=True)
ASCIIColors.cyan(f"Query:{query}")
else:
query = current_message.content
try:
docs, sorted_similarities = self.personality.persona_data_vectorizer.recover_text(query, top_k=self.config.data_vectorization_nb_chunks)
for doc, infos in zip(docs, sorted_similarities):
documentation += f"document chunk:\n{doc}"
docs, sorted_similarities, document_ids = self.personality.persona_data_vectorizer.recover_text(query, top_k=self.config.data_vectorization_nb_chunks)
for doc, infos, doc_id in zip(docs, sorted_similarities, document_ids):
documentation += f"document chunk:\nchunk_infos:{infos}\ncontent:{doc}"
except:
self.warning("Couldn't add documentation to the context. Please verify the vector database")
@ -782,14 +792,14 @@ class LOLLMSWebUI(LOLLMSElfServer):
documentation="\n!@>important information: Use the documentation data to answer the user questions. If the data is not present in the documentation, please tell the user that the information he is asking for does not exist in the documentation section. It is strictly forbidden to give the user an answer without having actual proof from the documentation.\n!@>Documentation:\n"
if self.config.data_vectorization_build_keys_words:
discussion = self.recover_discussion(client_id)[-512:]
query = self.personality.fast_gen(f"\n!@>instruction: Read the discussion and rewrite the last prompt for someone who didn't read the entire discussion.\nDo not answer the prompt. Do not add explanations.\n!@>discussion:\n{discussion}\n!@>enhanced query: ", max_generation_size=256, show_progress=True)
discussion = self.recover_discussion(client_id)
query = self.personality.fast_gen(f"\n!@>instruction: Read the discussion and rewrite the last prompt for someone who didn't read the entire discussion.\nDo not answer the prompt. Do not add explanations.\n!@>discussion:\n{discussion[-2048:]}\n!@>enhanced query: ", max_generation_size=256, show_progress=True)
ASCIIColors.cyan(f"Query:{query}")
else:
query = current_message.content
try:
docs, sorted_similarities = self.personality.vectorizer.recover_text(query, top_k=self.config.data_vectorization_nb_chunks)
docs, sorted_similarities, document_ids = self.personality.vectorizer.recover_text(query, top_k=self.config.data_vectorization_nb_chunks)
for doc, infos in zip(docs, sorted_similarities):
documentation += f"document chunk:\nchunk path: {infos[0]}\nchunk content:{doc}"
documentation += "\n!@>important information: Use the documentation data to answer the user questions. If the data is not present in the documentation, please tell the user that the information he is asking for does not exist in the documentation section. It is strictly forbidden to give the user an answer without having actual proof from the documentation."
@ -801,7 +811,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
knowledge="!@>knowledge:\n"
try:
docs, sorted_similarities = self.long_term_memory.recover_text(current_message.content, top_k=self.config.data_vectorization_nb_chunks)
docs, sorted_similarities, document_ids = self.long_term_memory.recover_text(current_message.content, top_k=self.config.data_vectorization_nb_chunks)
for i,(doc, infos) in enumerate(zip(docs, sorted_similarities)):
knowledge += f"!@>knowledge {i}:\n!@>title:\n{infos[0]}\ncontent:\n{doc}"
except:
@ -817,11 +827,11 @@ class LOLLMSWebUI(LOLLMSElfServer):
# Tokenize the internet search results text and calculate its number of tokens
if len(internet_search_rsults)>0:
tokens_internet_search_rsults = self.model.tokenize(internet_search_rsults)
n_isearch_tk = len(tokens_internet_search_rsults)
if len(internet_search_results)>0:
tokens_internet_search_results = self.model.tokenize(internet_search_results)
n_isearch_tk = len(tokens_internet_search_results)
else:
tokens_internet_search_rsults = []
tokens_internet_search_results = []
n_isearch_tk = 0
@ -931,7 +941,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
else:
ai_prefix = ""
# Build the final prompt by concatenating the conditionning and discussion messages
prompt_data = conditionning + internet_search_rsults + documentation + knowledge + user_description + discussion_messages + positive_boost + negative_boost + force_language + fun_mode + ai_prefix
prompt_data = conditionning + internet_search_results + documentation + knowledge + user_description + discussion_messages + positive_boost + negative_boost + force_language + fun_mode + ai_prefix
# Tokenize the prompt data
tokens = self.model.tokenize(prompt_data)
@ -941,7 +951,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
ASCIIColors.bold("CONDITIONNING")
ASCIIColors.yellow(conditionning)
ASCIIColors.bold("INTERNET SEARCH")
ASCIIColors.yellow(internet_search_rsults)
ASCIIColors.yellow(internet_search_results)
ASCIIColors.bold("DOC")
ASCIIColors.yellow(documentation)
ASCIIColors.bold("HISTORY")
@ -958,8 +968,8 @@ class LOLLMSWebUI(LOLLMSElfServer):
# Details
context_details = {
"conditionning":conditionning,
"internet_search_sources":internet_search_sources,
"internet_search_rsults":internet_search_rsults,
"internet_search_infos":internet_search_infos,
"internet_search_results":internet_search_results,
"documentation":documentation,
"knowledge":knowledge,
"user_description":user_description,
@ -973,7 +983,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
}
# Return the prepared query, original message content, and tokenized query
return prompt_data, current_message.content, tokens, context_details, internet_search_sources
return prompt_data, current_message.content, tokens, context_details, internet_search_infos
def get_discussion_to(self, client_id, message_id=-1):
@ -1210,6 +1220,9 @@ class LOLLMSWebUI(LOLLMSElfServer):
if self.nb_received_tokens==0:
self.start_time = datetime.now()
self.update_message(client_id, "✍ warming up ...", msg_type=MSG_TYPE.MSG_TYPE_STEP_END, parameters= {'status':True})
self.update_message(client_id, "Generating ...", msg_type=MSG_TYPE.MSG_TYPE_STEP_START)
dt =(datetime.now() - self.start_time).seconds
if dt==0:
dt=1
@ -1378,7 +1391,7 @@ class LOLLMSWebUI(LOLLMSElfServer):
self.update_message(client_id, "✍ warming up ...", msg_type=MSG_TYPE.MSG_TYPE_STEP_START)
# prepare query and reception
self.discussion_messages, self.current_message, tokens, context_details, internet_search_sources = self.prepare_query(client_id, message_id, is_continue, n_tokens=self.config.min_n_predict, generation_type=generation_type)
self.discussion_messages, self.current_message, tokens, context_details, internet_search_infos = self.prepare_query(client_id, message_id, is_continue, n_tokens=self.config.min_n_predict, generation_type=generation_type)
self.prepare_reception(client_id)
self.generating = True
self.connections[client_id]["processing"]=True
@ -1459,22 +1472,23 @@ class LOLLMSWebUI(LOLLMSElfServer):
from lollms.internet import get_favicon_url, get_root_url
sources_text = '<div class="mt-4 flex flex-wrap items-center gap-x-2 gap-y-1.5 text-sm ">'
sources_text += '<div class="text-gray-400 mr-10px">Sources:</div>'
for source in internet_search_sources:
url = "/".join(source.split("/")[:-1])
for source in internet_search_infos:
url = source["url"]
favicon_url = get_favicon_url(url)
if favicon_url is None:
favicon_url ="/personalities/internet/loi/assets/logo.png"
root_url = get_root_url(url)
sources_text += "\n".join([
f'<a class="flex items-center gap-2 whitespace-nowrap rounded-lg border bg-white px-2 py-1.5 leading-none hover:border-gray-300 dark:border-gray-800 dark:bg-gray-900 dark:hover:border-gray-700" target="_blank" href="{url}">',
f'<img class="h-3.5 w-3.5 rounded" src="{favicon_url}">'
f'<div>{root_url}</div>'
f' <img class="h-3.5 w-3.5 rounded" src="{favicon_url}">',
f' <div>{root_url}</div>',
f'</a>',
])
sources_text += '</div>'
self.connections[client_id]["generated_text"]=self.connections[client_id]["generated_text"].split("!@>")[0] + "\n" + sources_text
self.personality.full(self.connections[client_id]["generated_text"])
self.close_message(client_id)
self.update_message(client_id, "Generating ...", msg_type=MSG_TYPE.MSG_TYPE_STEP_END)
self.connections[client_id]["processing"]=False
if self.connections[client_id]["schedule_for_deletion"]:

@ -1 +1 @@
Subproject commit b050a331440bd1c5e6daa9ed3607f41f52503335
Subproject commit 7311d3acc18f4fdc2d79f74e1f4e3426ed6d9851

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

8
web/dist/assets/index-822a6900.css vendored Normal file

File diff suppressed because one or more lines are too long

4
web/dist/index.html vendored
View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-5a9814a4.js"></script>
<link rel="stylesheet" href="/assets/index-5504ec28.css">
<script type="module" crossorigin src="/assets/index-1e833b9c.js"></script>
<link rel="stylesheet" href="/assets/index-822a6900.css">
</head>
<body>
<div id="app"></div>

View File

@ -94,6 +94,11 @@
@click="clear_files">
<i data-feather="trash" class="w-5 h-5 "></i>
</button>
<button type="button" title="Clear all"
class="flex items-center p-0.5 text-sm rounded-sm hover:text-red-600 active:scale-75"
@click="download_database">
<i data-feather="download-cloud" class="w-5 h-5 "></i>
</button>
</div>
<div v-if="showPersonalities" class="mx-1">
<MountedPersonalitiesList ref="mountedPersList"
@ -655,6 +660,14 @@ export default {
});
},
download_database(){
axios.get('/download_database')
},
remove_file(file){
axios.get('/remove_file',{name: file}).then(res=>{
console.log(res)
})
},
clear_files(){
axios.get('/clear_personality_files_list').then(res=>{
console.log(res)
@ -662,6 +675,7 @@ export default {
this.$store.state.toast.showToast("File removed successfully",4,true);
this.filesList.length = 0;
this.isFileSentList.length = 0;
this.totalSize = 0;
}
else{
this.$store.state.toast.showToast("Files couldn't be removed",4,false);

View File

@ -1,7 +1,5 @@
<template>
<div class="flex items-start">
<div class="-ml-1.5 h-3 w-3 flex-none rounded-full bg-gray-200 dark:bg-gray-600 ">
</div>
<div class="step flex items-center mb-4">
<div class="flex items-center justify-center w-6 h-6 mr-2">
<div v-if="!done">
@ -34,7 +32,7 @@
fill="currentFill" />
</svg>
</div>
<h3 class="text-md -mt-1.5 pl-2.5 text-gray-800 dark:text-gray-100" :class="{'text-green-500': done, 'text-yellow-500': !done}">{{ message }}</h3>
<h3 class="text-sm" >{{ message }}</h3>
</div>
</div>
</template>

View File

@ -1258,11 +1258,15 @@ export default {
else if(messageItem && msgObj.message_type==this.msgTypes.MSG_TYPE_CHUNK){
messageItem.content += msgObj.content
} else if (msgObj.message_type == this.msgTypes.MSG_TYPE_STEP){
console.log("received step")
messageItem.status_message = msgObj.content
messageItem.steps.push({"message":msgObj.content,"done":true, "status":true })
} else if (msgObj.message_type == this.msgTypes.MSG_TYPE_STEP_START){
console.log("received step start")
messageItem.status_message = msgObj.content
messageItem.steps.push({"message":msgObj.content,"done":false, "status":true })
} else if (msgObj.message_type == this.msgTypes.MSG_TYPE_STEP_END) {
console.log("received step end")
// Find the step with the matching message and update its 'done' property to true
const matchingStep = messageItem.steps.find(step => step.message === msgObj.content);

View File

@ -715,6 +715,40 @@
</td>
</tr>
<tr>
<td style="min-width: 200px;">
<label for="internet_quick_search" class="text-sm font-bold" style="margin-right: 1rem;">Activate quick search:</label>
</td>
<td>
<div class="flex flex-row">
<input
type="checkbox"
id="internet_quick_search"
required
v-model="configFile.internet_quick_search"
@change="settingsChanged=true"
class="mt-1 px-2 py-1 border border-gray-300 rounded dark:bg-gray-600"
>
</div>
</td>
</tr>
<tr>
<td style="min-width: 200px;">
<label for="internet_activate_search_decision" class="text-sm font-bold" style="margin-right: 1rem;">Activate search decision:</label>
</td>
<td>
<div class="flex flex-row">
<input
type="checkbox"
id="internet_activate_search_decision"
required
v-model="configFile.internet_activate_search_decision"
@change="settingsChanged=true"
class="mt-1 px-2 py-1 border border-gray-300 rounded dark:bg-gray-600"
>
</div>
</td>
</tr>
<tr>
<td style="min-width: 200px;">
<label for="internet_vectorization_chunk_size" class="text-sm font-bold" style="margin-right: 1rem;">Internet vectorization chunk size:</label>
</td>
@ -741,7 +775,7 @@
<div class="flex flex-col">
<input id="internet_vectorization_overlap_size" v-model="configFile.internet_vectorization_overlap_size"
@change="settingsChanged=true"
type="range" min="0" max="64000" step="1"
type="range" min="0" max="1000" step="1"
class="flex-none h-2 mt-14 mb-2 w-full bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700 focus:ring-blue-500 focus:border-blue-500 dark:border-gray-600 dark:placeholder-gray-400 dark:focus:ring-blue-500 dark:focus:border-blue-500">
<input v-model="configFile.internet_vectorization_overlap_size"
@ -760,7 +794,7 @@
<div class="flex flex-col">
<input id="internet_vectorization_nb_chunks" v-model="configFile.internet_vectorization_nb_chunks"
@change="settingsChanged=true"
type="range" min="0" max="64000" step="1"
type="range" min="0" max="100" step="1"
class="flex-none h-2 mt-14 mb-2 w-full bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700 focus:ring-blue-500 focus:border-blue-500 dark:border-gray-600 dark:placeholder-gray-400 dark:focus:ring-blue-500 dark:focus:border-blue-500">
<input v-model="configFile.internet_vectorization_nb_chunks"
@ -779,7 +813,7 @@
<div class="flex flex-col">
<input id="internet_nb_search_pages" v-model="configFile.internet_nb_search_pages"
@change="settingsChanged=true"
type="range" min="0" max="64000" step="1"
type="range" min="1" max="100" step="1"
class="flex-none h-2 mt-14 mb-2 w-full bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700 focus:ring-blue-500 focus:border-blue-500 dark:border-gray-600 dark:placeholder-gray-400 dark:focus:ring-blue-500 dark:focus:border-blue-500">
<input v-model="configFile.internet_nb_search_pages"

@ -1 +1 @@
Subproject commit 70851b43376a8a6cb1270bf076b969a877f678d4
Subproject commit cd9661448f09f70f59c73bf513dd7052f1e147fc