| 19 | TIMEOUT_MESSAGE = f"Execution of the code snippet has timed out for exceeding {TIMEOUT_SECONDS} seconds." |
| 20 | |
| 21 | def truncate_string(text, max_length=500, is_evalf=True): |
| 22 | # print(text, file=sys.stderr) |
| 23 | # print(type(text), file=sys.stderr) |
| 24 | if is_evalf and isinstance(text, str): |
| 25 | try: |
| 26 | text_sympy = float(text) |
| 27 | refine_text = str(round(text_sympy, 4)) + "\n" |
| 28 | text = text if len(text) < len(refine_text) else refine_text |
| 29 | except: |
| 30 | pass |
| 31 | |
| 32 | if len(str(text)) > max_length: |
| 33 | return str(text)[:max_length//2] + "..." + str(text)[-max_length//2:] |
| 34 | return text |
| 35 | |
| 36 | def extract_content(text): |
| 37 | pattern = r'print\((.*?)\)' |