-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (47 loc) · 1.46 KB
/
Copy pathmain.py
File metadata and controls
55 lines (47 loc) · 1.46 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
import sys
from horribleagent.cli import build_arg_parser, build_agent, build_welcome
from horribleagent.constants import HELP_DETAILS
def main(argv=None):
args = build_arg_parser().parse_args(argv)
agent = build_agent(args)
print(build_welcome(agent, model=args.model, host=args.host))
if args.prompt:
prompt = " ".join(args.prompt).strip()
if prompt:
print()
try:
print(agent.ask(prompt))
except RuntimeError as exc:
print(str(exc), file=sys.stderr)
return 1
return 0
while True:
try:
user_input = input("\nhorrible-agent> ").strip()
except (EOFError, KeyboardInterrupt):
print("")
return 0
if not user_input:
continue
if user_input in {"/exit", "/quit"}:
return 0
if user_input == "/help":
print(HELP_DETAILS)
continue
if user_input == "/memory":
print(agent.memory_text())
continue
if user_input == "/session":
print(agent.session_path)
continue
if user_input == "/reset":
agent.reset()
print("session reset")
continue
print()
try:
print(agent.ask(user_input))
except RuntimeError as exc:
print(str(exc), file=sys.stderr)
if __name__ == "__main__":
raise SystemExit(main())