"""多语言工单/邮件分诊:一次前向传播同时回答 部门 / 紧急度 / 流失风险 / 情绪。 用法: python apps/inbox_triage.py # 跑内置样例(中/英/日/西/印地语) python apps/inbox_triage.py "你的邮件正文" """ import sys, json, time from common import get_agent, show QUESTIONS = { "department": {"type": "choice", "instructions": "Which team should handle this message?", "criteria": {"billing": "invoices, payments, refunds, double charge", "technical": "bugs, crashes, outages, login failures", "sales": "pricing, quotes, upgrades, enterprise plans", "shipping": "delivery, tracking, lost or damaged package"}}, "urgency": {"type": "score", "instructions": "How urgent is this?", "criteria": ["not urgent", "soon", "blocking"]}, "churn_risk": {"type": "noul", "instructions": "Does the user threaten to cancel or leave?"}, "sentiment": {"type": "choice", "instructions": "What is the customer's tone?", "criteria": {"angry": "furious, threatening, insulting", "frustrated": "annoyed but civil", "neutral": "matter of fact", "happy": "grateful, positive"}}, } SAMPLES = [ {"subject": "Duplicate charge on invoice 4411", "body": "We were billed twice for March. Please refund the duplicate or we're moving to a competitor."}, {"subject": "登录一直失败", "body": "从昨天开始整个团队都登录不了后台,报 502,我们的上线被卡住了,急!"}, {"subject": "見積もりのお願い", "body": "エンタープライズプランの料金と年間契約の割引について教えてください。"}, {"subject": "Paquete perdido", "body": "El rastreo dice entregado pero no recibí nada. Llevo una semana esperando, estoy muy molesto."}, {"subject": "धन्यवाद", "body": "आपकी टीम ने मेरी समस्या बहुत जल्दी हल कर दी। बहुत बहुत धन्यवाद!"}, ] def main(): agent = get_agent("multilingual") states = [{"subject": "(cli)", "body": " ".join(sys.argv[1:])}] if len(sys.argv) > 1 else SAMPLES for s in states: t = time.time() r = agent.predict(s, QUESTIONS) dt = (time.time() - t) * 1000 print(f"\n=== {s['subject']} [{dt:.0f} ms]\n {s['body'][:80]}") show(r) if __name__ == "__main__": main()