AI safety check
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user