Extract a complete code block from an LLM response for a full rewrite. Args: llm_response: The full text response from the LLM. language: The programming language to look for in the markdown code block. Returns: The extracted code string, or None if no code blo
(llm_response: str, language: str = "python")
| 107 | |
| 108 | |
| 109 | def parse_full_rewrite(llm_response: str, language: str = "python") -> Optional[str]: |
| 110 | """ |
| 111 | Extract a complete code block from an LLM response for a full rewrite. |
| 112 | |
| 113 | Args: |
| 114 | llm_response: The full text response from the LLM. |
| 115 | language: The programming language to look for in the markdown code block. |
| 116 | |
| 117 | Returns: |
| 118 | The extracted code string, or None if no code block is found. |
| 119 | """ |
| 120 | # First, try to find a code block specifically marked with the given language |
| 121 | code_block_pattern = r"```" + language + r"\n(.*?)```" |
| 122 | matches = re.findall(code_block_pattern, llm_response, re.DOTALL) |
| 123 | |
| 124 | if matches: |
| 125 | # Return the content of the first matching block, stripped of whitespace |
| 126 | return matches[0].strip() |
| 127 | |
| 128 | # Fallback: if no language-specific block is found, look for any code block |
| 129 | code_block_pattern = r"```(.*?)```" |
| 130 | matches = re.findall(code_block_pattern, llm_response, re.DOTALL) |
| 131 | |
| 132 | if matches: |
| 133 | return matches[0].strip() |
| 134 | |
| 135 | # Final fallback: if no code blocks are found at all, return the raw response |
| 136 | return llm_response |
| 137 | |
| 138 | |
| 139 | def format_diff_summary(diff_blocks: List[Tuple[str, str]]) -> str: |
no outgoing calls
no test coverage detected