davidtran999 commited on
Commit
4e11279
·
verified ·
1 Parent(s): 49a3bd1

Upload backend/hue_portal/chatbot/chatbot.py with huggingface_hub

Browse files
backend/hue_portal/chatbot/chatbot.py CHANGED
@@ -175,6 +175,27 @@ class Chatbot(CoreChatbot):
175
 
176
  print(f"[WIZARD] Chatbot layer check - intent={intent}, wizard_stage={wizard_stage}, selected_doc_code={selected_doc_code}, selected_topic={selected_topic}, has_doc_code_in_query={has_doc_code_in_query}, query='{query[:50]}'")
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  # Stage 1: Choose document (if no document selected and no code in query)
179
  # Use Query Rewrite Strategy from slow_path_handler instead of old LLM suggestions
180
  if intent == "search_legal" and not selected_doc_code and not has_doc_code_in_query:
 
175
 
176
  print(f"[WIZARD] Chatbot layer check - intent={intent}, wizard_stage={wizard_stage}, selected_doc_code={selected_doc_code}, selected_topic={selected_topic}, has_doc_code_in_query={has_doc_code_in_query}, query='{query[:50]}'")
177
 
178
+ # Reset wizard state if new query doesn't have document code and wizard_stage is "answer"
179
+ # This handles the case where user asks a new question after completing a previous wizard flow
180
+ if intent == "search_legal" and not has_doc_code_in_query and wizard_stage == "answer":
181
+ print("[WIZARD] 🔄 New query detected, resetting wizard state for fresh start")
182
+ selected_doc_code = None
183
+ selected_topic = None
184
+ wizard_stage = None
185
+ if session_id:
186
+ try:
187
+ ConversationContext.update_session_metadata(
188
+ session_id,
189
+ {
190
+ "selected_document_code": None,
191
+ "selected_topic": None,
192
+ "wizard_stage": None,
193
+ "wizard_depth": 0,
194
+ }
195
+ )
196
+ except Exception as e:
197
+ print(f"⚠️ Failed to reset wizard state: {e}")
198
+
199
  # Stage 1: Choose document (if no document selected and no code in query)
200
  # Use Query Rewrite Strategy from slow_path_handler instead of old LLM suggestions
201
  if intent == "search_legal" and not selected_doc_code and not has_doc_code_in_query: