From 33c119cd3a9601f0fae8ecac277e487673aca395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Thu, 28 May 2026 16:43:45 +0000 Subject: [PATCH] add main.py --- main.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..5640b38 --- /dev/null +++ b/main.py @@ -0,0 +1,77 @@ +"""CLI for the RAG agent with ChromaDB and Tavily web search. + +Commands: + /add - add text to local knowledge base + /load - load a .txt file into the knowledge base + /help - show available commands + /quit - exit + - ask the agent (auto-selects local KB or web) +""" +import sys +from dotenv import load_dotenv + +load_dotenv() + +from vectorstore import add_documents # noqa: E402 +from agent import run_agent # noqa: E402 + +HELP_TEXT = """ +Commands: + /add - add text to local ChromaDB knowledge base + /load - load a .txt file into the knowledge base + /help - show this help + /quit - exit + - ask the agent (uses Local KB or Web as appropriate) +""" + +def main() -> None: + print("RAG Agent: ChromaDB + Tavily Web Search") + print("Type /help for commands, /quit to exit.\n") + + while True: + try: + line = input("You: ").strip() + except (EOFError, KeyboardInterrupt): + print("\nExiting.") + sys.exit(0) + + if not line: + continue + + if line == "/quit": + print("Goodbye!") + break + + elif line == "/help": + print(HELP_TEXT) + + elif line.startswith("/add "): + text = line[5:].strip() + if not text: + print("Usage: /add ") + continue + n = add_documents([text]) + print(f"Added {n} chunk(s) to knowledge base.") + + elif line.startswith("/load "): + path = line[6:].strip() + try: + with open(path, encoding="utf-8") as fh: + content = fh.read() + n = add_documents([content]) + print(f"Loaded '{path}': {n} chunk(s) added.") + except FileNotFoundError: + print(f"File not found: {path}") + except Exception as exc: + print(f"Error: {exc}") + + else: + try: + response = run_agent(line) + print(f"Agent: {response}\n") + except Exception as exc: + print(f"Agent error: {exc}") + + +if __name__ == "__main__": + main()