zenaight commited on
Commit
ff3c46d
·
1 Parent(s): d14240d

images still have bugs

Browse files
Files changed (1) hide show
  1. ai_chat.py +20 -65
ai_chat.py CHANGED
@@ -889,13 +889,19 @@ async def handle_image_request(state):
889
  print(f"DEBUG - Found user selected option {option_num}: {selected_property_context.get('title')}")
890
  break
891
 
892
- # Look for property type mentions that user specifically asked about
893
- for i, prop in enumerate(props):
894
- title_words = prop.get("title", "").lower().split()
895
- for word in ["warehouse", "office", "space", "unit"]:
896
- if word in content and word in title_words:
 
 
 
 
 
 
897
  selected_property_context = prop
898
- print(f"DEBUG - Found user interest in {word}: {prop.get('title')}")
899
  break
900
 
901
  # Use the property the user specifically selected/discussed
@@ -954,66 +960,15 @@ async def handle_image_request(state):
954
  selected_property = props[most_mentioned[0]]
955
  print(f"DEBUG - Selected property from pronoun context: {selected_property.get('title')}")
956
 
957
- # Fallback: Use conversation context to find which property user was discussing
958
- if not selected_property and len(props) > 1:
959
- # Check conversation history for property context
960
- session_messages = state.get("session_messages", [])
961
- print(f"DEBUG - Checking {len(session_messages)} session messages for property context")
962
-
963
- # Look for property mentions in recent conversation
964
- recent_messages = session_messages[-10:] # Last 10 messages
965
- property_mentions = {}
966
-
967
- for msg in recent_messages:
968
- if msg.get("role") == "assistant":
969
- content = msg.get("content", "").lower()
970
- for i, prop in enumerate(props):
971
- title = prop.get("title", "").lower()
972
- location = prop.get("location", "").lower()
973
- # Check if this property was mentioned in AI response
974
- title_words = title.split()
975
- if len(title_words) >= 2: # Use first 2 words for matching
976
- key_phrase = " ".join(title_words[:2])
977
- if key_phrase in content or location in content:
978
- property_mentions[i] = property_mentions.get(i, 0) + 1
979
- print(f"DEBUG - Found mention of property {i}: {title}")
980
 
981
- # Use most mentioned property from conversation
982
- if property_mentions:
983
- most_mentioned = max(property_mentions.items(), key=lambda x: x[1])
984
- selected_property = props[most_mentioned[0]]
985
- print(f"DEBUG - Selected property from conversation context: {selected_property.get('title')}")
986
- else:
987
- # Check if user is asking for images in a general way (like "show me images")
988
- # and there's only one property or clear context from recent messages
989
- if len(props) == 1:
990
- # Only one property available - use it
991
- selected_property = props[0]
992
- print(f"DEBUG - Only one property available, using: {selected_property.get('title')}")
993
- else:
994
- # Look for any recent property discussion in the last few messages
995
- very_recent_messages = session_messages[-5:] # Last 5 messages
996
- for msg in very_recent_messages:
997
- if msg.get("role") == "assistant":
998
- content = msg.get("content", "").lower()
999
- # Check if any property was mentioned in the last AI response
1000
- for i, prop in enumerate(props):
1001
- title = prop.get("title", "").lower()
1002
- if any(word in content for word in title.split()[:3]): # Check first 3 words of title
1003
- selected_property = prop
1004
- print(f"DEBUG - Found recent mention of property: {prop.get('title')}")
1005
- break
1006
- if selected_property:
1007
- break
1008
-
1009
- # If still no property selected, only then ask user to specify
1010
- if not selected_property:
1011
- prop_options = []
1012
- for i, prop in enumerate(props[:3], 1): # Show first 3 options
1013
- prop_options.append(f"Option {i}: {prop.get('title')}")
1014
-
1015
- options_text = "\n".join(prop_options)
1016
- return [f"I have multiple properties available. Which one would you like to see images of?\n\n{options_text}\n\nPlease let me know which option you'd like images for."]
1017
 
1018
  # Final fallback: use first property if only one or no context found
1019
  if not selected_property:
 
889
  print(f"DEBUG - Found user selected option {option_num}: {selected_property_context.get('title')}")
890
  break
891
 
892
+ # Look for specific property type mentions that user explicitly asked about
893
+ # Only if they specifically mentioned the property type in their image request
894
+ if "warehouse" in content and "warehouse" in user_message:
895
+ for i, prop in enumerate(props):
896
+ if "warehouse" in prop.get("title", "").lower():
897
+ selected_property_context = prop
898
+ print(f"DEBUG - Found user specifically asking for warehouse images: {prop.get('title')}")
899
+ break
900
+ elif "office" in content and "office" in user_message:
901
+ for i, prop in enumerate(props):
902
+ if "office" in prop.get("title", "").lower():
903
  selected_property_context = prop
904
+ print(f"DEBUG - Found user specifically asking for office images: {prop.get('title')}")
905
  break
906
 
907
  # Use the property the user specifically selected/discussed
 
960
  selected_property = props[most_mentioned[0]]
961
  print(f"DEBUG - Selected property from pronoun context: {selected_property.get('title')}")
962
 
963
+ # If still no property selected and user didn't specify, ask for clarification
964
+ if not selected_property:
965
+ print("DEBUG - No clear property context found, asking user to specify")
966
+ prop_options = []
967
+ for i, prop in enumerate(props[:3], 1): # Show first 3 options
968
+ prop_options.append(f"Option {i}: {prop.get('title')}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
969
 
970
+ options_text = "\n".join(prop_options)
971
+ return [f"I have multiple properties available. Which one would you like to see images of?\n\n{options_text}\n\nPlease let me know which option you'd like images for."]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
972
 
973
  # Final fallback: use first property if only one or no context found
974
  if not selected_property: