Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| from pathlib import Path | |
| from typing import Any | |
| import json | |
| from .demo_packs import load_demo_pack | |
| from .storage import DEFAULT_DB_PATH, SQLiteStore | |
| def ingest_demo_pack(pack_path: str | Path, db_path: str | Path = DEFAULT_DB_PATH, reset: bool = False) -> dict[str, Any]: | |
| pack = load_demo_pack(pack_path) | |
| manifest = pack.manifest | |
| manuals = manifest.get('manuals', []) if isinstance(manifest, dict) else [] | |
| jobs = manifest.get('jobs', []) if isinstance(manifest, dict) else [] | |
| if reset: | |
| db_file = Path(db_path) | |
| if db_file.exists(): | |
| db_file.unlink() | |
| store = SQLiteStore(db_path, Path(pack.path) / '_artifacts') | |
| try: | |
| for job in jobs: | |
| title = job.get('title', job.get('job_id', 'job')) | |
| payload = { | |
| 'job_id': job.get('job_id'), | |
| 'title': title, | |
| 'equipment_type': job.get('equipment_type'), | |
| 'severity': job.get('severity'), | |
| 'expected_section_titles': job.get('expected_section_titles', []), | |
| } | |
| text = '\n'.join(filter(None, [job.get('symptom', ''), job.get('notes', ''), job.get('resolution', '')])) | |
| store.store_record(pack.project, pack.pack_id, title, text, payload) | |
| store._conn.commit() | |
| finally: | |
| store.close() | |
| return { | |
| 'pack_id': pack.pack_id, | |
| 'manual_count': len(manuals), | |
| 'job_count': len(jobs), | |
| 'description': manifest.get('description', pack.description), | |
| } | |