-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_runner.py
More file actions
63 lines (46 loc) · 1.87 KB
/
Copy pathcli_runner.py
File metadata and controls
63 lines (46 loc) · 1.87 KB
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
"""Command-line runner for Agent Lightning evaluation."""
import asyncio
import os
from typing import cast
from dotenv import load_dotenv
import pandas as pd
from rich.console import Console
from agentlightning import LLM, AgentOpsTracer, InMemoryLightningStore, LitAgentRunner
from agent import loan_risk_agent, RiskTask
load_dotenv()
console = Console()
async def main():
"""Main entry point for CLI runner."""
console.print("[bold cyan]🚀 Loan Default Early Warning System - CLI Mode[/bold cyan]")
console.print("[dim]Using Agent Lightning Framework[/dim]\n")
# Check API key
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
console.print("[bold red]❌ Error:[/bold red] OPENAI_API_KEY not found in .env file!")
return
console.print(f"[green]✓ API Key loaded[/green]\n")
# Initialize LLM
llm = LLM(
endpoint="https://api.openai.com/v1",
model="gpt-4o-mini",
)
# Load test data
try:
data = pd.read_csv("data/loan_risk_samples.csv")
except FileNotFoundError:
console.print("[bold red]❌ Error:[/bold red] data/loan_risk_samples.csv not found!")
return
# Setup Agent Lightning components
tracer = AgentOpsTracer()
runner = LitAgentRunner[RiskTask](tracer=tracer)
store = InMemoryLightningStore()
# Run evaluation
console.print(f"[bold blue]Running {len(data)} test scenarios...[/bold blue]\n")
with runner.run_context(agent=loan_risk_agent, store=store):
for index in range(min(8, len(data))):
sample = cast(RiskTask, data.iloc[index].to_dict())
await runner.step(sample, resources={"main_llm": llm})
console.print() # Blank line between tests
console.print("\n[bold green]✓ All evaluations complete![/bold green]")
if __name__ == "__main__":
asyncio.run(main())