Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files2025 unmodified lines2026202720282029203020312032203320342035179 unmodified lines221522162217221822192220222122222223222422252226222722282229223013 unmodified lines2244224522462247224822492250225122522253225422552256225722582259723 unmodified lines298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430052025 unmodified linesplain,)if fa_match and fa_match[-1].strip():return f"final_answer({json.dumps(fa_match[-1].strip(), ensure_ascii=False)})"return (f'print("Invalid non-code output. Write valid Python code inside 'f'{open_t}...{close_t} calling a tool or final_answer(...).")')converted_top = _convert_xml_tool_calls(text)179 unmodified linesreasoning_str,)if fa_matches and fa_matches[-1].strip():ans_val = fa_matches[-1].strip()content_str = (f"{cls.open_tag}\n"f"final_answer({json.dumps(ans_val, ensure_ascii=False)})\n"f"{cls.close_tag}")else:content_str = (f"{cls.open_tag}\n"f'print("No Python code block produced. Write valid Python code inside {cls.open_tag}...{cls.close_tag} to call a tool or final_answer(...).")\n'f"{cls.close_tag}")13 unmodified linescleaned,)if fa_direct and fa_direct[-1].strip():ans_val = fa_direct[-1].strip()cleaned = (f"{cls.open_tag}\n"f"final_answer({json.dumps(ans_val, ensure_ascii=False)})\n"f"{cls.close_tag}")else:cleaned = (f"{cls.open_tag}\n"f'print("Invalid non-code output. Write valid Python code inside {cls.open_tag}...{cls.close_tag} to call a tool or final_answer(...).")\n'f"{cls.close_tag}")723 unmodified linesreturn cleanedblocked_models.add(model_name)breaklast_step = getattr(getattr(run_agent, "memory", None), "steps", None)if last_step:for st in reversed(last_step):cand_val = getattr(st, "action_output", None)if cand_val is None:continuefallback_clean = self._clean_exact_match_answer(str(cand_val))if (fallback_cleanand not fallback_clean.startswith(("AGENT ERROR:", "Error ", "No attachment", "No web results", "No Wikipedia"))and len(fallback_clean) <= 600):return " ".join(fallback_clean.splitlines()).strip()blocked_models.add(model_name)continueexcept Exception as exc:llm_err = getattr(built_model, "_last_llm_error", None)if llm_err is not None and llm_err is not exc:2025 unmodified lines2026202720282029203020312032203320342035203620372038203920402041179 unmodified lines222122222223222422252226222722282229223022312232223322342235223622372238223922402241224213 unmodified lines2256225722582259226022612262226322642265226622672268226922702271227222732274227522762277723 unmodified lines3001300230033004300530062025 unmodified linesplain,)if fa_match and fa_match[-1].strip():safe_ans = (json.dumps(fa_match[-1].strip(), ensure_ascii=False).replace("<", "\\u003c").replace(">", "\\u003e").replace("```", "\\x60\\x60\\x60"))return f"final_answer({safe_ans})"return ('print("Invalid non-code output. Write valid Python code inside ''the code block calling a tool or final_answer(...).")')converted_top = _convert_xml_tool_calls(text)179 unmodified linesreasoning_str,)if fa_matches and fa_matches[-1].strip():ans_val = (json.dumps(fa_matches[-1].strip(), ensure_ascii=False).replace("<", "\\u003c").replace(">", "\\u003e").replace("```", "\\x60\\x60\\x60"))content_str = (f"{cls.open_tag}\n"f"final_answer({ans_val})\n"f"{cls.close_tag}")else:content_str = (f"{cls.open_tag}\n"'print("No Python code block produced. Write valid Python code inside ''the code block to call a tool or final_answer(...).")\n'f"{cls.close_tag}")13 unmodified linescleaned,)if fa_direct and fa_direct[-1].strip():ans_val = (json.dumps(fa_direct[-1].strip(), ensure_ascii=False).replace("<", "\\u003c").replace(">", "\\u003e").replace("```", "\\x60\\x60\\x60"))cleaned = (f"{cls.open_tag}\n"f"final_answer({ans_val})\n"f"{cls.close_tag}")else:cleaned = (f"{cls.open_tag}\n"'print("Invalid non-code output. Write valid Python code inside ''the code block to call a tool or final_answer(...).")\n'f"{cls.close_tag}")723 unmodified linesreturn cleanedblocked_models.add(model_name)breakexcept Exception as exc:llm_err = getattr(built_model, "_last_llm_error", None)if llm_err is not None and llm_err is not exc:
app.py+27-26