Extract the first fenced code block; fall back to raw text. The regex is permissive about the language tag (e.g. ```py / ```python3 / ``` ... ```). We pick the *first* fence on the assumption that the LLM obeys the prompt and emits a single solution block.
(text: str)
| 38 | |
| 39 | |
| 40 | def extract_code(text: str) -> str: |
| 41 | """Extract the first fenced code block; fall back to raw text. |
| 42 | |
| 43 | The regex is permissive about the language tag (e.g. ```py / ```python3 / |
| 44 | ``` ... ```). We pick the *first* fence on the assumption that the LLM |
| 45 | obeys the prompt and emits a single solution block. |
| 46 | """ |
| 47 | if not isinstance(text, str): |
| 48 | return "" |
| 49 | text = text.strip() |
| 50 | if not text: |
| 51 | return "" |
| 52 | m = _FENCE_RE.search(text) |
| 53 | if m: |
| 54 | return m.group(1).strip() |
| 55 | # No fence: treat the whole response as code (best-effort fallback). |
| 56 | return text |
| 57 | |
| 58 | |
| 59 | def _build_driver(candidate_code: str, sample_io: list[dict]) -> str: |
no outgoing calls
no test coverage detected