ciyidogan commited on
Commit
21a66b7
Β·
verified Β·
1 Parent(s): 8691557

Update chat_handler.py

Browse files
Files changed (1) hide show
  1. chat_handler.py +23 -1
chat_handler.py CHANGED
@@ -399,11 +399,33 @@ def _process_parameters(session: Session, intent_config, raw: str) -> bool:
399
  except json.JSONDecodeError as e:
400
  log(f"❌ JSON parsing error: {e}")
401
  log(f"❌ Failed to parse: {raw[:200]}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  return False
403
  except Exception as e:
404
  log(f"❌ Parameter processing error: {e}")
405
  return False
406
-
407
  # ───────────────────────── API EXECUTION ───────────────────────── #
408
  async def _execute_api_call(session: Session, intent_config) -> str:
409
  """Execute API call and return humanized response"""
 
399
  except json.JSONDecodeError as e:
400
  log(f"❌ JSON parsing error: {e}")
401
  log(f"❌ Failed to parse: {raw[:200]}")
402
+
403
+ # Fallback: Try to extract simple values from user input
404
+ # This is especially useful for single parameter responses
405
+ if session.state == "await_param" and len(session.awaiting_parameters) > 0:
406
+ # Get the first missing parameter
407
+ first_missing = session.awaiting_parameters[0]
408
+ param_config = next(
409
+ (p for p in intent_config.parameters if p.name == first_missing),
410
+ None
411
+ )
412
+
413
+ if param_config and session.chat_history:
414
+ # Get the last user input
415
+ last_user_input = session.chat_history[-1].get("content", "").strip()
416
+
417
+ # For simple inputs like city names, try direct assignment
418
+ if param_config.type in ["str", "string"] and len(last_user_input.split()) <= 3:
419
+ if validate(last_user_input, param_config):
420
+ session.variables[param_config.variable_name] = last_user_input
421
+ log(f"βœ… Fallback extraction: {first_missing}={last_user_input}")
422
+ return True
423
+
424
  return False
425
  except Exception as e:
426
  log(f"❌ Parameter processing error: {e}")
427
  return False
428
+
429
  # ───────────────────────── API EXECUTION ───────────────────────── #
430
  async def _execute_api_call(session: Session, intent_config) -> str:
431
  """Execute API call and return humanized response"""