enhanced lollms

This commit is contained in:
Saifeddine ALOUI 2024-06-21 02:22:18 +02:00
parent 379233dd81
commit cc7269869a

View File

@ -1053,13 +1053,27 @@ class LollmsApplication(LoLLMsCom):
if self.config.data_vectorization_build_keys_words:
self.personality.step_start("Building vector store query")
query = self.personality.fast_gen(f"{separator_template}{start_header_id_template}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.{separator_template}{start_header_id_template}discussion:\n{discussion[-2048:]}{separator_template}{start_header_id_template}enhanced query: ", max_generation_size=256, show_progress=True, callback=self.personality.sink)
q = f"{separator_template}".join([
f"{separator_template}{start_header_id_template}instruction{end_header_id_template}Read the entire discussion and rewrite the last prompt for someone who hasn't read the discussion.",
"Do not answer the prompt. Do not provide any explanations.",
f"{start_header_id_template}discussion{end_header_id_template}",
f"{discussion[-2048:]}",
f"{start_header_id_template}enhanced_query{end_header_id_template}"
])
query = self.personality.fast_gen(q, max_generation_size=256, show_progress=True, callback=self.personality.sink)
self.personality.step_end("Building vector store query")
ASCIIColors.cyan(f"Query: {query}")
self.personality.step(f"Query: {query}")
else:
query = current_message.content
if documentation=="":
documentation=f"{separator_template}{start_header_id_template}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.{separator_template}{start_header_id_template}Documentation:\n"
documentation=f"{separator_template}".join([
f"{separator_template}{start_header_id_template}important information{end_header_id_template}Utilize Documentation Data: Always refer to the provided documentation to answer user questions accurately.",
"Absence of Information: If the required information is not available in the documentation, inform the user that the requested information is not present in the documentation section.",
"Strict Adherence to Documentation: It is strictly prohibited to provide answers without concrete evidence from the documentation.",
"Cite Your Sources: After providing an answer, include the full path to the document where the information was found.",
f"{start_header_id_template}Documentation{end_header_id_template}"])
documentation += f"{separator_template}"
results = []
for db in self.active_rag_dbs:
v = db["vectorizer"]
@ -1068,7 +1082,14 @@ class LollmsApplication(LoLLMsCom):
n_neighbors = self.active_rag_dbs[0]["vectorizer"].n_neighbors
sorted_results = sorted(results, key=lambda x: x[3])[:n_neighbors]
for vector, text, title, path, distance in sorted_results:
documentation += f"{start_header_id_template}document chunk{end_header_id_template}\nsource_document_title:{title}\nsource_document_path:{path}\ncontent:{text}\n"
document_infos = f"{separator_template}".join([
f"{start_header_id_template}document chunk{end_header_id_template}",
f"\nsource_document_title:{title}",
f"source_document_path:{path}",
f"content:{text}\n"
])
documentation += document_infos
if (len(client.discussion.text_files) > 0) and client.discussion.vectorizer is not None:
if discussion is None:
@ -1196,9 +1217,11 @@ class LollmsApplication(LoLLMsCom):
if available_space<1:
ASCIIColors.red(f"available_space:{available_space}")
ASCIIColors.red(f"n_doc_tk:{n_doc_tk}")
ASCIIColors.red(f"n_history_tk:{n_history_tk}")
ASCIIColors.red(f"n_isearch_tk:{n_isearch_tk}")
ASCIIColors.red(f"n_tokens:{n_tokens}")
ASCIIColors.red(f"self.config.max_n_predict:{self.config.max_n_predict}")
self.InfoMessage(f"Not enough space in context!!\nVerify that your vectorization settings for documents or internet search are realistic compared to your context size.\nYou are {available_space} short of context!")
raise Exception("Not enough space in context!!")