zenaight commited on
Commit ·
3fdf3b6
1
Parent(s): 440c7f4
Add conditional edges for chat flow control
Browse files- Introduced a `should_continue` function to determine whether to proceed to the next node based on the response state, enhancing the decision-making process in the chat flow.
- Replaced direct edges with conditional edges for `intent_update`, `property_search`, and `exit_check`, allowing for more dynamic control of the conversation based on user responses.
- These changes aim to improve the responsiveness and adaptability of the AI chat system, ensuring a smoother user experience by managing the flow of conversation more effectively.
- ai_chat.py +18 -3
ai_chat.py
CHANGED
|
@@ -454,11 +454,26 @@ graph.add_node("property_search", RunnableLambda(extract_and_search_properties))
|
|
| 454 |
graph.add_node("exit_check", RunnableLambda(detect_end_chat))
|
| 455 |
graph.add_node("chat", RunnableLambda(chat_with_session_memory))
|
| 456 |
graph.set_entry_point("persona_update")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
graph.add_edge("persona_update", "classify_intent")
|
| 458 |
graph.add_edge("classify_intent", "intent_update")
|
| 459 |
-
graph.
|
| 460 |
-
|
| 461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
graph.add_edge("chat", END)
|
| 463 |
chat_graph = graph.compile()
|
| 464 |
|
|
|
|
| 454 |
graph.add_node("exit_check", RunnableLambda(detect_end_chat))
|
| 455 |
graph.add_node("chat", RunnableLambda(chat_with_session_memory))
|
| 456 |
graph.set_entry_point("persona_update")
|
| 457 |
+
|
| 458 |
+
# Add conditional edges - if a node returns a response, go to END
|
| 459 |
+
def should_continue(state):
|
| 460 |
+
"""Check if we should continue to the next node or end"""
|
| 461 |
+
return state.get("response") is None
|
| 462 |
+
|
| 463 |
graph.add_edge("persona_update", "classify_intent")
|
| 464 |
graph.add_edge("classify_intent", "intent_update")
|
| 465 |
+
graph.add_conditional_edges("intent_update", should_continue, {
|
| 466 |
+
True: "property_search",
|
| 467 |
+
False: END
|
| 468 |
+
})
|
| 469 |
+
graph.add_conditional_edges("property_search", should_continue, {
|
| 470 |
+
True: "exit_check",
|
| 471 |
+
False: END
|
| 472 |
+
})
|
| 473 |
+
graph.add_conditional_edges("exit_check", should_continue, {
|
| 474 |
+
True: "chat",
|
| 475 |
+
False: END
|
| 476 |
+
})
|
| 477 |
graph.add_edge("chat", END)
|
| 478 |
chat_graph = graph.compile()
|
| 479 |
|