1. Build a basic chatbot using Gemini 2.0 flash
This commit is contained in:
35
main.py
Normal file
35
main.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# from src.graph_builder import build_graph
|
||||
from src.graph_builder import graph_builder
|
||||
from src.nodes import chatbot
|
||||
from langgraph.graph import START, END
|
||||
|
||||
|
||||
# The first argument is the unique node name
|
||||
# The second argument is the function or object that will be called whenever
|
||||
# the node is used.
|
||||
|
||||
if __name__ == "__main__":
|
||||
graph_builder.add_node("chatbot", chatbot)
|
||||
graph_builder.add_edge(START, "chatbot")
|
||||
graph_builder.add_edge("chatbot", END)
|
||||
graph = graph_builder.compile()
|
||||
|
||||
def stream_graph_updates(user_input: str):
|
||||
for event in graph.stream({"messages": [{"role": "user", "content": user_input}]}):
|
||||
for value in event.values():
|
||||
print("Assistant:", value["messages"][-1].content)
|
||||
|
||||
|
||||
while True:
|
||||
try:
|
||||
user_input = input("User: ")
|
||||
if user_input.lower() in ["quit", "exit", "q"]:
|
||||
print("Goodbye!")
|
||||
break
|
||||
stream_graph_updates(user_input)
|
||||
except:
|
||||
# fallback if input() is not available
|
||||
user_input = "What do you know about LangGraph?"
|
||||
print("User: " + user_input)
|
||||
stream_graph_updates(user_input)
|
||||
break
|
||||
Reference in New Issue
Block a user