Better prompt
This commit is contained in:
+14
-8
@@ -6,21 +6,27 @@ import shared.config as config
|
|||||||
|
|
||||||
# 1. Define the output schema as a Pydantic model
|
# 1. Define the output schema as a Pydantic model
|
||||||
class DishSafetyResult(BaseModel):
|
class DishSafetyResult(BaseModel):
|
||||||
is_safe: bool = Field(
|
visible_objects: list[str] = Field(
|
||||||
description="True if no microwave hazards presents."
|
description="List all distinct physical objects visible in or around the dish (e.g., bowl, liquid, spoon, cover)."
|
||||||
)
|
)
|
||||||
warning_message: str = Field(
|
material_analysis: str = Field(
|
||||||
description=f"Short explanation of any hazard found (no more than one sentence), or an empty string if safe.",
|
description="Analyze the physical material of each visible object (e.g., ceramic, stainless steel, glass, flexible film)."
|
||||||
)
|
)
|
||||||
detected_hazards: list[str] = Field(
|
detected_hazards: list[str] = Field(
|
||||||
description="List of specific hazard items detected. Only include items that are actually present in the image. If no hazards are detected, this list should be empty."
|
description="List only the items from visible_objects made of metal, metallic foil/trim, or sealed plastic. Empty if none."
|
||||||
|
)
|
||||||
|
is_safe: bool = Field(
|
||||||
|
description="Must be set to True ONLY if detected_hazards is empty. Otherwise False."
|
||||||
|
)
|
||||||
|
warning_message: str = Field(
|
||||||
|
description="One short sentence explaining the hazard if detected_hazards is not empty, otherwise an empty string."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def check_dish_safety(image_path: str) -> dict:
|
def check_dish_safety(image_path: str) -> dict:
|
||||||
prompt = (
|
prompt = (
|
||||||
"Analyze this top-down photo of a dish prepared for microwave cooking. "
|
"Examine this top-down photo of a dish intended for a microwave. "
|
||||||
"Inspect the area for metal utensils, aluminum foil, metallic dish patterns, or unvented plastic wraps that could be dangerous for the dish microwave cooking process or pose a safety risk."
|
"Carefully inspect all visible objects and their surface materials to determine if any microwave safety hazards exist."
|
||||||
)
|
)
|
||||||
|
|
||||||
# 2. Pass the Pydantic class directly to generate()
|
# 2. Pass the Pydantic class directly to generate()
|
||||||
@@ -28,7 +34,7 @@ def check_dish_safety(image_path: str) -> dict:
|
|||||||
prompt=prompt,
|
prompt=prompt,
|
||||||
images=[image_path],
|
images=[image_path],
|
||||||
output_format=DishSafetyResult,
|
output_format=DishSafetyResult,
|
||||||
should_think=False
|
should_think=False,
|
||||||
)
|
)
|
||||||
print(f"[Debug] Raw response from AI generator: {response_raw}")
|
print(f"[Debug] Raw response from AI generator: {response_raw}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user