Spaces:
Sleeping
Sleeping
Rajan Sharma
commited on
Create clarifier.py
Browse files- clarifier.py +27 -0
clarifier.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# clarifier.py
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
from typing import Dict, Any, List
|
| 4 |
+
|
| 5 |
+
def missing_inputs_questions(plan: Dict[str,Any], binding: Dict[str,Dict[str,Any]]) -> List[str]:
|
| 6 |
+
"""
|
| 7 |
+
For each required input in plan['requires'], if binding[name]['match'] is None or score too low,
|
| 8 |
+
produce a specific question asking for the exact data or where it lives.
|
| 9 |
+
"""
|
| 10 |
+
reqs = [r.get("input") or r.get("name") or "" for r in (plan.get("requires") or [])]
|
| 11 |
+
out: List[str] = []
|
| 12 |
+
for r in reqs:
|
| 13 |
+
b = binding.get(r, {})
|
| 14 |
+
if (not b) or (b.get("match") is None) or (float(b.get("score", 0.0)) < 0.46):
|
| 15 |
+
out.append(f"Where can I find **{r}** in your files (exact column name), or please provide its value?")
|
| 16 |
+
# Always end with planning constraints
|
| 17 |
+
if out:
|
| 18 |
+
out.append("Any constraints (time windows, cohorts, or routing/scheduling rules) I should apply?")
|
| 19 |
+
return out
|
| 20 |
+
|
| 21 |
+
def render_phase1_markdown(questions: List[str]) -> str:
|
| 22 |
+
if not questions:
|
| 23 |
+
return "**Clarification Questions**\n- No data gaps detected. Please confirm to proceed with analysis."
|
| 24 |
+
out = ["**Clarification Questions**"]
|
| 25 |
+
for q in questions:
|
| 26 |
+
out.append(f"- {q}")
|
| 27 |
+
return "\n".join(out)
|