MCPcopy Create free account
hub / github.com/Alibaba-NLP/DeepResearch / extract_code

Function extract_code

inference/file_tools/utils.py:281–292  ·  view source on GitHub ↗
(text: str)

Source from the content-addressed store, hash-verified

279
280
281def extract_code(text: str) -> str:
282 # Match triple backtick blocks first
283 triple_match = re.search(r'```[^\n]*\n(.+?)```', text, re.DOTALL)
284 if triple_match:
285 text = triple_match.group(1)
286 else:
287 try:
288 text = json5.loads(text)['code']
289 except Exception:
290 print_traceback(is_error=False)
291 # If no code blocks found, return original text
292 return text
293
294
295def json_loads(text: str) -> dict:

Callers 1

Calls 2

searchMethod · 0.80
print_tracebackFunction · 0.70

Tested by

no test coverage detected