Bettter safety check
This commit is contained in:
+22
-14
@@ -3,34 +3,42 @@ 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):
|
||||
visible_objects: list[str] = Field(
|
||||
description="List physical container items and utensils visible in the image."
|
||||
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="Brief description of container material (e.g., standard plastic tray, glass bowl)."
|
||||
description="Short description of the materials present."
|
||||
)
|
||||
detected_hazards: list[str] = Field(
|
||||
description="List of visually confirmed metal or foil hazards. MUST be empty [] if no metal or foil is present."
|
||||
description="List objects from utensils_and_containers where is_metal is True."
|
||||
)
|
||||
is_safe: bool = Field(
|
||||
description="Set to True if detected_hazards is empty. Set to False ONLY if metal or aluminum foil is present."
|
||||
description="True if detected_hazards is completely empty []. False if ANY metal is found."
|
||||
)
|
||||
warning_message: str = Field(
|
||||
description="Short warning if is_safe is False, otherwise an empty string."
|
||||
description="If is_safe is False, set to 'REMOVE METAL UTENSIL OR FOIL BEFORE MICROWAVING'. Otherwise empty ''."
|
||||
)
|
||||
|
||||
|
||||
def check_dish_safety(image_path: str) -> dict:
|
||||
prompt = (
|
||||
"Analyze this food image for microwave safety.\n\n"
|
||||
"DEFAULT ASSUMPTION:\n"
|
||||
"- Assume the dish is SAFE (is_safe = True, detected_hazards = []).\n"
|
||||
"- Standard food (meat, vegetables, potatoes) and standard containers (black plastic meal trays, plastic bowls, ceramic, glass) are 100% SAFE for microwaves.\n\n"
|
||||
"STRICT HAZARD RULE:\n"
|
||||
"- Flag as UNSAFE ONLY if you can literally see actual metal cutlery (metal spoon/fork/knife), aluminum foil packaging, or metal foil trim in the image.\n"
|
||||
"- Do NOT invent or hallucinate hazards. If you do not see shiny metal or aluminum foil, detected_hazards MUST be an empty list []."
|
||||
"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."
|
||||
)
|
||||
|
||||
response_raw = generate(
|
||||
|
||||
Reference in New Issue
Block a user