v
File size: 984 Bytes
f59a827
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from typing import TypedDict

class SafetyResult(TypedDict):
    safe: bool
    reason: str

UNSAFE_KEYWORDS = [
    "đốt",
    "cháy",
    "nổ",
    "phá hủy",
    "phá hoại",
    "đập vỡ",
    "làm đau",
    "tấn công",
    "giết",
    "cầm dao",
    "tắt báo cháy",
]

def check_safety(command: str) -> SafetyResult:
    """Check whether a Vietnamese command is safe for a home robot to execute."""
    text = command.lower()

    for word in UNSAFE_KEYWORDS:
        if word in text:
            return {
                "safe": False,
                "reason": f"Command contains unsafe keyword: '{word}'",
            }

    # default: safe
    return {
        "safe": True,
        "reason": "No unsafe patterns detected",
    }

if __name__ == "__main__":
    tests = [
        "Bật đèn phòng khách",
        "Đốt rèm cửa đi",
        "Mang dao vào phòng khách",
    ]
    for t in tests:
        print(t, "->", check_safety(t))