feat(gtm): v2.5 - Hard Fact Extraction & UI
- Backend: Implemented secondary extraction phase for structured specs (JSON schema). - Backend: Added strict normalization rules (min, cm, kg). - Frontend: Added 'Phase1Data' interface update for specs. - Frontend: Implemented new UI component for 'Technical Specifications' in Phase 1. - Frontend: Updated header and sidebar to display 'v2.5' build marker. - Docs: Updated architectural documentation.
This commit is contained in:
@@ -203,6 +203,90 @@ def phase1(payload):
|
||||
|
||||
try:
|
||||
data = json.loads(response)
|
||||
|
||||
# --- PART 2: HARD FACTS EXTRACTION ---
|
||||
spec_schema = """
|
||||
{
|
||||
"metadata": {
|
||||
"product_id": "string (slug)",
|
||||
"brand": "string",
|
||||
"model_name": "string",
|
||||
"category": "cleaning | service | security | industrial",
|
||||
"manufacturer_url": "string"
|
||||
},
|
||||
"core_specs": {
|
||||
"battery_runtime_min": "integer (standardized to minutes)",
|
||||
"charge_time_min": "integer (standardized to minutes)",
|
||||
"weight_kg": "float",
|
||||
"dimensions_cm": { "l": "float", "w": "float", "h": "float" },
|
||||
"max_slope_deg": "float",
|
||||
"ip_rating": "string",
|
||||
"climb_height_cm": "float",
|
||||
"navigation_type": "string (e.g. SLAM, LiDAR, VSLAM)",
|
||||
"connectivity": ["string"]
|
||||
},
|
||||
"layers": {
|
||||
"cleaning": {
|
||||
"fresh_water_l": "float",
|
||||
"dirty_water_l": "float",
|
||||
"area_performance_sqm_h": "float",
|
||||
"mop_pressure_kg": "float"
|
||||
},
|
||||
"service": {
|
||||
"max_payload_kg": "float",
|
||||
"number_of_trays": "integer",
|
||||
"display_size_inch": "float",
|
||||
"ads_capable": "boolean"
|
||||
},
|
||||
"security": {
|
||||
"camera_types": ["string"],
|
||||
"night_vision": "boolean",
|
||||
"gas_detection": ["string"],
|
||||
"at_interface": "boolean"
|
||||
}
|
||||
},
|
||||
"extended_features": [
|
||||
{ "feature": "string", "value": "string", "unit": "string" }
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
specs_prompt = f"""
|
||||
PHASE 1 (Part 2): HARD FACT EXTRACTION
|
||||
Input: "{analysis_content}"
|
||||
|
||||
Task: Extract technical specifications strictly according to the provided JSON schema.
|
||||
|
||||
NORMALIZATION RULES (STRICTLY FOLLOW):
|
||||
1. Time: Convert ALL time values (runtime, charging) to MINUTES (Integer). Example: "1:30 h" -> 90, "2 hours" -> 120.
|
||||
2. Dimensions/Weight: All lengths in CM, weights in KG.
|
||||
3. Performance: Area performance always in m²/h.
|
||||
4. Booleans: Use true/false (not strings).
|
||||
5. Unknowns: If a value is not in the text, set it to null. DO NOT HALLUCINATE.
|
||||
|
||||
LOGIC FOR LAYERS:
|
||||
- If product uses water/brushes -> Fill 'layers.cleaning'.
|
||||
- If product delivers items/trays -> Fill 'layers.service'.
|
||||
- If product patrols/detects -> Fill 'layers.security'.
|
||||
|
||||
EXTENDED FEATURES:
|
||||
- Put any technical feature that doesn't fit the schema into 'extended_features'.
|
||||
|
||||
Output JSON format ONLY based on this schema:
|
||||
{spec_schema}
|
||||
"""
|
||||
|
||||
log_and_save(project_id, "phase1_specs", "prompt", specs_prompt)
|
||||
specs_response = call_gemini_flash(specs_prompt, system_instruction=sys_instr, json_mode=True)
|
||||
log_and_save(project_id, "phase1_specs", "response", specs_response)
|
||||
|
||||
try:
|
||||
specs_data = json.loads(specs_response)
|
||||
data['specs'] = specs_data
|
||||
except json.JSONDecodeError:
|
||||
logging.error(f"Failed to decode JSON from Gemini response in phase1 (specs): {specs_response}")
|
||||
data['specs'] = {"error": "Failed to extract specs", "raw": specs_response}
|
||||
|
||||
db_manager.save_gtm_result(project_id, 'phase1_result', json.dumps(data))
|
||||
|
||||
# WICHTIG: ID zurückgeben, damit Frontend sie speichert
|
||||
|
||||
Reference in New Issue
Block a user