-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
49 lines (35 loc) · 1.16 KB
/
cli.py
File metadata and controls
49 lines (35 loc) · 1.16 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
# cli.py
from rag.engine import RAGEngine
from rag.prompt import INITIAL_MESSAGE
def run_cli():
print("AStarBot CLI")
print("Type 'exit' to quit.\n")
engine = RAGEngine()
# Conversation state (client-side simulation)
recent_messages = []
summary = None
# Initial assistant message
print(f"AStarBot: {INITIAL_MESSAGE}\n")
recent_messages.append(
{"role": "assistant", "content": INITIAL_MESSAGE}
)
while True:
user_input = input("You: ").strip()
if user_input.lower() in {"exit", "quit"}:
print("Goodbye!")
break
result = engine.chat(
question=user_input,
recent_messages=recent_messages,
summary=summary,
)
answer = result["answer"]
summary = result["updated_summary"]
print(f"AStarBot: {answer}\n")
recent_messages.append({"role": "user", "content": user_input})
recent_messages.append({"role": "assistant", "content": answer})
# Keep window bounded
if len(recent_messages) > 12:
recent_messages = recent_messages[-12:]
if __name__ == "__main__":
run_cli()