File size: 1,417 Bytes
0490201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
from __future__ import annotations

import json
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
    sys.path.insert(0, str(ROOT))

from ML_Pipeline.steering.music_steering_spec import MusicSteeringSpec


def extract_think_payload(raw_text: str) -> dict:
    start_token = "<|think|>"
    end_token = "</|think|>"
    start = raw_text.find(start_token)
    end = raw_text.find(end_token)

    if start == -1 or end == -1 or end <= start:
        raise ValueError("Missing <|think|> payload block.")

    payload = raw_text[start + len(start_token):end].strip()
    return json.loads(payload)


def main() -> int:
    raw_text = """
Prelude
<|think|>
{
  "schema_version": "1.1",
  "emotion": {"energy": 0.82, "valence": 0.38, "tension": 0.71},
  "rhythm": {"tempo_bpm": 132.0, "syncopation": 0.44, "density": 0.67},
  "style_tags": ["dark-synth", "industrial", "cinematic"],
  "notes": ["bridge-build", "dummy-payload"]
}
</|think|>
Postlude
""".strip()

    payload = extract_think_payload(raw_text)
    steering = MusicSteeringSpec.from_dict(payload)
    report = {
        "status": "PASS",
        "schema_version": payload.get("schema_version", "missing"),
        "parsed": steering.to_dict(),
    }
    print(json.dumps(report, indent=2, sort_keys=True))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())