From 05c6945b4e703da6eca5e4bac2c8fe1a4e32b6cb Mon Sep 17 00:00:00 2001 From: Stu Carney Date: Tue, 11 Jul 2023 10:57:37 -0500 Subject: [PATCH] Minor suggested updates to askmyfiles.py --- askmyfiles.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/askmyfiles.py b/askmyfiles.py index 3f218d2..977ee28 100755 --- a/askmyfiles.py +++ b/askmyfiles.py @@ -93,7 +93,7 @@ def process_query_result(self, documents): ### End Excerpt from file source {documents['metadatas'][0][index]['source']}""") return [references, self.join_strings(output)[:max_chars]] - def query_db(self, string, max_chars=None): + def query_db(self, string): max_results = 100 self.load_db() query_embedding = self.embeddings_model.embed_query(string) @@ -275,7 +275,6 @@ def add_webpage(self, url): print(f"Creating embeddings...",end='',flush=True) chunks = self.split_text(content) - chunk_count = len(chunks) print(f"[{len(chunks)} chunks]",end='',flush=True) vectorized_chunks = self.vectorize_chunks(chunks, metadata) self.files_collection.delete(where={"file_hash": metadata["file_hash"]}) @@ -318,7 +317,6 @@ def process_file(self,file_path): return False chunks = self.split_text(content) - chunk_count = len(chunks) print(f"[{len(chunks)} chunks]",end='',flush=True) # Vectorize Chunks @@ -344,9 +342,6 @@ def load_files(self): file_saved = False saved_files = file_saved or saved_files - if saved_files: - self.persist_db() - return saved_files def get_hints(self): @@ -375,8 +370,9 @@ def ask(self, query): [ Start with and prioritize knowledge from My askmyfiles Library when you answer my question. Answer in a very detailed manner when possible. - If the question is regarding code: prefer to answer using service objects and other abstractions already defined in MyAskmyfilesLibrary and follow similar coding conventions. - If the question is regarding code: identify if there is a tags file present to inform your answers about modules, classes, and methods. + If the question is regarding code: + 1. Try to answer using service objects and other abstractions already defined in MyAskmyfilesLibrary and follow similar coding conventions. + 2. Identify if there is a tags file present to inform your answer about modules, classes, and methods. ] ### Question: {text} @@ -395,6 +391,11 @@ def ask(self, query): if index != -1: sources = text[index + len("Sources:"):] + second_pass_query_db = f""" + {query} + {first_answer} + """ + second_pass_query = f""" [ Consider the following first question and answer: @@ -407,7 +408,7 @@ def ask(self, query): """ print("THINKING MORE...", end='', flush=True) - local_query_result2 = self.query_db(second_pass_query) + local_query_result2 = self.query_db(second_pass_query_db) second_answer = answer_chain.run(excerpts=local_query_result2[1],hints=self.get_hints(),text=second_pass_query) # Output