diff --git a/convert_instructions_to_pdf.py b/convert_instructions_to_pdf.py new file mode 100644 index 000000000..deffdcb14 --- /dev/null +++ b/convert_instructions_to_pdf.py @@ -0,0 +1,49 @@ +import os +import subprocess +from pathlib import Path + +DOC_ROOT_DIR = "docs/source/" + +def convert_rst_to_pdf(rst_file_lst, output_path): + + for i,rst_file in enumerate(rst_file_lst): + + try: + # Run rst2pdf command using subprocess + file_name = rst_file.split("/")[-1] + file_name = file_name[:-4] + + if not Path(output_path+file_name+".pdf").is_file(): + output_file = output_path+file_name+".pdf" + + subprocess.run(['rst2pdf', rst_file, '-o', output_file], check=True) + print(f"Conversion successful. PDF saved to {output_path+file_name}") + + except subprocess.CalledProcessError as e: + print(f"Conversion failed. Error: {e}") + + if i%10 == 0: + print(f"Completed {i} files") + + + + + +def get_all_files_recursively(directory): + directory_path = Path(directory) + all_files = list(directory_path.rglob('*')) + return all_files + + +def convert_instr_to_pdf(): + + all_files_in_directory = get_all_files_recursively(DOC_ROOT_DIR) + all_files_in_directory = [str(f) for f in all_files_in_directory] + all_files_in_directory = [f for f in all_files_in_directory if f.endswith(".rst")] + + print(f"TOtal nos of files: {len(all_files_in_directory)}") + + os.mkdir("doc_pdf/") + convert_rst_to_pdf(all_files_in_directory, 'doc_pdf/') + + diff --git a/run_chatbot.py b/run_chatbot.py new file mode 100644 index 000000000..afceb6336 --- /dev/null +++ b/run_chatbot.py @@ -0,0 +1,51 @@ +import argparse +from convert_instructions_to_pdf import * +import os +from llama_index import VectorStoreIndex, SimpleDirectoryReader + + +parser = argparse.ArgumentParser(description='A chatbot for EvaDB') + +parser.add_argument("--reload_docs", help="Reload all the RST files and rebuild the index") +parser.add_argument("--open_ai_key", help="OpenAI key") + +args = parser.parse_args() + +reload_docs_flag = args.reload_docs +open_ai_key = args.open_ai_key + +os.environ["OPENAI_API_KEY"] = open_ai_key + + +if reload_docs_flag == "True": + print("Started reloading the docs") + convert_instr_to_pdf() + print("Finished reloading docs") + +#llama +print("Creating the Llama index.....") +documents = SimpleDirectoryReader("doc_pdf/").load_data() +index = VectorStoreIndex.from_documents(documents) + +query_engine = index.as_query_engine() + +print("Finished Creating the Llama index....") + + +while(True): + print("Welcome to EvaDB ") + print("Please enter your query. Enter 1 to exit the chatbot") + + user_query = input() + + if user_query == "1": + break + + else: + response = query_engine.query(user_query) + print(response) + + +print("Terminating the chatbot.. See you next time!") + +