Compare commits
1 Commits
step35/150
...
mimo/code/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a69189110c |
@@ -98,11 +98,17 @@ class TrajectoryLogger:
|
|||||||
|
|
||||||
all_cycles = []
|
all_cycles = []
|
||||||
for traj_file in sorted(self.log_dir.glob("trajectory_*.jsonl")):
|
for traj_file in sorted(self.log_dir.glob("trajectory_*.jsonl")):
|
||||||
with open(traj_file) as f:
|
with open(traj_file, encoding="utf-8") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line:
|
if not line:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
all_cycles.append(json.loads(line))
|
all_cycles.append(json.loads(line))
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
# Skip truncated/corrupt lines so one bad append does not
|
||||||
|
# poison the entire export.
|
||||||
|
continue
|
||||||
|
|
||||||
# Quality filter — only keep cycles where the model actually
|
# Quality filter — only keep cycles where the model actually
|
||||||
# produced meaningful thought (not just "Nothing has happened")
|
# produced meaningful thought (not just "Nothing has happened")
|
||||||
|
|||||||
31
tests/test_trajectory_logger.py
Normal file
31
tests/test_trajectory_logger.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import json
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||||
|
if str(PROJECT_ROOT) not in sys.path:
|
||||||
|
sys.path.insert(0, str(PROJECT_ROOT))
|
||||||
|
|
||||||
|
from nexus.trajectory_logger import TrajectoryLogger
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_for_training_skips_malformed_jsonl_lines(tmp_path):
|
||||||
|
logger = TrajectoryLogger(log_dir=tmp_path, system_prompt="System prompt")
|
||||||
|
logger.log_cycle(
|
||||||
|
perception="A useful perception",
|
||||||
|
thought="This is a sufficiently detailed thought for export.",
|
||||||
|
actions=["World responds with a tactical update."],
|
||||||
|
cycle_ms=42,
|
||||||
|
)
|
||||||
|
|
||||||
|
with logger.log_file.open("a", encoding="utf-8") as handle:
|
||||||
|
handle.write('{"id": "broken"\n')
|
||||||
|
|
||||||
|
output = logger.export_for_training(tmp_path / "training.jsonl")
|
||||||
|
|
||||||
|
exported_lines = output.read_text(encoding="utf-8").strip().splitlines()
|
||||||
|
assert len(exported_lines) == 1
|
||||||
|
|
||||||
|
exported_cycle = json.loads(exported_lines[0])
|
||||||
|
assert exported_cycle["id"].endswith("_cycle_0")
|
||||||
|
assert exported_cycle["message_count"] == 4
|
||||||
Reference in New Issue
Block a user