From 6d81aced8ce093f83f198cd3154269e5a8b246f1 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 13:32:46 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20ma?= =?UTF-8?q?in.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 82 --------------------------------------------------------- 1 file changed, 82 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index 206b3fe..0000000 --- a/main.py +++ /dev/null @@ -1,82 +0,0 @@ -""" -CLI for interacting with the RAG agent. - -Commands: - /add – add document to knowledge base - /search – search knowledge base - /quit – exit - -Optional argument: --load-dir DIR – load all .txt files from directory at start. -""" - -import argparse -import sys -from pathlib import Path - -from rag_agent import agent, add_to_knowledge_base, search_knowledge_base -from langchain_core.messages import HumanMessage - - -def load_directory(dir_path: str): - """Load all .txt files from a directory into the knowledge base.""" - p = Path(dir_path) - if not p.is_dir(): - print(f"{dir_path} is not a directory") - return - for txt_file in p.rglob("*.txt"): - try: - content = txt_file.read_text(encoding="utf-8") - title = txt_file.stem - add_to_knowledge_base(content=content, title=title) - print(f"Loaded {txt_file}") - except Exception as e: - print(f"Failed to load {txt_file}: {e}") - - -def main(): - parser = argparse.ArgumentParser(description="RAG agent CLI") - parser.add_argument("--load-dir", type=str, help="Directory with .txt files to preload") - args = parser.parse_args() - - if args.load_dir: - load_directory(args.load_dir) - - print("Enter commands (/add , /search , /quit). Press Ctrl+C to exit.") - while True: - try: - line = input(">>> ").strip() - except (EOFError, KeyboardInterrupt): - print("\nExiting.") - break - if not line: - continue - if line.lower() == "/quit": - print("Bye!") - break - if line.startswith("/add "): - path = line[5:].strip() - try: - content = Path(path).read_text(encoding="utf-8") - title = Path(path).stem - res = add_to_knowledge_base(content=content, title=title) - print(res) - except Exception as e: - print(f"Error adding file: {e}") - elif line.startswith("/search "): - query = line[8:].strip() - try: - res = search_knowledge_base(query=query, max_results=5) - print(res) - except Exception as e: - print(f"Error searching: {e}") - else: - # Treat any other input as a message to the agent - try: - result = agent.ainvoke({"messages": [HumanMessage(content=line)]}) - print(result["messages"][-1].content) - except Exception as e: - print(f"Agent error: {e}") - -if __name__ == "__main__": - import asyncio - asyncio.run(main())