-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
47 lines (38 loc) · 1.56 KB
/
Copy pathcli.py
File metadata and controls
47 lines (38 loc) · 1.56 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
"""Terminal interface."""
verbose = False
DIM = "\033[2m"
BOLD = "\033[1m"
CYAN = "\033[36m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
RESET = "\033[0m"
def banner(backend):
print(f"\n{DIM}──────────────────────────────────{RESET}")
print(f"{BOLD} miniature{RESET} {DIM}({backend}){RESET}")
print(f"{DIM}──────────────────────────────────{RESET}\n")
def prompt():
try:
user = input(f"{BOLD}>{RESET} ").strip()
except (KeyboardInterrupt, EOFError):
print()
return None
return user if user and user not in ("quit", "exit", "q") else None
def agent_response(text):
print(f"\n{CYAN}{text}{RESET}\n")
def tool_call(name, args):
args_str = ", ".join(f"{k}={v!r}" for k, v in args.items())
print(f" {YELLOW}▸ {name}{RESET}{DIM}({args_str}){RESET}")
def tool_result(name, result):
lines = str(result).strip().split("\n")
preview = lines[0][:80] + ("…" if len(lines[0]) > 80 or len(lines) > 1 else "")
print(f" {GREEN}→{RESET} {DIM}{preview}{RESET}")
def verbose_prompt(messages, max_size=1024):
if not verbose:
return
print(f"{DIM}── verbose prompt ──{RESET}")
for m in messages:
text = m["content"][:max_size] + ("…" if len(m["content"]) > max_size else "")
print(f"{DIM} [{m['role']}] {text}{RESET}")
print(f"{DIM}────────────────{RESET}")
def goodbye():
print(f"{DIM}bye{RESET}\n")