Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """Debug Hindi language enforcement.""" | |
| from validator import validate, _detect_language_mix | |
| # Test case: Hindi merchant, pure English message | |
| category_ctx = { | |
| "slug": "dentists", | |
| "voice": { | |
| "tone": "peer-clinical", | |
| "vocab_allowed": ["procedure"], | |
| "vocab_taboo": ["guaranteed", "cure"], | |
| }, | |
| } | |
| merchant_ctx = { | |
| "identity": { | |
| "name": "Dr. Meera", | |
| "languages": ["en", "hi"], # REQUIRES Hindi-English mix | |
| }, | |
| "customer_aggregate": {"high_risk_adult_count": 124} | |
| } | |
| trigger_ctx = { | |
| "kind": "research_digest", | |
| } | |
| pure_english = "Dr. Meera, JIDA Oct issue shows fluoride cuts cavities by 38%. Your 124 high-risk patients should know. Want me to draft?" | |
| print("INPUT:") | |
| print(f" Message: {pure_english}") | |
| print(f" Merchant languages: {merchant_ctx['identity']['languages']}") | |
| print() | |
| # Debug checks | |
| print("DEBUG CHECKS:") | |
| languages = merchant_ctx.get("identity", {}).get("languages", []) | |
| print(f" languages extracted: {languages}") | |
| wants_mix = "hi" in languages | |
| print(f" wants_mix (hi in languages): {wants_mix}") | |
| has_mix = _detect_language_mix(pure_english) | |
| print(f" has_mix (_detect_language_mix): {has_mix}") | |
| should_fail = wants_mix and not has_mix | |
| print(f" should_fail (wants_mix and not has_mix): {should_fail}") | |
| print() | |
| # Run validator | |
| is_valid, problems = validate(pure_english, "open_ended", category_ctx, merchant_ctx, trigger_ctx, None) | |
| print("VALIDATOR OUTPUT:") | |
| print(f" is_valid: {is_valid}") | |
| print(f" problems: {problems}") | |