-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive.py
More file actions
164 lines (141 loc) · 6.21 KB
/
Copy pathinteractive.py
File metadata and controls
164 lines (141 loc) · 6.21 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
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
"""Interactive mode with Rich UI for human-in-the-loop review."""
from rich.console import Console
from rich.panel import Panel
from rich.prompt import Prompt
from rich import box
import signal
from contextlib import contextmanager
console = Console()
class InteractiveReviewer:
"""Handles interactive review of candidates with Rich UI."""
def __init__(self, timeout_seconds: int = 60):
"""Initialize interactive reviewer."""
self.timeout_seconds = timeout_seconds
self.timeout_occurred = False
def display_candidate(self, candidate_num: int, total: int, name: str,
url: str, score: int, reasoning: str, message: str):
"""Display candidate information in a formatted panel."""
# Color-code score
if score >= 7:
score_color = 'green'
elif score >= 5:
score_color = 'yellow'
else:
score_color = 'red'
# Build panel content
content = (
f"[bold cyan]Candidate #{candidate_num}/{total}: {name}[/bold cyan]\n"
f"Profile: {url}\n\n"
f"[bold]Score:[/bold] [{score_color}]{score}/10[/{score_color}]\n"
f"[bold]Reasoning:[/bold] {reasoning}\n\n"
f"[bold]Generated Message:[/bold]\n[cyan]{message}[/cyan]"
)
# Display panel
console.print(Panel(
content,
title="Review Candidate",
box=box.DOUBLE,
border_style="cyan"
))
def get_decision(self) -> str:
"""
Prompt user for decision (no timeout - take your time).
Returns: 'y', 'n', 'e', or 'q'
"""
choice = Prompt.ask(
"\n[bold][Y][/bold] Send [bold][N][/bold] Skip "
"[bold][E][/bold] Edit [bold][Q][/bold] Quit",
choices=['y', 'n', 'e', 'q', 'Y', 'N', 'E', 'Q'],
show_choices=False
)
return choice.lower()
def get_custom_message(self, original_message: str) -> str:
"""
Prompt user to edit message (no timeout).
Returns edited message or empty string if cancelled.
"""
console.print("\n[bold]Edit Message[/bold]")
console.print(f"[dim]Original: {original_message}[/dim]\n")
while True:
custom_message = Prompt.ask(
"Enter new message (or 'cancel' to skip)",
default=original_message
)
if custom_message.lower() == 'cancel':
return ''
# Validate length
if len(custom_message) < 50:
console.print("[red]Message too short (min 50 chars). Try again.[/red]")
continue
if len(custom_message) > 300:
console.print("[red]Message too long (max 300 chars). Try again.[/red]")
continue
return custom_message
@contextmanager
def _timeout_context(self, seconds: int):
"""Context manager for timeout handling."""
def timeout_handler(signum, frame):
raise TimeoutError()
# Set up signal handler (Unix-like systems only)
try:
old_handler = signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(seconds)
try:
yield
finally:
signal.alarm(0)
signal.signal(signal.SIGALRM, old_handler)
except AttributeError:
# Windows doesn't support SIGALRM, skip timeout
console.print("[yellow]Warning: Timeout not supported on this platform[/yellow]")
yield
def display_summary(self, stats: dict):
"""Display final summary statistics."""
console.print("\n" + "="*50)
console.print("[bold cyan]Session Summary[/bold cyan]")
console.print("="*50)
console.print(f"Candidates evaluated: {stats.get('evaluated', 0)}")
console.print(f"Invitations sent: {stats.get('sent', 0)}")
console.print(f" - Auto-sent: {stats.get('sent_auto', 0)}")
console.print(f" - Custom edited: {stats.get('sent_custom', 0)}")
console.print(f"Skipped (manual): {stats.get('skipped_manual', 0)}")
console.print(f"Skipped (threshold): {stats.get('skipped_threshold', 0)}")
console.print(f"Skipped (timeout): {stats.get('skipped_timeout', 0)}")
console.print(f"Errors: {stats.get('errors', 0)}")
console.print("="*50 + "\n")
class AutoModeRunner:
"""Handles automated mode without human review."""
def __init__(self):
"""Initialize auto mode runner."""
pass
def log_evaluation(self, candidate_num: int, total: int, candidate_id: str,
name: str, score: int, reasoning: str):
"""Log evaluation in auto mode."""
console.print(
f"[dim]Processing {candidate_id} ({candidate_num}/{total})...[/dim]"
)
if score >= 7:
score_indicator = "[green]✓[/green]"
elif score >= 5:
score_indicator = "[yellow]~[/yellow]"
else:
score_indicator = "[red]✗[/red]"
console.print(f" {score_indicator} Score: {score}/10 - {reasoning[:50]}...")
def log_action(self, action: str, name: str = None):
"""Log action taken in auto mode."""
if action == 'sent':
console.print(f" [green]✓[/green] Invitation sent to {name}")
elif action == 'skipped-threshold':
console.print(f" [red]✗[/red] Skipped (below threshold)")
elif action == 'error':
console.print(f" [red]✗[/red] Error processing candidate")
def display_summary(self, stats: dict):
"""Display final summary statistics."""
console.print("\n" + "="*50)
console.print("[bold cyan]Auto Mode Summary[/bold cyan]")
console.print("="*50)
console.print(f"Candidates evaluated: {stats.get('evaluated', 0)}")
console.print(f"Invitations sent: {stats.get('sent', 0)}")
console.print(f"Skipped (threshold): {stats.get('skipped_threshold', 0)}")
console.print(f"Errors: {stats.get('errors', 0)}")
console.print("="*50 + "\n")