Add main.py
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
import argparse
|
||||
from dotenv import load_dotenv
|
||||
from vectorstore import VectorStore
|
||||
from agent import get_agent
|
||||
|
||||
|
||||
def main():
|
||||
load_dotenv()
|
||||
parser = argparse.ArgumentParser(description="RAG Agent CLI")
|
||||
parser.add_argument("--docs_dir", type=str, default=None, help="Directory with documents to load")
|
||||
args = parser.parse_args()
|
||||
|
||||
vectorstore = VectorStore()
|
||||
if args.docs_dir:
|
||||
if os.path.isdir(args.docs_dir):
|
||||
print(f"Loading documents from {args.docs_dir}...")
|
||||
vectorstore.add_documents(args.docs_dir)
|
||||
print("Documents loaded and indexed.")
|
||||
else:
|
||||
print(f"Documents directory {args.docs_dir} does not exist.")
|
||||
agent = get_agent(vectorstore)
|
||||
|
||||
print("RAG Agent ready. Type your query or 'exit' to quit.")
|
||||
try:
|
||||
while True:
|
||||
query = input("You: ")
|
||||
if query.lower() in ("exit", "quit"):
|
||||
print("Goodbye!")
|
||||
break
|
||||
try:
|
||||
response = agent.run(query)
|
||||
print(f"Agent: {response}")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
except KeyboardInterrupt:
|
||||
print("\nInterrupted. Exiting.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user