Spaces:
Runtime error
Runtime error
File size: 6,199 Bytes
46f2cb3 23f437b 46f2cb3 a428e27 46f2cb3 a428e27 46f2cb3 23f437b 46f2cb3 a428e27 46f2cb3 a428e27 46f2cb3 a428e27 46f2cb3 a428e27 46f2cb3 a428e27 46f2cb3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
#!/usr/bin/env python3
"""
Simple CLI interface for querying the product design document via RAG
"""
import subprocess
import sys
import argparse
import os
import shutil
from pathlib import Path
def find_modal_command():
"""Find the modal command - check venv first, then PATH, then python -m modal"""
script_dir = Path(__file__).parent
# First priority: Check for venv/bin/modal (most common case)
venv_modal = script_dir / "venv" / "bin" / "modal"
if venv_modal.exists():
return [str(venv_modal)]
# Second priority: Check parent directory venv
parent_venv_modal = script_dir.parent / "venv" / "bin" / "modal"
if parent_venv_modal.exists():
return [str(parent_venv_modal)]
# Third priority: Check if modal is in PATH (might be activated venv)
modal_path = shutil.which("modal")
if modal_path:
return ["modal"]
# Fourth priority: Try python -m modal
try:
result = subprocess.run(
[sys.executable, "-m", "modal", "--version"],
capture_output=True,
text=True,
timeout=5
)
if result.returncode == 0:
return [sys.executable, "-m", "modal"]
except:
pass
# Last resort: return "modal" and let it fail with helpful error
return ["modal"]
def query(question: str):
"""Query the product design document"""
print(f"\n{'='*70}")
print(f"π€ Question: {question}")
print(f"{'='*70}\n")
modal_cmd = find_modal_command()
try:
result = subprocess.run(
modal_cmd + [
"run",
"src/rag/modal-rag-product-design.py::query_product_design",
"--question", question
],
capture_output=True,
text=True,
check=True
)
print(result.stdout)
if result.stderr:
print("Warnings:", result.stderr)
except FileNotFoundError:
print("β Error: Modal command not found!")
print("\nπ‘ Solutions:")
print("\n1. Activate your virtual environment:")
print(" source venv/bin/activate")
print(" python src/web/query_product_design.py --index")
print("\n2. Or use the helper script:")
print(" ./scripts/setup/run_with_venv.sh --index")
print("\n3. Or install Modal globally:")
print(" pip3 install modal")
sys.exit(1)
except subprocess.CalledProcessError as e:
print(f"β Error: {e}")
print(f"Output: {e.stdout}")
print(f"Error: {e.stderr}")
sys.exit(1)
def index():
"""Index the product design documents"""
print("\nπ Indexing product design documents...\n")
modal_cmd = find_modal_command()
try:
result = subprocess.run(
modal_cmd + ["run", "src/rag/modal-rag-product-design.py::index_product_design"],
capture_output=True,
text=True,
check=True
)
print(result.stdout)
if result.stderr:
print("Warnings:", result.stderr)
except FileNotFoundError:
print("β Error: Modal command not found!")
print("\nπ‘ Solutions:")
print("\n1. Activate your virtual environment:")
print(" source venv/bin/activate")
print(" python src/web/query_product_design.py --index")
print("\n2. Or use the helper script:")
print(" ./scripts/setup/run_with_venv.sh --index")
print("\n3. Or install Modal globally:")
print(" pip3 install modal")
sys.exit(1)
except subprocess.CalledProcessError as e:
print(f"β Error: {e}")
print(f"Output: {e.stdout}")
print(f"Error: {e.stderr}")
sys.exit(1)
def interactive():
"""Interactive query mode"""
print("\n" + "="*70)
print("π Product Design Document Query Interface")
print("="*70)
print("\nType your questions about the TokyoDrive Insurance product design.")
print("Type 'exit' or 'quit' to exit.\n")
while True:
try:
question = input("β Your question: ").strip()
if not question:
continue
if question.lower() in ['exit', 'quit', 'q']:
print("\nπ Goodbye!\n")
break
query(question)
print("\n")
except KeyboardInterrupt:
print("\n\nπ Goodbye!\n")
break
except EOFError:
print("\n\nπ Goodbye!\n")
break
def main():
parser = argparse.ArgumentParser(
description="Query the TokyoDrive Insurance product design document",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Index the documents first
python src/web/query_product_design.py --index
# Ask a single question
python src/web/query_product_design.py --query "What are the three product tiers?"
# Interactive mode
python src/web/query_product_design.py --interactive
# Example questions:
- "What are the three product tiers and their premium ranges?"
- "What is the Year 3 premium volume projection?"
- "What coverage does the Standard tier include?"
- "What are the FSA licensing requirements?"
"""
)
parser.add_argument(
"--query", "-q",
type=str,
help="Ask a single question"
)
parser.add_argument(
"--index", "-i",
action="store_true",
help="Index the product design documents"
)
parser.add_argument(
"--interactive", "-I",
action="store_true",
help="Start interactive query mode"
)
args = parser.parse_args()
if args.index:
index()
elif args.query:
query(args.query)
elif args.interactive:
interactive()
else:
parser.print_help()
print("\nπ‘ Tip: Use --interactive for an interactive session")
print(" Or use --query 'your question' for a single query")
if __name__ == "__main__":
main()
|