Files
Smartwave/cloud/safety_checker.py
T
Ninluc ddc136a5ca
Build, push image, and notify Watchtower / build-image (push) Successful in 1m59s
Build, push image, and notify Watchtower / notify (push) Successful in 10s
AI safety check
2026-08-10 16:36:27 +02:00

42 lines
1.3 KiB
Python

import json
from APIs.aichat import generate
DISH_SAFETY_SCHEMA = {
"type": "object",
"properties": {
"is_safe": {
"type": "boolean",
"description": "True if no microwave hazards (metal, foil, sealed packaging) are present."
},
"warning_message": {
"type": "string",
"description": "Explanation of any hazard found, or an empty string if safe."
},
"detected_hazards": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of specific hazard items detected."
}
},
"required": ["is_safe", "warning_message", "detected_hazards"]
}
def check_dish_safety(image_path: str) -> dict:
prompt = (
"Analyze this top-down photo of a dish prepared for microwave cooking. "
"Inspect the area for metal utensils, aluminum foil, metallic dish patterns, or unvented plastic wraps."
)
# Pass the schema directly to the generation call
response_raw = generate(
prompt=prompt,
images=[image_path],
output_format=DISH_SAFETY_SCHEMA # Passed as Ollama's `format` parameter
)
if isinstance(response_raw, dict):
return response_raw
return json.loads(response_raw)