Spaces:
Sleeping
Sleeping
| from loguru import logger | |
| from app.dto.response import DialogServiceResult | |
| from app.services.helper import extra_time_dialogflow | |
| class TimeService: | |
| def check_time_ambiguity(time: str | dict) -> bool: | |
| """ | |
| Kiểm tra xem thời gian có phải là dạng mơ hồ (ambiguous) hay không. | |
| Args: | |
| time (str | list): Thời gian có thể là chuỗi hoặc danh sách các thời gian. | |
| Returns: | |
| bool: True nếu thời gian là mơ hồ, False nếu rõ ràng. | |
| """ | |
| if not time: | |
| logger.error("[TimeService][check_time_ambiguity] Time is empty") | |
| raise ValueError("Time is required") | |
| time = extra_time_dialogflow(time) | |
| return isinstance(time, list) | |
| def get_time_ambiguous_selection(time: str | dict) -> DialogServiceResult: | |
| """ | |
| Trả về danh sách các lựa chọn thời gian nếu thời gian là mơ hồ. | |
| Args: | |
| time (str | list): Thời gian có thể là chuỗi hoặc danh sách các thời gian. | |
| Returns: | |
| list[str]: Danh sách các lựa chọn thời gian nếu mơ hồ, rỗng nếu không. | |
| """ | |
| time = extra_time_dialogflow(time) | |
| if isinstance(time, str): | |
| # Nếu thời gian là chuỗi rõ ràng, trả về False và chuỗi đó | |
| parameters = {"is_time_ambiguous": False} | |
| return DialogServiceResult(parameters=parameters) | |
| if isinstance(time, list): | |
| text = "Vui lòng chọn thời gian cụ thể:\n" | |
| text += "\n".join(f"{i+1}. {t}" for i, t in enumerate(time)) | |
| return DialogServiceResult( | |
| text=[text], | |
| payload=time, | |
| parameters={"is_time_ambiguous": True}, | |
| ) | |
| text = "Vui lòng chỉ định thời gian cụ thể" | |
| return DialogServiceResult(text=[text]) | |