feat(maker): AI parsing schede tecniche PDF via OpenRouter
- Nuovo servizio ai_service.py: estrae testo da PDF (pdfplumber) + analisi AI (OpenRouter)
- Endpoint POST /api/recipes/{id}/parse-technical-sheet con validazione file
- UI: bottone "Importa da PDF" nel task editor con modale upload + preview editabile
- Task suggeriti modificabili/rimovibili prima della creazione bulk
- Config: OPENROUTER_API_KEY e OPENROUTER_MODEL in .env
- Dipendenze: pdfplumber + httpx aggiunti a server deps
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -424,3 +424,24 @@ def api_get_measurement_count(recipe_id: int, version_number: int):
|
||||
return jsonify(resp), resp.get("status_code", 500)
|
||||
|
||||
return jsonify(resp), 200
|
||||
|
||||
|
||||
@maker_bp.route("/api/recipes/<int:recipe_id>/parse-technical-sheet", methods=["POST"])
|
||||
@login_required
|
||||
@role_required("Maker")
|
||||
def api_parse_technical_sheet(recipe_id: int):
|
||||
"""Proxy: Parse PDF technical sheet with AI."""
|
||||
file = request.files.get("file")
|
||||
if not file:
|
||||
return jsonify({"error": True, "detail": "Nessun file caricato"}), 400
|
||||
|
||||
api_key = session.get("api_key", "")
|
||||
base_url = Config.API_SERVER_URL.rstrip("/")
|
||||
resp = http_requests.post(
|
||||
f"{base_url}/api/recipes/{recipe_id}/parse-technical-sheet",
|
||||
headers={"X-API-Key": api_key},
|
||||
files={"file": (file.filename, file.stream, file.content_type)},
|
||||
timeout=90,
|
||||
)
|
||||
|
||||
return jsonify(resp.json()), resp.status_code
|
||||
|
||||
Reference in New Issue
Block a user