| |
| """Local tests for the accepted-baseline parser path.""" |
|
|
| import json |
|
|
| from script import build_prompt, count_expected_answers, parse_model_output |
|
|
|
|
| BASELINE_SYSTEM = ( |
| "You solve International Linguistics Olympiad problems using only the data in the problem. " |
| "Infer the pattern from the examples. Think silently. Return valid JSON only: " |
| '{"answers": ["..."]}' |
| ) |
|
|
|
|
| def check_parse(raw: str, expected: list[str]) -> None: |
| actual = parse_model_output(raw, None) |
| assert actual == expected, (raw, actual, expected) |
|
|
| encoded = json.dumps(actual, ensure_ascii=False) |
| assert json.loads(encoded) == expected |
|
|
|
|
| def main() -> None: |
| assert count_expected_answers("Translate:\n1. mi\n2. yu") is None |
| assert count_expected_answers("") is None |
|
|
| messages = build_prompt( |
| { |
| "task_type": "match_letter", |
| "eval_type": "single", |
| "context": "1. context item should not affect answer count", |
| "query": "Translate this one item.", |
| }, |
| None, |
| ) |
| assert messages[0]["content"] == BASELINE_SYSTEM |
| assert "Task type: match_letter" in messages[1]["content"] |
| assert "Return one answer per numbered item." in messages[1]["content"] |
| assert "Use the context examples" not in messages[1]["content"] |
|
|
| check_parse("1. abc\n2. def", ["abc", "def"]) |
| check_parse("1. abc\n2. def\n3. ghi\n4. jkl\n5. mno", ["abc", "def", "ghi", "jkl", "mno"]) |
| check_parse("(a) k谩 [艐a]\n- 膷始a\n2) O'Neil", ["k谩 [艐a]", "膷始a", "O'Neil"]) |
| check_parse("'谩艐a' [x] /t汀s始/\n(kept)", ["'谩艐a' [x] /t汀s始/", "(kept)"]) |
| check_parse(" keep internal spaces ", ["keep internal spaces"]) |
| check_parse("", []) |
| check_parse('{"answers": ["mi go", "yu sleep"]}', ['{"answers": ["mi go", "yu sleep"]}']) |
| check_parse('["k谩 [艐a]", "膷始a"]', ['["k谩 [艐a]", "膷始a"]']) |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|