afaceuser09 commited on
Commit
52e21d8
·
verified ·
1 Parent(s): 4469463

Update reasoning_engine.py

Browse files
Files changed (1) hide show
  1. reasoning_engine.py +32 -4
reasoning_engine.py CHANGED
@@ -440,6 +440,22 @@ def _embed(text: str) -> np.ndarray:
440
  show_progress_bar=False,
441
  )[0]
442
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
 
444
  def _ensure_experience_embedding_column(conn: sqlite3.Connection) -> None:
445
  """Ensure the experience table has a BLOB column for precomputed embeddings."""
@@ -700,6 +716,11 @@ def plan(query: str, history: List[Dict[str, str]]) -> Dict[str, Any]:
700
  }
701
 
702
  def analyze(query: str, plan_data: Dict[str, Any], evidence: str, history: List[Dict[str, str]]) -> str:
 
 
 
 
 
703
  messages = [
704
  {"role": "system", "content": ANALYST_SYSTEM},
705
  {
@@ -718,6 +739,11 @@ def analyze(query: str, plan_data: Dict[str, Any], evidence: str, history: List[
718
 
719
  def verify(query: str, plan_data: Dict[str, Any], analysis: str, evidence: str) -> str:
720
  """Independent verification pass."""
 
 
 
 
 
721
  messages = [
722
  {"role": "system", "content": VERIFIER_SYSTEM},
723
  {
@@ -741,10 +767,12 @@ def final_answer(
741
  history: List[Dict[str, str]],
742
  verification: Optional[str] = None,
743
  ) -> str:
744
- """Final reasoning/synthesis pass.
745
- `verification` is optional to preserve compatibility with the previous
746
- five-argument search pipeline.
747
- """
 
 
748
  verification_text = verification or "No separate verification pass was supplied."
749
  messages = [
750
  {"role": "system", "content": FINAL_SYSTEM},
 
440
  show_progress_bar=False,
441
  )[0]
442
 
443
+ def _detect_and_count_characters(query: str) -> str:
444
+ """Programmatically extracts words from the query and builds an infallible character breakdown."""
445
+ words = re.findall(r'["\']?(\b[a-zA-Z]+)\b["\']?', query)
446
+ if not words:
447
+ return ""
448
+
449
+ lines = ["\n[SYSTEM GROUND-TRUTH LINGUISTIC EVIDENCE]"]
450
+ for word in sorted(list(set(words)), key=len, reverse=True):
451
+ if len(word) >= 3: # Focus on meaningful potential target words
452
+ w_lower = word.lower()
453
+ counts = {}
454
+ for char in w_lower:
455
+ counts[char] = counts.get(char, 0) + 1
456
+ breakdown = ", ".join([f"'{c}': {cnt}" for c, cnt in sorted(counts.items())])
457
+ lines.append(f"The word '{word}' has a length of {len(word)} letters. Exact character breakdown: {breakdown}")
458
+ return "\n".join(lines) if len(lines) > 1 else ""
459
 
460
  def _ensure_experience_embedding_column(conn: sqlite3.Connection) -> None:
461
  """Ensure the experience table has a BLOB column for precomputed embeddings."""
 
716
  }
717
 
718
  def analyze(query: str, plan_data: Dict[str, Any], evidence: str, history: List[Dict[str, str]]) -> str:
719
+ # Inject programmatic linguistic truth into evidence
720
+ truth = _detect_and_count_characters(query)
721
+ if truth:
722
+ evidence = f"{evidence}\n{truth}"
723
+
724
  messages = [
725
  {"role": "system", "content": ANALYST_SYSTEM},
726
  {
 
739
 
740
  def verify(query: str, plan_data: Dict[str, Any], analysis: str, evidence: str) -> str:
741
  """Independent verification pass."""
742
+ # Inject programmatic linguistic truth into evidence for verifier verification
743
+ truth = _detect_and_count_characters(query)
744
+ if truth:
745
+ evidence = f"{evidence}\n{truth}"
746
+
747
  messages = [
748
  {"role": "system", "content": VERIFIER_SYSTEM},
749
  {
 
767
  history: List[Dict[str, str]],
768
  verification: Optional[str] = None,
769
  ) -> str:
770
+ """Final reasoning/synthesis pass."""
771
+ # Ensure final synthesis also sees the correct counts unmistakably
772
+ truth = _detect_and_count_characters(query)
773
+ if truth:
774
+ evidence = f"{evidence}\n{truth}"
775
+
776
  verification_text = verification or "No separate verification pass was supplied."
777
  messages = [
778
  {"role": "system", "content": FINAL_SYSTEM},