MCPcopy Create free account
hub / github.com/InternScience/SciReason / extract_code

Function extract_code

opencompass/lagent/actions/ipython_interpreter.py:255–270  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

253
254
255def extract_code(text):
256 # Match triple backtick blocks first
257 triple_match = re.search(r'```[^\n]*\n(.+?)```', text, re.DOTALL)
258 # Match single backtick blocks second
259 single_match = re.search(r'`([^`]*)`', text, re.DOTALL)
260 if triple_match:
261 text = triple_match.group(1)
262 elif single_match:
263 text = single_match.group(1)
264 else:
265 try:
266 text = json5.loads(text)['code']
267 except Exception:
268 pass
269 # If no code blocks found, return original text
270 return text
271
272
273def escape_ansi(line):

Callers 3

save_resultsMethod · 0.90
_callMethod · 0.85
__call__Method · 0.85

Calls 1

groupMethod · 0.80

Tested by

no test coverage detected