-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (30 loc) · 1.41 KB
/
main.py
File metadata and controls
41 lines (30 loc) · 1.41 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
from agents.graph import *
from utils.imports import *
from configs.ConfigEnv import *
from configs.MongoSaver import MongoDBSaver
config = {"configurable": {"thread_id": "1"}}
def main():
with MongoDBSaver.from_conn_info(host=host, port=27017, db_name="checkpoints") as checkpointer:
graph = setup_graph()
app = graph.compile(checkpointer=checkpointer)
config = {"configurable": {"thread_id": "1"}}
while True:
user_input = input("User: ")
if user_input.lower() in ["quit", "exit", "q"]:
print("Goodbye!")
break
state_name = "__start__"
next_step = "Master"
print(f"Current State: {state_name} | Next Step: {next_step}")
for step in app.stream({"messages": [HumanMessage(content=user_input)]}, config, stream_mode="updates"):
try:
state_name = list(step.keys())[0]
next_step = step[state_name].get('next', 'Master')
except:
state_name = next_step
next_step = "Master"
print(f"Current State: {state_name} | Next Step: {next_step}")
if state_name == "ChatAgent":
print("Assistant: ", step["ChatAgent"]["messages"][-1].content)
if __name__ == "__main__":
main()