| from typing import Literal | |
| Intent = Literal["clean_room", "go_dock", "play_music", "answer_question", "small_talk", "other"] | |
| def route_intent(text: str) -> Intent: | |
| """Very simple rule-based intent router for short commands. | |
| Works best with lowercase, accent-stripped Vietnamese or English. | |
| """ | |
| t = text.lower() | |
| if any(k in t for k in ["hút bụi", "vacuum", "clean room", "quét nhà"]): | |
| return "clean_room" | |
| if any(k in t for k in ["về sạc", "go charge", "go dock", "về dock"]): | |
| return "go_dock" | |
| if any(k in t for k in ["bật nhạc", "play music", "phát nhạc"]): | |
| return "play_music" | |
| if any(k in t for k in ["thời tiết", "mấy giờ", "how is the weather", "question"]): | |
| return "answer_question" | |
| if any(k in t for k in ["kể chuyện cười", "joke", "chúc ngủ ngon", "good night", "hello", "xin chào"]): | |
| return "small_talk" | |
| return "other" | |
| if __name__ == "__main__": | |
| tests = [ | |
| "Robot ơi hút bụi phòng khách đi", | |
| "Đi về sạc đi", | |
| "Bật nhạc nhẹ giúp tôi với", | |
| "Hôm nay thời tiết thế nào", | |
| "Kể chuyện cười đi", | |
| "Ờ... thôi để sau", | |
| ] | |
| for txt in tests: | |
| print(txt, "->", route_intent(txt)) | |