MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/optillm / extract_code_blocks

Function extract_code_blocks

optillm/plugins/coc_plugin.py:97–105  ·  view source on GitHub ↗

Extract Python code blocks from text.

(text: str)

Source from the content-addressed store, hash-verified

95'''
96
97def extract_code_blocks(text: str) -> List[str]:
98 """Extract Python code blocks from text."""
99 pattern = r'```python\s*(.*?)\s*```'
100 matches = re.findall(pattern, text, re.DOTALL)
101 blocks = [m.strip() for m in matches]
102 logger.info(f"Extracted {len(blocks)} code blocks")
103 for i, block in enumerate(blocks):
104 logger.info(f"Code block {i+1}:\n{block}")
105 return blocks
106
107def sanitize_code(code: str) -> str:
108 """Prepare code for safe execution by removing problematic visualization code."""

Callers 2

generate_fixed_codeFunction · 0.85
runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected