From 467740ba844d67a71d2728a4e56f2f0185acd593 Mon Sep 17 00:00:00 2001 From: Matthias Guillitte Date: Sun, 23 Aug 2026 12:51:55 +0200 Subject: [PATCH] Better prompt --- cloud/safety_checker.py | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/cloud/safety_checker.py b/cloud/safety_checker.py index 2458136..25cde84 100644 --- a/cloud/safety_checker.py +++ b/cloud/safety_checker.py @@ -3,41 +3,26 @@ from pydantic import BaseModel, Field from APIs.aichat import generate import shared.config as config -class UtensilMaterialCheck(BaseModel): - object_name: str = Field( - description="Name of utensil or container seen (e.g., spoon, fork, tray)." - ) - is_metal: bool = Field( - description="True ONLY if the object is made of metal, stainless steel, or aluminum." - ) - class DishSafetyResult(BaseModel): - utensils_and_containers: list[UtensilMaterialCheck] = Field( - description="List each visible non-food object and check if it is made of metal." - ) - material_analysis: str = Field( - description="Short description of the materials present." + is_safe: bool = Field( + description="Set to True if the dish contains ONLY normal food, rice, stew, and ceramic/glass/plastic bowls. Set to False ONLY if shiny metallic cutlery (spoon/fork/knife) or metallic foil is present." ) detected_hazards: list[str] = Field( - description="List objects from utensils_and_containers where is_metal is True." - ) - is_safe: bool = Field( - description="True if detected_hazards is completely empty []. False if ANY metal is found." + description="List ONLY physical metal objects found (e.g., ['metal spoon']). If is_safe is True, this MUST be an empty list []." ) warning_message: str = Field( - description="If is_safe is False, set to 'REMOVE METAL UTENSIL OR FOIL BEFORE MICROWAVING'. Otherwise empty ''." + description="Clear warning if is_safe is False, otherwise empty string ''." ) def check_dish_safety(image_path: str) -> dict: prompt = ( - "Analyze this microwave dish image strictly for EQUIPMENT DAMAGE HAZARDS (Metal, Steel, Aluminum Foil).\n\n" - "GOAL:\n" - "Identify if any metallic item (metal spoon, fork, knife, aluminum foil, wire) is inside the dish.\n\n" - "RULES:\n" - "1. Examine all utensils carefully, even in dim lighting or dark spots.\n" - "2. Spoons, forks, and knives are often STAINLESS STEEL / METAL. If a spoon or fork is visible, mark is_metal = True unless it is clearly bright colored plastic.\n" - "3. Ignore chemical or health concerns (plastic cancer risks are IRRELEVANT). Focus ONLY on spark/fire hazards (metal, foil).\n" - "4. If ANY utensil is metal: set is_metal=True, add it to detected_hazards, and set is_safe=False." + "You are a microwave safety vision inspector.\n\n" + "TASK: Check if this dish contains any REAL METAL CUTLERY (metal spoons, forks, knives) or ALUMINUM FOIL.\n\n" + "CRITICAL RULES:\n" + "1. Rice, curry, stew, potatoes, herbs, dark sauce, and ceramic/plastic/glass bowls are SAFE food items.\n" + "2. Camera image noise, shadows, and food textures are NOT metal objects.\n" + "3. Unless a shiny, metallic silver/gold utensil or foil sheet is clearly visible, mark is_safe = True and detected_hazards = [].\n" + "4. Do NOT invent or guess utensils if none are clearly visible." ) response_raw = generate(