Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files2351 unmodified lines2352235323542355235623572351 unmodified lines'the code block calling a tool or final_answer(...).")')@classmethoddef _validate_message(cls, msg):import json2351 unmodified lines2352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872351 unmodified lines'the code block calling a tool or final_answer(...).")')tag_blocks = re.findall(rf"{re.escape(open_t)}(.*?){re.escape(close_t)}",text,flags=re.DOTALL | re.IGNORECASE,)if tag_blocks:non_empty_blocks = [b.strip() for b in tag_blocks if b.strip()]for raw_block in reversed(non_empty_blocks):extracted = _extract_valid_python(raw_block)if "Invalid non-code output." not in extracted:return f"{open_t}\n{extracted}\n{close_t}"if non_empty_blocks:return f"{open_t}\n{_extract_valid_python(non_empty_blocks[-1])}\n{close_t}"fenced_blocks = re.findall(r"```(?:py|python)?\s*\n(.*?)```",text,flags=re.DOTALL | re.IGNORECASE,)if fenced_blocks:non_empty_fenced = [b.strip() for b in fenced_blocks if b.strip()]for raw_block in reversed(non_empty_fenced):extracted = _extract_valid_python(raw_block)if "Invalid non-code output." not in extracted:return f"{open_t}\n{extracted}\n{close_t}"if non_empty_fenced:return f"{open_t}\n{_extract_valid_python(non_empty_fenced[-1])}\n{close_t}"return f"{open_t}\n{_extract_valid_python(text)}\n{close_t}"@classmethoddef _validate_message(cls, msg):import json
app.py+30