()
| 34 | |
| 35 | |
| 36 | def build_example_rows() -> list[tuple[str, str, str]]: |
| 37 | rows: list[tuple[str, int, str, str]] = [] |
| 38 | with open(EXAMPLE_TEXTS_JSONL_PATH, "r", encoding="utf-8") as f: |
| 39 | for line in f: |
| 40 | if not line.strip(): |
| 41 | continue |
| 42 | sample = json.loads(line) |
| 43 | parsed = _parse_example_id(sample.get("id", "")) |
| 44 | if parsed is None: |
| 45 | continue |
| 46 | |
| 47 | language, index = parsed |
| 48 | instruction = str(sample.get("instruction", "")).strip() |
| 49 | text = str(sample.get("text", "")).strip() |
| 50 | rows.append((language, index, instruction, text)) |
| 51 | |
| 52 | language_order = {"zh": 0, "en": 1} |
| 53 | rows.sort(key=lambda item: (language_order.get(item[0], 99), item[1])) |
| 54 | return [(f"{language}/{index}", instruction, text) for language, index, instruction, text in rows] |
| 55 | |
| 56 | |
| 57 | EXAMPLE_ROWS = build_example_rows() |
no test coverage detected