Paul720810 commited on
Commit
230e2a9
·
verified ·
1 Parent(s): 3e99f1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -484,8 +484,6 @@ class TextToSQLSystem:
484
 
485
  # in class TextToSQLSystem:
486
 
487
- # in class TextToSQLSystem:
488
-
489
  def _validate_and_fix_sql(self, question: str, raw_response: str) -> Tuple[Optional[str], str]:
490
  """
491
  (V23 / 统一实体识别版)
@@ -569,6 +567,18 @@ class TextToSQLSystem:
569
  return self._finalize_sql(template_sql, f"模板覆寫: {time_log} 報告列表查詢")
570
 
571
  # ... (此处可以继续添加 V17 版本中的其他所有 if/elif 模板)
 
 
 
 
 
 
 
 
 
 
 
 
572
 
573
  # ==============================================================================
574
  # 第二层:常规修正流程 (Fallback Corrections)
 
484
 
485
  # in class TextToSQLSystem:
486
 
 
 
487
  def _validate_and_fix_sql(self, question: str, raw_response: str) -> Tuple[Optional[str], str]:
488
  """
489
  (V23 / 统一实体识别版)
 
567
  return self._finalize_sql(template_sql, f"模板覆寫: {time_log} 報告列表查詢")
568
 
569
  # ... (此处可以继续添加 V17 版本中的其他所有 if/elif 模板)
570
+ elif '報告' in q_lower and any(kw in q_lower for kw in ['幾份', '多少', '數量', '總數']) and not entity_match_data:
571
+ year_match = re.search(r'(\d{4})\s*年?', question)
572
+ time_condition, time_log = "", "總"
573
+ if year_match:
574
+ year = year_match.group(1)
575
+ time_condition = f"WHERE ReportAuthorization IS NOT NULL AND strftime('%Y', ReportAuthorization) = '{year}'"
576
+ time_log = f"{year}年"
577
+ else:
578
+ time_condition = "WHERE ReportAuthorization IS NOT NULL"
579
+ self._log(f"🔄 檢測到查詢【{time_log}全局報告總數】意圖,啟用模板。", "INFO")
580
+ template_sql = f"SELECT COUNT(DISTINCT JobNo) AS report_count FROM JobTimeline {time_condition};"
581
+ return self._finalize_sql(template_sql, f"模板覆寫: {time_log}全局報告總數查詢")
582
 
583
  # ==============================================================================
584
  # 第二层:常规修正流程 (Fallback Corrections)