MCPcopy Create free account
hub / github.com/FareedKhan-dev/ai-long-task / parse_full_rewrite

Function parse_full_rewrite

utils/code_utils.py:109–136  ·  view source on GitHub ↗

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")

Source from the content-addressed store, hash-verified

107
108
109def 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
139def format_diff_summary(diff_blocks: List[Tuple[str, str]]) -> str:

Callers 2

_run_iteration_workerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected