Spaces:
Running
Running
File size: 3,368 Bytes
8c9362b |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
import asyncio
import sys
import os
# Add project root to path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from app.ai.agent.graph import get_aida_graph
async def verify_fix():
print("π Verifying Fixes for Intent & UI...")
graph = get_aida_graph()
session_id = "verify_session_001"
user_id = "tester"
# 1. INITIAL LISTING (Should not have replace flag)
print("\n1. sending initial listing request...")
state_1 = await graph.ainvoke({
"user_id": user_id,
"session_id": session_id,
"user_role": "landlord",
"last_user_message": "List a 2-bed in Lagos",
"start_new_session": True
}, config={"configurable": {"thread_id": session_id}, "recursion_limit": 50})
temp_data_1 = state_1.get("temp_data", {})
replace_1 = temp_data_1.get("replace_last_message", False)
intent_1 = state_1.get("intent_type")
print(f" Intent: {intent_1}")
print(f" Replace Flag: {replace_1} (Expected: False)")
# 2. PROVIDE PRICE (Still building, replace flag false?)
# "List a 2-bed in Lagos" -> Missing price. So it asks for price.
print("\n2. Providing price...")
state_2 = await graph.ainvoke({
"user_id": user_id,
"session_id": session_id,
"user_role": "landlord",
"last_user_message": "50k",
# Persist state via thread_id
}, config={"configurable": {"thread_id": session_id}, "recursion_limit": 50})
# Check if we reached validate
try:
curr_flow = state_2.get("current_flow")
# Handle enum if present
if hasattr(curr_flow, 'value'):
curr_flow = curr_flow.value
print(f" Current Flow: {curr_flow}")
except:
print(f" Current Flow: {state_2.get('current_flow')}")
# If we are in validate (draft shown), replace should be False (first show)
temp_data_2 = state_2.get("temp_data", {})
replace_2 = temp_data_2.get("replace_last_message", False)
print(f" Replace Flag: {replace_2} (Expected: False)")
# 3. CHANGE COMMAND (The Fix!)
print("\n3. Sending CHANGE command: 'Change price to 85k'...")
state_3 = await graph.ainvoke({
"user_id": user_id,
"session_id": session_id,
"user_role": "landlord",
"last_user_message": "Change price to 85k"
}, config={"configurable": {"thread_id": session_id}, "recursion_limit": 50})
intent_3 = state_3.get("intent_type")
temp_data_3 = state_3.get("temp_data", {})
replace_3 = temp_data_3.get("replace_last_message", False)
draft_3 = state_3.get("listing_draft", {})
print(f" Intent: {intent_3} (Expected: listing)")
print(f" Replace Flag: {replace_3} (Expected: True)")
print(f" New Price: {draft_3.get('price')} (Expected: 85000.0)")
passed = True
if intent_3 != "listing":
print("β Intent check failed")
passed = False
if replace_3 is not True:
print("β Replace flag check failed")
passed = False
if draft_3.get("price") != 85000.0:
print("β Price update check failed")
passed = False
if passed:
print("\nβ
VERIFICATION PASSED!")
else:
print("\nβ VERIFICATION FAILED")
if __name__ == "__main__":
asyncio.run(verify_fix())
|