Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChatBot for EvaDB #1436

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions convert_instructions_to_pdf.py
Original file line number Diff line number Diff line change
@@ -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/')


51 changes: 51 additions & 0 deletions run_chatbot.py
Original file line number Diff line number Diff line change
@@ -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!")