Collision/safety_precision/bare-word (adversarial %78.7->%83.0)
Browse files at this commit6f2764b88fbd60576d81f8ccd28f2cb0418585acParent: ec4d3b0- fix
- collision/safety_precision/bare-word (adversarial %78.7->%83.0)
3 changed files +29 -4
- src/engine.py +8 -1
- src/rules.py +18 -2
- src/safety/toxicity.py +3 -1
src/engine.pymodified+8 -1
| @@ -745,7 +745,14 @@ class Engine: | |||
| 745 | and topk[0]["intent"] in _SOCIAL_INTENTS | 745 | and topk[0]["intent"] in _SOCIAL_INTENTS |
| 746 | and topk[1]["intent"] in _SOCIAL_INTENTS | 746 | and topk[1]["intent"] in _SOCIAL_INTENTS |
| 747 | ) | 747 | ) |
| 748 | - ask_mode = pure_negation or ( | 748 | + # Tek kelimelik belirsiz sorgu (ör. "Ayarlar", "Sınav") KURAL değil similarity |
| 749 | + # ile eşleşiyorsa tam cevap verme -> netleştir + öneri (asla yanlış). | ||
| 750 | + single_word_similarity = ( | ||
| 751 | + not response.fallback | ||
| 752 | + and dec["source"] == "similarity" | ||
| 753 | + and len(effective_query.split()) == 1 | ||
| 754 | + ) | ||
| 755 | + ask_mode = pure_negation or single_word_similarity or ( | ||
| 749 | not response.fallback | 756 | not response.fallback |
| 750 | and dec["source"] == "similarity" | 757 | and dec["source"] == "similarity" |
| 751 | and ( | 758 | and ( |
src/rules.pymodified+18 -2
| @@ -130,7 +130,7 @@ _RAW_RULES: Final[list[dict[str, Any]]] = [ | |||
| 130 | {"intent": "course_create", "groups": [ | 130 | {"intent": "course_create", "groups": [ |
| 131 | {"all": ["yeni", "ders"], "none": ["saat", "oturum", "sınav", "öğrenci"]}, | 131 | {"all": ["yeni", "ders"], "none": ["saat", "oturum", "sınav", "öğrenci"]}, |
| 132 | {"all": ["ders", "oluştur"], "none": ["saat", "oturum", "sınav", "öğrenci"]}, | 132 | {"all": ["ders", "oluştur"], "none": ["saat", "oturum", "sınav", "öğrenci"]}, |
| 133 | - {"all": ["ders", "aç"], "none": ["saat", "oturum", "sınav", "öğrenci"]}, | 133 | + {"all": ["ders", "aç"], "none": ["saat", "oturum", "sınav", "öğrenci", "liste"]}, |
| 134 | {"all": ["sınıf", "oluştur"]}, | 134 | {"all": ["sınıf", "oluştur"]}, |
| 135 | ]}, | 135 | ]}, |
| 136 | {"intent": "lesson_session_add", "groups": [ | 136 | {"intent": "lesson_session_add", "groups": [ |
| @@ -149,6 +149,20 @@ _RAW_RULES: Final[list[dict[str, Any]]] = [ | |||
| 149 | {"intent": "exam_add_question", "groups": [ | 149 | {"intent": "exam_add_question", "groups": [ |
| 150 | {"all": ["soru", "ekle"]}, {"all": ["soru", "oluştur"]}, | 150 | {"all": ["soru", "ekle"]}, {"all": ["soru", "oluştur"]}, |
| 151 | {"all": ["seçmeli", "soru"]}, | 151 | {"all": ["seçmeli", "soru"]}, |
| 152 | + # Öğretmenin doğru şıkkı belirlemesi = soru tanımlama (cevap kaydetme DEĞİL). | ||
| 153 | + {"all": ["doğru", "şık"]}, | ||
| 154 | + ]}, | ||
| 155 | + {"intent": "exam_save_answer", "groups": [ | ||
| 156 | + {"all": ["cevab", "kaydet"]}, {"all": ["cevap", "kaydet"]}, | ||
| 157 | + {"all": ["şık", "seç"]}, {"all": ["işaretle", "cevab"]}, | ||
| 158 | + ]}, | ||
| 159 | + {"intent": "exam_live_monitor", "groups": [ | ||
| 160 | + {"all": ["sınav", "takip"]}, {"all": ["anlık", "takip"]}, | ||
| 161 | + {"all": ["sınav", "izle"]}, {"all": ["canlı", "izle"]}, | ||
| 162 | + ]}, | ||
| 163 | + {"intent": "course_view", "groups": [ | ||
| 164 | + {"all": ["ders", "liste"], "none": ["oluştur", "yeni", "öğrenci", "not"]}, | ||
| 165 | + {"all": ["derslerim"], "none": ["oluştur", "not"]}, | ||
| 152 | ]}, | 166 | ]}, |
| 153 | {"intent": "exam_grade_student", "groups": [ | 167 | {"intent": "exam_grade_student", "groups": [ |
| 154 | {"all": ["öğrenci", "not", "gir"]}, {"all": ["notlandır"]}, | 168 | {"all": ["öğrenci", "not", "gir"]}, {"all": ["notlandır"]}, |
| @@ -170,6 +184,7 @@ _RAW_RULES: Final[list[dict[str, Any]]] = [ | |||
| 170 | {"intent": "user_role_change", "groups": [ | 184 | {"intent": "user_role_change", "groups": [ |
| 171 | {"all": ["rol", "değiştir"]}, {"all": ["rol", "ata"]}, | 185 | {"all": ["rol", "değiştir"]}, {"all": ["rol", "ata"]}, |
| 172 | {"all": ["yetki", "yükselt"]}, {"all": ["kullanıcı", "rol"]}, | 186 | {"all": ["yetki", "yükselt"]}, {"all": ["kullanıcı", "rol"]}, |
| 187 | + {"all": ["kullanıcı", "admin"]}, {"all": ["admin", "yap"], "none": ["beni"]}, | ||
| 173 | ]}, | 188 | ]}, |
| 174 | {"intent": "term_manage", "groups": [ | 189 | {"intent": "term_manage", "groups": [ |
| 175 | {"all": ["dönem", "oluştur"]}, {"all": ["akademik", "dönem"]}, | 190 | {"all": ["dönem", "oluştur"]}, {"all": ["akademik", "dönem"]}, |
| @@ -257,7 +272,8 @@ _RAW_RULES: Final[list[dict[str, Any]]] = [ | |||
| 257 | {"intent": "homework_grade", "groups": [ | 272 | {"intent": "homework_grade", "groups": [ |
| 258 | {"all": ["ödev", "notland"]}, {"all": ["ödev", "değerlendir"]}, | 273 | {"all": ["ödev", "notland"]}, {"all": ["ödev", "değerlendir"]}, |
| 259 | {"all": ["ödev", "puan"]}, | 274 | {"all": ["ödev", "puan"]}, |
| 260 | - {"all": ["ödev", "not", "ver"]}, {"all": ["ödev", "not", "gir"]}, | 275 | + {"all": ["ödev", "not", "ver"], "none": ["bak", "aldı", "nereden"]}, |
| 276 | + {"all": ["ödev", "not", "gir"], "none": ["bak", "aldı"]}, | ||
| 261 | ]}, | 277 | ]}, |
| 262 | # --- Backend v2: pomodoro / mesajlar / etüt-kulüp / veli --- | 278 | # --- Backend v2: pomodoro / mesajlar / etüt-kulüp / veli --- |
| 263 | {"intent": "pomodoro_use", "groups": [ | 279 | {"intent": "pomodoro_use", "groups": [ |
src/safety/toxicity.pymodified+3 -1
| @@ -414,7 +414,9 @@ def evaluate_input(message: str, role: str = "ziyaretci", authenticated: bool = | |||
| 414 | profanity = _matched_root(prof_tokens, STRONG_PROFANITY) | 414 | profanity = _matched_root(prof_tokens, STRONG_PROFANITY) |
| 415 | if insult or profanity: | 415 | if insult or profanity: |
| 416 | # Eğitim/alıntı bağlamı -> izin. | 416 | # Eğitim/alıntı bağlamı -> izin. |
| 417 | - educational = any(m in tokens for m in _EDU_MARKERS) or "'" in message or '"' in message | 417 | + educational = any(m in tokens for m in _EDU_MARKERS) or any( |
| 418 | + q in message for q in ("'", '"', "‘", "’", "“", "”") | ||
| 419 | + ) | ||
| 418 | if educational: | 420 | if educational: |
| 419 | return _make(ALLOW, "PROFANITY_EDUCATIONAL", 0, "SAFE-PROF-000", | 421 | return _make(ALLOW, "PROFANITY_EDUCATIONAL", 0, "SAFE-PROF-000", |
| 420 | "", matched=[insult or profanity]) | 422 | "", matched=[insult or profanity]) |