|
| 1 | +import argparse |
| 2 | +import sys |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +from dotenv import load_dotenv |
| 6 | + |
| 7 | +from oculus.framework.runner import EvaluationRunner |
| 8 | +from oculus.integrations.fai_integration import create_fai_answer_function |
| 9 | + |
| 10 | +load_dotenv() |
| 11 | + |
| 12 | + |
| 13 | +def main() -> int: |
| 14 | + parser = argparse.ArgumentParser( |
| 15 | + description="Run Ask Fern evaluations using LLM-as-a-judge", |
| 16 | + formatter_class=argparse.RawDescriptionHelpFormatter, |
| 17 | + epilog=""" |
| 18 | +Examples: |
| 19 | + oculus --suite retrieval_quality --domain buildwithfern.com |
| 20 | + oculus --suite answer_quality --domain docs.cohere.com --run-id experiment_1 |
| 21 | + oculus --suite test --domain example.com --model command-a-03-2025 |
| 22 | + oculus --suite test --domain example.com --no-skip-existing |
| 23 | + """, |
| 24 | + ) |
| 25 | + |
| 26 | + parser.add_argument("--suite", type=str, required=True, help="Name of the evaluation suite") |
| 27 | + parser.add_argument("--domain", type=str, required=True, help="Documentation domain to query") |
| 28 | + parser.add_argument("--suite-path", type=Path, default=None, help="Base path to suites directory") |
| 29 | + parser.add_argument("--run-id", type=str, default=None, help="Unique run identifier") |
| 30 | + parser.add_argument( |
| 31 | + "--model", |
| 32 | + type=str, |
| 33 | + default="claude-4-sonnet-20250514", |
| 34 | + choices=["claude-4-sonnet-20250514", "command-a-03-2025"], |
| 35 | + help="Model to use for answer generation", |
| 36 | + ) |
| 37 | + parser.add_argument("--judge-model", type=str, default="claude-opus-4-20250514", help="Claude model for judging") |
| 38 | + parser.add_argument("--max-workers", type=int, default=16, help="Number of parallel workers") |
| 39 | + parser.add_argument("--no-skip-existing", action="store_true", help="Re-generate existing answers/evaluations") |
| 40 | + parser.add_argument("--output-dir", type=Path, default=None, help="Directory to save results") |
| 41 | + |
| 42 | + args = parser.parse_args() |
| 43 | + |
| 44 | + if args.suite_path: |
| 45 | + suite_base = args.suite_path |
| 46 | + else: |
| 47 | + suite_base = Path.cwd() / "suites" |
| 48 | + |
| 49 | + suite_path = suite_base / args.suite |
| 50 | + |
| 51 | + if not suite_path.exists(): |
| 52 | + print(f"Error: Suite directory not found: {suite_path}", file=sys.stderr) |
| 53 | + print(f"\nExpected structure:", file=sys.stderr) |
| 54 | + print(f" {suite_path}/", file=sys.stderr) |
| 55 | + print(f" questions/", file=sys.stderr) |
| 56 | + print(f" question_0.json", file=sys.stderr) |
| 57 | + return 1 |
| 58 | + |
| 59 | + questions_dir = suite_path / "questions" |
| 60 | + if not questions_dir.exists() or not any(questions_dir.glob("*.json")): |
| 61 | + print(f"Error: No questions found in {questions_dir}", file=sys.stderr) |
| 62 | + return 1 |
| 63 | + |
| 64 | + try: |
| 65 | + print(f"Initializing FAI integration for domain: {args.domain}") |
| 66 | + answer_fn = create_fai_answer_function(domain=args.domain, model=args.model) |
| 67 | + |
| 68 | + runner = EvaluationRunner( |
| 69 | + suite_name=args.suite, |
| 70 | + suite_path=suite_path, |
| 71 | + run_id=args.run_id, |
| 72 | + max_workers=args.max_workers, |
| 73 | + ) |
| 74 | + |
| 75 | + result = runner.run( |
| 76 | + answer_fn=answer_fn, |
| 77 | + model_name=args.model, |
| 78 | + judge_model=args.judge_model, |
| 79 | + skip_existing=not args.no_skip_existing, |
| 80 | + ) |
| 81 | + |
| 82 | + if args.output_dir: |
| 83 | + from oculus.utils.file_utils import save_json |
| 84 | + |
| 85 | + args.output_dir.mkdir(parents=True, exist_ok=True) |
| 86 | + output_path = args.output_dir / f"results_{result.run_id}.json" |
| 87 | + save_json(output_path, result.model_dump()) |
| 88 | + print(f"\nAdditional output saved to: {output_path}") |
| 89 | + |
| 90 | + return 0 |
| 91 | + |
| 92 | + except ImportError as e: |
| 93 | + print(f"\nError: Failed to import required modules", file=sys.stderr) |
| 94 | + print(f"{e}", file=sys.stderr) |
| 95 | + print(f"\nMake sure:", file=sys.stderr) |
| 96 | + print(f" 1. FAI dependencies are installed (poetry install in servers/fai)", file=sys.stderr) |
| 97 | + print(f" 2. PYTHONPATH includes the FAI source directory", file=sys.stderr) |
| 98 | + return 1 |
| 99 | + |
| 100 | + except Exception as e: |
| 101 | + print(f"\nError: Evaluation failed", file=sys.stderr) |
| 102 | + print(f"{e}", file=sys.stderr) |
| 103 | + import traceback |
| 104 | + |
| 105 | + traceback.print_exc() |
| 106 | + return 1 |
| 107 | + |
| 108 | + |
| 109 | +if __name__ == "__main__": |
| 110 | + sys.exit(main()) |
0 commit comments