ciyidogan commited on
Commit
3ad4750
Β·
verified Β·
1 Parent(s): 01672a3

Update chat_handler.py

Browse files
Files changed (1) hide show
  1. chat_handler.py +7 -7
chat_handler.py CHANGED
@@ -54,7 +54,6 @@ def _safe_intent_parse(raw: str) -> tuple[str, str]:
54
  # ───────────────────────── CONFIG ───────────────────────── #
55
  cfg = ConfigProvider.get()
56
  SPARK_URL = str(cfg.global_config.spark_endpoint).rstrip("/")
57
- ALLOWED_INTENTS = {"flight-booking", "flight-info", "booking-cancel"}
58
 
59
  # ───────────────────────── SPARK ───────────────────────── #
60
  def initialize_llm():
@@ -210,15 +209,15 @@ async def _handle_new_message(session: Session, user_input: str, version) -> str
210
  session.chat_history,
211
  user_input,
212
  version.intents,
213
- session.project_name # Yeni parametre
214
  )
215
 
216
- # Get Spark response
217
  raw = await spark_generate(session, prompt, user_input)
218
 
219
  # Empty response fallback
220
  if not raw:
221
- log("⚠️ Empty response from Spark")
222
  return "ÜzgΓΌnΓΌm, mesajΔ±nΔ±zΔ± anlayamadΔ±m. LΓΌtfen tekrar dener misiniz?"
223
 
224
  # Check for intent
@@ -230,9 +229,10 @@ async def _handle_new_message(session: Session, user_input: str, version) -> str
230
  # Parse intent
231
  intent_name, tail = _safe_intent_parse(raw)
232
 
233
- # Validate intent
234
- if intent_name not in ALLOWED_INTENTS:
235
- log(f"⚠️ Invalid intent: {intent_name}")
 
236
  return _trim_response(tail) if tail else "Size nasΔ±l yardΔ±mcΔ± olabilirim?"
237
 
238
  # Short message guard (less than 3 words usually means incomplete request)
 
54
  # ───────────────────────── CONFIG ───────────────────────── #
55
  cfg = ConfigProvider.get()
56
  SPARK_URL = str(cfg.global_config.spark_endpoint).rstrip("/")
 
57
 
58
  # ───────────────────────── SPARK ───────────────────────── #
59
  def initialize_llm():
 
209
  session.chat_history,
210
  user_input,
211
  version.intents,
212
+ session.project_name
213
  )
214
 
215
+ # Get LLM response
216
  raw = await spark_generate(session, prompt, user_input)
217
 
218
  # Empty response fallback
219
  if not raw:
220
+ log("⚠️ Empty response from LLM")
221
  return "ÜzgΓΌnΓΌm, mesajΔ±nΔ±zΔ± anlayamadΔ±m. LΓΌtfen tekrar dener misiniz?"
222
 
223
  # Check for intent
 
229
  # Parse intent
230
  intent_name, tail = _safe_intent_parse(raw)
231
 
232
+ # βœ… Session'daki intent'lerle validate et
233
+ valid_intents = {intent.name for intent in version.intents}
234
+ if intent_name not in valid_intents:
235
+ log(f"⚠️ Invalid intent: {intent_name} (valid: {valid_intents})")
236
  return _trim_response(tail) if tail else "Size nasΔ±l yardΔ±mcΔ± olabilirim?"
237
 
238
  # Short message guard (less than 3 words usually means incomplete request)