#!/usr/bin/env python3 """Quick start script for Agentic RAG system""" import os import sys import json from pathlib import Path def check_environment(): """Check if environment is properly configured""" print("šŸ” Checking environment...") # Check for .env file if not Path(".env").exists() and Path(".env.example").exists(): print("šŸ“ Creating .env from .env.example") import shutil shutil.copy(".env.example", ".env") print("āš ļø Please edit .env and add your API keys") return False # Load environment variables from dotenv import load_dotenv load_dotenv() # Check for at least one API key providers = ["MOONSHOT_API_KEY", "ARK_API_KEY", "DASHSCOPE_API_KEY", "SILICONFLOW_API_KEY", "OPENAI_API_KEY", "OPENROUTER_API_KEY"] has_key = False for provider in providers: if os.getenv(provider): has_key = True print(f"āœ… Found {provider}") break if not has_key: print("āŒ No API keys found. Please set at least one in .env file:") print(" - MOONSHOT_API_KEY for Kimi") print(" - ARK_API_KEY for Doubao") print(" - SILICONFLOW_API_KEY for SiliconFlow") print(" - OPENAI_API_KEY for OpenAI") return False return True def setup_demo_documents(): """Create demo documents if they don't exist""" print("\nšŸ“š Setting up demo documents...") eval_dir = Path("evaluation") eval_dir.mkdir(exist_ok=True) # Check if documents already exist doc_file = eval_dir / "legal_documents.json" dataset_file = eval_dir / "legal_qa_dataset.json" if not doc_file.exists() or not dataset_file.exists(): print("šŸ“„ Generating legal documents and dataset...") os.chdir("evaluation") os.system("python dataset_builder.py") os.chdir("..") print("āœ… Documents generated") else: print("āœ… Documents already exist") return doc_file, dataset_file def check_retrieval_pipeline(): """Check if local retrieval pipeline is running""" print("\nšŸ”Œ Checking retrieval pipeline...") kb_type = os.getenv("KB_TYPE", "local") if kb_type == "local": import requests try: response = requests.get("http://localhost:4242/health", timeout=2) if response.status_code == 200: print("āœ… Local retrieval pipeline is running") return True except Exception: pass print("āš ļø Local retrieval pipeline is not running") print(" Please run in another terminal:") print(" cd ../retrieval-pipeline && python main.py") print("\n Or use Dify by setting KB_TYPE=dify in .env") return False else: print(f"āœ… Using {kb_type} knowledge base") return True def index_documents(doc_file): """Index documents into knowledge base""" print("\nšŸ“ Indexing documents...") # Check if already indexed store_file = Path("document_store.json") if store_file.exists(): with open(store_file, 'r', encoding='utf-8') as f: store = json.load(f) if len(store) > 0: print(f"āœ… Found {len(store)} documents already indexed") return True print("šŸ”„ Indexing legal documents...") result = os.system(f"python chunking.py {doc_file}") if result == 0: print("āœ… Documents indexed successfully") return True else: print("āŒ Failed to index documents") return False def run_demo(): """Run interactive demo""" print("\n" + "="*60) print("šŸš€ Starting Agentic RAG Demo") print("="*60) print("\nDemo queries you can try:") print("1. ę•…ę„ę€äŗŗē½Ŗåˆ¤å‡ å¹“ļ¼Ÿ") print("2. ē›—ēŖƒē½Ŗēš„ē«‹ę”ˆę ‡å‡†ę˜Æä»€ä¹ˆļ¼Ÿ") print("3. é†‰é…’é©¾é©¶å¦‚ä½•å¤„ē½šļ¼Ÿ") print("4. å¼ ęŸęŒåˆ€å…„å®¤ęŠ¢åŠ«å¹¶é€ ęˆä»–äŗŗé‡ä¼¤ļ¼Œåŗ”å¦‚ä½•å®šē½Ŗé‡åˆ‘ļ¼Ÿ") print("\nCommands:") print("- 'mode' to switch between agentic/non-agentic") print("- 'clear' to clear conversation history") print("- 'quit' to exit") print("\nStarting in interactive mode...") print("-"*60) os.system("python main.py") def run_comparison_demo(): """Run comparison between agentic and non-agentic modes""" print("\n" + "="*60) print("šŸ”„ Running Comparison Demo") print("="*60) queries = [ "ę•…ę„ę€äŗŗē½Ŗåˆ¤å‡ å¹“ļ¼Ÿ", "å¼ ęŸå› ē»ęµŽēŗ ēŗ·ęŒåˆ€é—Æå…„ęŽęŸå®¶äø­ļ¼Œåˆŗä¼¤ęŽęŸč‡“é‡ä¼¤å¹¶ę‹æčµ°5äø‡å…ƒēŽ°é‡‘ļ¼Œåŗ”å¦‚ä½•å®šē½Ŗļ¼Ÿ" ] for query in queries: print(f"\nšŸ“ Query: {query}") os.system(f'python main.py --mode compare --query "{query}"') input("\nPress Enter to continue...") def main(): """Main quickstart function""" print("šŸŽÆ Agentic RAG System - Quick Start") print("="*60) # Check environment if not check_environment(): print("\nāŒ Please configure your environment first") sys.exit(1) # Setup demo documents doc_file, dataset_file = setup_demo_documents() # Check retrieval pipeline if not check_retrieval_pipeline(): print("\nāš ļø Warning: Retrieval pipeline not available") print(" The system may not work properly") response = input("\nContinue anyway? (y/n): ") if response.lower() != 'y': sys.exit(0) # Index documents if not index_documents(doc_file): print("\nāŒ Failed to index documents") sys.exit(1) # Menu print("\n" + "="*60) print("šŸ“‹ Select an option:") print("="*60) print("1. Interactive Demo (chat with the system)") print("2. Comparison Demo (see agentic vs non-agentic)") print("3. Run Full Evaluation") print("4. Exit") choice = input("\nYour choice (1-4): ") if choice == "1": run_demo() elif choice == "2": run_comparison_demo() elif choice == "3": print("\nšŸ“Š Running full evaluation...") os.chdir("evaluation") os.system("python evaluate.py") os.chdir("..") elif choice == "4": print("\nšŸ‘‹ Goodbye!") else: print("\nāŒ Invalid choice") if __name__ == "__main__": # Install dependencies if needed try: import openai import requests from dotenv import load_dotenv except ImportError: print("šŸ“¦ Installing required packages...") os.system("pip install -r requirements.txt") print("āœ… Packages installed") main()