MCPcopy Create free account
hub / github.com/AMAP-ML/Thinking-with-Map / extract_code

Function extract_code

demo/qwen_agent/utils/utils.py:284–295  ·  view source on GitHub ↗
(text: str)

Source from the content-addressed store, hash-verified

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

Callers 2

callMethod · 0.90
callMethod · 0.90

Calls 2

print_tracebackFunction · 0.85
searchMethod · 0.45

Tested by

no test coverage detected