File size: 1,056 Bytes
1e2c036
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Stable example output loading for demo playback."""

from __future__ import annotations

import json
from pathlib import Path

from src.models.schema import GenerationResult, TraceRecord


DEFAULT_SAMPLE_TRACE_DIR = Path("data/traces/samples")


def sample_trace_path(index: int, sample_dir: Path = DEFAULT_SAMPLE_TRACE_DIR) -> Path | None:
    """Return the committed sample trace path for a 0-based example index."""
    trace_id = f"sample-{index + 1:02d}"
    matches = sorted(sample_dir.glob(f"{trace_id}-*.json"))
    return matches[0] if matches else None


def load_sample_generation(index: int, sample_dir: Path = DEFAULT_SAMPLE_TRACE_DIR) -> GenerationResult | None:
    path = sample_trace_path(index, sample_dir)
    if path is None:
        return None

    trace = TraceRecord.model_validate(json.loads(path.read_text(encoding="utf-8")))
    return GenerationResult(
        object_understanding=trace.object_understanding,
        persona=trace.persona,
        diary=trace.diary,
        trace=trace,
        trace_path=str(path),
    )