Return doctest-style assertions extracted from the task description.
(prompt: Dict[str, Any] | str)
| 29 | |
| 30 | @staticmethod |
| 31 | def extract_example(prompt: Dict[str, Any] | str) -> List[str]: |
| 32 | """Return doctest-style assertions extracted from the task description.""" |
| 33 | if isinstance(prompt, dict): |
| 34 | prompt_text = str(prompt.get("task", "")) |
| 35 | else: |
| 36 | prompt_text = str(prompt) |
| 37 | |
| 38 | lines = [line.strip() for line in prompt_text.splitlines() if line.strip()] |
| 39 | results: List[str] = [] |
| 40 | iterator = iter(lines) |
| 41 | for line in iterator: |
| 42 | if not line.startswith(">>>"): |
| 43 | continue |
| 44 | function_call = line[4:].strip() |
| 45 | expected_output = next(iterator, "").strip() |
| 46 | if not function_call or not expected_output: |
| 47 | continue |
| 48 | results.append(f"assert {function_call} == {expected_output}") |
| 49 | return results |
| 50 | |
| 51 | @staticmethod |
| 52 | def _is_python_code_block(text: str) -> bool: |