zenaight commited on
Commit ·
0e649c6
1
Parent(s): 0d86ec7
Add debug statements to persona and intent extraction functions
Browse files- Introduced debug print statements in `extract_and_update_persona`, `extract_and_update_intent`, and `classify_user_intent` to log the start of processing and responses generated, enhancing traceability during execution.
- Updated `extract_and_search_properties` to include a debug statement for classification checks, improving visibility into the property search process.
- These changes aim to facilitate debugging and provide better insights into the state of the application during user interactions.
- ai_chat.py +8 -0
ai_chat.py
CHANGED
|
@@ -117,6 +117,7 @@ class ChatState(TypedDict):
|
|
| 117 |
classification: str
|
| 118 |
|
| 119 |
async def extract_and_update_persona(state):
|
|
|
|
| 120 |
# a. Define which persona fields to track
|
| 121 |
persona_fields = ["language", "tone"]
|
| 122 |
user_message = state["user_message"]
|
|
@@ -165,12 +166,15 @@ async def extract_and_update_persona(state):
|
|
| 165 |
missing = [f for f in persona_fields if state["persona"].get(f) is None]
|
| 166 |
if missing:
|
| 167 |
state["response"] = f"Hi there! What is your {missing[0]} preference?"
|
|
|
|
| 168 |
return state
|
| 169 |
|
| 170 |
# f. All persona fields present—proceed to chat
|
|
|
|
| 171 |
return {"response": None}
|
| 172 |
|
| 173 |
async def extract_and_update_intent(state):
|
|
|
|
| 174 |
intent_fields = ["location_preference", "budget", "size_preference_sqm", "must_have"]
|
| 175 |
user_message = state["user_message"]
|
| 176 |
session_id = state["session_id"]
|
|
@@ -272,14 +276,17 @@ async def extract_and_update_intent(state):
|
|
| 272 |
"must_have": "Hi there! What features are must-haves for you?"
|
| 273 |
}
|
| 274 |
state["response"] = questions.get(missing[0], f"Hi there! Could you tell me your {missing[0]}?")
|
|
|
|
| 275 |
return state
|
| 276 |
|
|
|
|
| 277 |
return {"response": None}
|
| 278 |
|
| 279 |
async def classify_user_intent(state):
|
| 280 |
"""
|
| 281 |
Classify the user's message to determine if they want to search for properties.
|
| 282 |
"""
|
|
|
|
| 283 |
user_message = state["user_message"]
|
| 284 |
prompt = f"""
|
| 285 |
Classify the user's message into exactly one of:
|
|
@@ -299,6 +306,7 @@ async def extract_and_search_properties(state):
|
|
| 299 |
"""
|
| 300 |
Search for properties based on user intent and store results in state.
|
| 301 |
"""
|
|
|
|
| 302 |
# Only search when the LLM tagged this as a listings request
|
| 303 |
classification = state.get("classification")
|
| 304 |
print(f"DEBUG - Property search classification check: '{classification}'")
|
|
|
|
| 117 |
classification: str
|
| 118 |
|
| 119 |
async def extract_and_update_persona(state):
|
| 120 |
+
print("DEBUG - Starting extract_and_update_persona")
|
| 121 |
# a. Define which persona fields to track
|
| 122 |
persona_fields = ["language", "tone"]
|
| 123 |
user_message = state["user_message"]
|
|
|
|
| 166 |
missing = [f for f in persona_fields if state["persona"].get(f) is None]
|
| 167 |
if missing:
|
| 168 |
state["response"] = f"Hi there! What is your {missing[0]} preference?"
|
| 169 |
+
print(f"DEBUG - Persona update returning response: {state['response']}")
|
| 170 |
return state
|
| 171 |
|
| 172 |
# f. All persona fields present—proceed to chat
|
| 173 |
+
print("DEBUG - Persona update returning None")
|
| 174 |
return {"response": None}
|
| 175 |
|
| 176 |
async def extract_and_update_intent(state):
|
| 177 |
+
print("DEBUG - Starting extract_and_update_intent")
|
| 178 |
intent_fields = ["location_preference", "budget", "size_preference_sqm", "must_have"]
|
| 179 |
user_message = state["user_message"]
|
| 180 |
session_id = state["session_id"]
|
|
|
|
| 276 |
"must_have": "Hi there! What features are must-haves for you?"
|
| 277 |
}
|
| 278 |
state["response"] = questions.get(missing[0], f"Hi there! Could you tell me your {missing[0]}?")
|
| 279 |
+
print(f"DEBUG - Intent update returning response: {state['response']}")
|
| 280 |
return state
|
| 281 |
|
| 282 |
+
print("DEBUG - Intent update returning None")
|
| 283 |
return {"response": None}
|
| 284 |
|
| 285 |
async def classify_user_intent(state):
|
| 286 |
"""
|
| 287 |
Classify the user's message to determine if they want to search for properties.
|
| 288 |
"""
|
| 289 |
+
print("DEBUG - Starting classify_user_intent")
|
| 290 |
user_message = state["user_message"]
|
| 291 |
prompt = f"""
|
| 292 |
Classify the user's message into exactly one of:
|
|
|
|
| 306 |
"""
|
| 307 |
Search for properties based on user intent and store results in state.
|
| 308 |
"""
|
| 309 |
+
print("DEBUG - Starting extract_and_search_properties")
|
| 310 |
# Only search when the LLM tagged this as a listings request
|
| 311 |
classification = state.get("classification")
|
| 312 |
print(f"DEBUG - Property search classification check: '{classification}'")
|