-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.py
More file actions
26 lines (23 loc) · 752 Bytes
/
Copy pathchat.py
File metadata and controls
26 lines (23 loc) · 752 Bytes
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
from graph import build_graph
from config import graph_config
def stream_graph_updates(graph, user_input: str):
for event in graph.stream(
{"messages": [{"role": "user", "content": user_input}]},
config=graph_config,
stream_mode="values"
):
event["messages"][-1].pretty_print()
def run_chat_loop():
graph = build_graph()
while True:
try:
user_input = input("user: ")
if user_input.lower() in ["exit", "quit", "q"]:
print("Goodbye")
break
stream_graph_updates(graph, user_input)
except KeyboardInterrupt:
print("\nGoodbye")
break
except Exception as e:
print(f"Error: {e}")