Aniruddha7 commited on
Commit
86b079e
·
verified ·
1 Parent(s): 8f4e31a

Fix: < > operators falsely rejected as placeholders; Groq TTS models filtered; reason prints

Browse files
Files changed (1) hide show
  1. Agent/agentic_workflow.py +18 -7
Agent/agentic_workflow.py CHANGED
@@ -1030,7 +1030,10 @@ def _groq_chat_models() -> list:
1030
  )
1031
  r.raise_for_status()
1032
  ids = [m.get("id") for m in r.json().get("data", []) if m.get("id")]
1033
- exclude_tokens = ("whisper", "tts", "playai", "guard")
 
 
 
1034
  text_models = [
1035
  i for i in ids
1036
  if not any(tok in i.lower() for tok in exclude_tokens)
@@ -1055,8 +1058,10 @@ def _groq_text_completion(prompt: str, max_tokens: int = 1024, timeout: float =
1055
  if GROQ_TEXT_MODEL:
1056
  candidates.append(GROQ_TEXT_MODEL)
1057
  candidates.extend(_groq_chat_models())
1058
- if not candidates:
1059
- candidates.extend(_GROQ_CANDIDATE_FALLBACKS)
 
 
1060
  # Prefer Qwen-family ids (closest match to the dormant HF primary,
1061
  # Qwen/Qwen2.5-Coder) while keeping the explicit override untouched.
1062
  ordered = candidates[:1] # explicit override, if set, stays first
@@ -2845,19 +2850,25 @@ def is_sql_valid(sql: str, question: str = None) -> bool:
2845
 
2846
  sql_lower = sql.lower().strip()
2847
 
2848
- # Quick placeholder check
2849
- PLACEHOLDER_TOKENS = ["<", ">", "...", "___", "placeholder", "example", "your_"]
 
 
 
 
2850
  PLACEHOLDER_REGEXES = [
2851
  r"<[A-Z_]+>", # <TABLE_NAME>, <COLUMN>
2852
  r"\b(table_name|column_name|your_\w+)\b"
2853
  ]
2854
-
2855
  for token in PLACEHOLDER_TOKENS:
2856
  if token in sql_lower:
 
2857
  return False
2858
-
2859
  for regex in PLACEHOLDER_REGEXES:
2860
  if re.search(regex, sql, re.IGNORECASE):
 
2861
  return False
2862
 
2863
  # Reject hardcoded department codes (D001-D009) - indicates incomplete query
 
1030
  )
1031
  r.raise_for_status()
1032
  ids = [m.get("id") for m in r.json().get("data", []) if m.get("id")]
1033
+ # Non-chat families: ASR, TTS (incl. Orpheus/CanopyLabs voices,
1034
+ # whose ids carry no "tts" token), guard models, embeddings.
1035
+ exclude_tokens = ("whisper", "tts", "playai", "guard", "orpheus",
1036
+ "canopylabs", "asr", "embed")
1037
  text_models = [
1038
  i for i in ids
1039
  if not any(tok in i.lower() for tok in exclude_tokens)
 
1058
  if GROQ_TEXT_MODEL:
1059
  candidates.append(GROQ_TEXT_MODEL)
1060
  candidates.extend(_groq_chat_models())
1061
+ # ALWAYS merge the static known-good ids: the live /models listing can
1062
+ # return non-chat families (filtered) or be temporarily empty — the static
1063
+ # tail guarantees resumable candidates. Duplicates are removed below.
1064
+ candidates.extend(_GROQ_CANDIDATE_FALLBACKS)
1065
  # Prefer Qwen-family ids (closest match to the dormant HF primary,
1066
  # Qwen/Qwen2.5-Coder) while keeping the explicit override untouched.
1067
  ordered = candidates[:1] # explicit override, if set, stays first
 
2850
 
2851
  sql_lower = sql.lower().strip()
2852
 
2853
+ # Quick placeholder check.
2854
+ # NOTE: "<" and ">" are LEGITIMATE comparison operators ("price > average",
2855
+ # "count < 5", "<>"). They were once listed here and SILENTLY rejected every
2856
+ # greater/less-than question on every database. Real placeholders are caught
2857
+ # by the regexes below (<TABLE_NAME> style) — keep operators legal.
2858
+ PLACEHOLDER_TOKENS = ["...", "___", "placeholder", "example", "your_"]
2859
  PLACEHOLDER_REGEXES = [
2860
  r"<[A-Z_]+>", # <TABLE_NAME>, <COLUMN>
2861
  r"\b(table_name|column_name|your_\w+)\b"
2862
  ]
2863
+
2864
  for token in PLACEHOLDER_TOKENS:
2865
  if token in sql_lower:
2866
+ print(f"[VALIDATION] Rejected: placeholder token '{token}'")
2867
  return False
2868
+
2869
  for regex in PLACEHOLDER_REGEXES:
2870
  if re.search(regex, sql, re.IGNORECASE):
2871
+ print(f"[VALIDATION] Rejected: placeholder pattern /{regex}/")
2872
  return False
2873
 
2874
  # Reject hardcoded department codes (D001-D009) - indicates incomplete query