diff --git a/cloud/safety_checker.py b/cloud/safety_checker.py index 55b5aad..98fa484 100644 --- a/cloud/safety_checker.py +++ b/cloud/safety_checker.py @@ -4,27 +4,30 @@ from APIs.aichat import generate import shared.config as config class DishSafetyResult(BaseModel): - visible_objects: list[str] = Field( - description="List EVERY distinct item visible in the frame, one item per list element (e.g., ['ceramic bowl', 'rice', 'metal spoon handle', 'stew'])." + step_1_visible_items: list[str] = Field( + description="List ONLY 2-3 broad visible items (e.g., ['ceramic bowl', 'brown stew']). Do NOT guess objects if blurry." ) - is_safe: bool = Field( - description="Is the microwave dish safe to microwave? True if safe, False if unsafe." + step_2_has_metal_or_cutlery: bool = Field( + description="Is a metal spoon, fork, knife, or foil clearly visible? True ONLY if distinct metal is seen, otherwise False." ) detected_hazards: list[str] = Field( - description="List ONLY physical hazard items found. Empty list [] if safe." + description="List ONLY physical metal items (e.g. ['metal spoon']). MUST be an empty list [] if step_2 is False." + ) + is_safe: bool = Field( + description="MUST be True if step_2 is False. Set to False ONLY if metal cutlery/foil is present." ) warning_message: str = Field( - description="Warning statement if unsafe, otherwise empty string ''." + description="Short warning if unsafe, otherwise empty string ''." ) def check_dish_safety(image_path: str) -> dict: prompt = ( - "You are an expert microwave safety quality inspector analyzing a top-down camera frame.\n\n" - "INSPECTION STEPS:\n" - "Describe what you see in the image, identify any viewable hazards, and determine if the dish is safe to microwave.\n" - "Alert only if the cooking of the dish **will cause damage** to the microwave or the dish itself, like metallic objects.\n\n" - "NOTES:\n" - "The camera focus is wrongly setup, so the image may be blurry. Please do not take the blurriness or lack of view into a hazard" + "You are a strict microwave safety vision inspector analyzing a top-down frame.\n\n" + "RULES:\n" + "1. First, list basic items in `step_1_visible_items`.\n" + "2. Examine the dish for shiny metallic cutlery, forks, spoons, or aluminum foil.\n" + "3. Set `step_2_has_metal_or_cutlery` to True ONLY if clear metallic cutlery is visible.\n" + "4. If the image is blurry and no metal is clearly identified, assume NO metal is present (step_2 = False, is_safe = True)." ) response_raw = generate( @@ -33,9 +36,11 @@ def check_dish_safety(image_path: str) -> dict: output_format=DishSafetyResult, should_think=False, ) + if config.DEBUG_MESSAGES: print(f"[Debug] Raw response from AI generator: {response_raw}") + # Handling response mapping... if isinstance(response_raw, str): try: validated_result = DishSafetyResult.model_validate_json(response_raw)