zenaight commited on
Commit ·
b92bfbc
1
Parent(s): 0e649c6
Enhance intent extraction logic to handle property inquiries
Browse files- Added a classification check in `extract_and_update_intent` to determine if the user is asking for property listings, allowing the system to skip preference questions when appropriate.
- Updated the state graph to reorder the processing flow, ensuring intent classification occurs before intent extraction, improving the overall logic and efficiency of user interactions.
- These changes aim to refine the user experience by providing more relevant responses based on user intent, while maintaining clarity in the conversation flow.
- ai_chat.py +12 -4
ai_chat.py
CHANGED
|
@@ -269,6 +269,14 @@ async def extract_and_update_intent(state):
|
|
| 269 |
|
| 270 |
missing = [f for f in intent_fields if state["intent"].get(f) is None]
|
| 271 |
if missing:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
questions = {
|
| 273 |
"location_preference": "Hi there! Which area or suburb are you interested in?",
|
| 274 |
"budget": "Hi there! What is your monthly budget?",
|
|
@@ -418,15 +426,15 @@ async def detect_end_chat(state):
|
|
| 418 |
# --- Build LangGraph ---
|
| 419 |
graph = StateGraph(ChatState)
|
| 420 |
graph.add_node("persona_update", RunnableLambda(extract_and_update_persona))
|
| 421 |
-
graph.add_node("intent_update", RunnableLambda(extract_and_update_intent))
|
| 422 |
graph.add_node("classify_intent", RunnableLambda(classify_user_intent))
|
|
|
|
| 423 |
graph.add_node("property_search", RunnableLambda(extract_and_search_properties))
|
| 424 |
graph.add_node("exit_check", RunnableLambda(detect_end_chat))
|
| 425 |
graph.add_node("chat", RunnableLambda(chat_with_session_memory))
|
| 426 |
graph.set_entry_point("persona_update")
|
| 427 |
-
graph.add_edge("persona_update", "
|
| 428 |
-
graph.add_edge("
|
| 429 |
-
graph.add_edge("
|
| 430 |
graph.add_edge("property_search", "exit_check")
|
| 431 |
graph.add_edge("exit_check", "chat")
|
| 432 |
graph.add_edge("chat", END)
|
|
|
|
| 269 |
|
| 270 |
missing = [f for f in intent_fields if state["intent"].get(f) is None]
|
| 271 |
if missing:
|
| 272 |
+
# Check if user is asking for properties (using AI classification)
|
| 273 |
+
classification = state.get("classification")
|
| 274 |
+
if classification == "search_listings":
|
| 275 |
+
# User is asking for properties, don't interrupt with preference questions
|
| 276 |
+
print("DEBUG - User asking for properties, skipping preference questions")
|
| 277 |
+
return {"response": None}
|
| 278 |
+
|
| 279 |
+
# User is setting preferences, ask for missing fields
|
| 280 |
questions = {
|
| 281 |
"location_preference": "Hi there! Which area or suburb are you interested in?",
|
| 282 |
"budget": "Hi there! What is your monthly budget?",
|
|
|
|
| 426 |
# --- Build LangGraph ---
|
| 427 |
graph = StateGraph(ChatState)
|
| 428 |
graph.add_node("persona_update", RunnableLambda(extract_and_update_persona))
|
|
|
|
| 429 |
graph.add_node("classify_intent", RunnableLambda(classify_user_intent))
|
| 430 |
+
graph.add_node("intent_update", RunnableLambda(extract_and_update_intent))
|
| 431 |
graph.add_node("property_search", RunnableLambda(extract_and_search_properties))
|
| 432 |
graph.add_node("exit_check", RunnableLambda(detect_end_chat))
|
| 433 |
graph.add_node("chat", RunnableLambda(chat_with_session_memory))
|
| 434 |
graph.set_entry_point("persona_update")
|
| 435 |
+
graph.add_edge("persona_update", "classify_intent")
|
| 436 |
+
graph.add_edge("classify_intent", "intent_update")
|
| 437 |
+
graph.add_edge("intent_update", "property_search")
|
| 438 |
graph.add_edge("property_search", "exit_check")
|
| 439 |
graph.add_edge("exit_check", "chat")
|
| 440 |
graph.add_edge("chat", END)
|