Better prompt ?
This commit is contained in:
+12
-21
@@ -4,42 +4,33 @@ from APIs.aichat import generate
|
||||
import shared.config as config
|
||||
|
||||
|
||||
# 1. Output schema with strict anti-hallucination descriptions
|
||||
class DishSafetyResult(BaseModel):
|
||||
visible_objects: list[str] = Field(
|
||||
description="Objective list of physical items visible (e.g., 'black plastic tray', 'stew', 'plastic fork'). Do NOT categorize them as safe or hazards here."
|
||||
description="List physical container items and utensils visible in the image."
|
||||
)
|
||||
material_analysis: str = Field(
|
||||
description="Describe physical materials based strictly on visual cues. Note: Smooth, rigid black plastic meal trays are Polypropylene/CPET plastic (safe), NOT foam/styrofoam."
|
||||
description="Brief description of container material (e.g., standard plastic tray, glass bowl)."
|
||||
)
|
||||
detected_hazards: list[str] = Field(
|
||||
description=(
|
||||
"List ONLY explicit physical hazards: metal utensils/cutlery, aluminum foil/wrappers, "
|
||||
"metallic foil trim, spongy white foam/styrofoam containers, or airtight unvented plastic wrap. "
|
||||
"Rigid black or clear plastic meal trays are NOT hazards. Empty if none."
|
||||
)
|
||||
description="List of visually confirmed metal or foil hazards. MUST be empty [] if no metal or foil is present."
|
||||
)
|
||||
is_safe: bool = Field(
|
||||
description="Set to True if detected_hazards is completely empty. Otherwise set to False."
|
||||
description="Set to True if detected_hazards is empty. Set to False ONLY if metal or aluminum foil is present."
|
||||
)
|
||||
warning_message: str = Field(
|
||||
description="One brief sentence warning if detected_hazards is non-empty, otherwise an empty string."
|
||||
description="Short warning if is_safe is False, otherwise an empty string."
|
||||
)
|
||||
|
||||
|
||||
def check_dish_safety(image_path: str) -> dict:
|
||||
prompt = (
|
||||
"Analyze this food image for critical microwave safety hazards.\n\n"
|
||||
"MATERIAL IDENTIFICATION RULES:\n"
|
||||
"- Black plastic meal trays / TV dinner containers = Smooth, rigid Polypropylene (PP) or CPET plastic. These are STANDARD MICROWAVE MEAL TRAYS and are SAFE.\n"
|
||||
"- Styrofoam / EPS = White or light-colored spongy, cellular foam. (Do NOT misclassify smooth black plastic as styrofoam!).\n\n"
|
||||
"STRICT HAZARDS TO LOOK FOR:\n"
|
||||
"1. Metal objects (metal forks, spoons, knives, metal bowls).\n"
|
||||
"2. Aluminum foil or foil packaging.\n"
|
||||
"3. Metallic gold/silver decorative trim on ceramic dishes.\n"
|
||||
"4. White spongy foam / Styrofoam packaging.\n"
|
||||
"5. Tightly sealed, unvented plastic film or foil lids.\n\n"
|
||||
"If the meal is simply inside a standard black plastic tray or ceramic/glass dish without any metal/foil/foam present, flag it as SAFE (is_safe = True)."
|
||||
"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 []."
|
||||
)
|
||||
|
||||
response_raw = generate(
|
||||
|
||||
Reference in New Issue
Block a user