Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files752 unmodified lines753754755756757758151 unmodified lines9109119129139149159169179189191267 unmodified lines218721882189219021912192752 unmodified linestext = body_text[:4200] + "\n...\n" + body_text[-4200:]else:text = body_textexcept Exception as e:return f"Wikipedia error for '{query}': {str(e)}"151 unmodified lines"openrouter/google/gemma-4-31b-it:free","openrouter/google/gemma-3-27b-it:free",])if self.provider_keys.get("nvidia_nim"):candidate_models.extend(["nvidia_nim/nvidia/nemotron-3-ultra-550b-a55b","nvidia_nim/moonshotai/kimi-k2-instruct","nvidia_nim/moonshotai/kimi-k2.5",])1267 unmodified lines'the code block calling a tool or final_answer(...).")')@classmethoddef _validate_message(cls, msg):import json752 unmodified lines753754755756757758759760761762763764765766767768151 unmodified lines9209219229239249259269279289291267 unmodified lines219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235752 unmodified linestext = body_text[:4200] + "\n...\n" + body_text[-4200:]else:text = body_textdisplay_title = resolved_title or titleheader_lines = [f"Wikipedia: {display_title}"]if rev_id:header_lines[0] += f" (2022 revision {rev_id})"if other_titles:header_lines.append(f"Other search matches: {', '.join(other_titles[:4])}")body_out = text if text else "No readable article text found."result_str = "\n".join(header_lines) + "\n\n" + body_outwiki_cache[cache_key] = result_strreturn result_strexcept Exception as e:return f"Wikipedia error for '{query}': {str(e)}"151 unmodified lines"openrouter/google/gemma-4-31b-it:free","openrouter/google/gemma-3-27b-it:free",])if self.provider_keys.get("nvidia_nim") or self.provider_key_pools.get("nvidia_nim"):vision_candidates.extend(["nvidia_nim/meta/llama-3.2-90b-vision-instruct","nvidia_nim/nvidia/nemotron-nano-12b-v2-vl","nvidia_nim/moonshotai/kimi-k2.5",])1267 unmodified lines'the code block calling a tool or final_answer(...).")')tag_matches = re.findall(rf"{re.escape(open_t)}(.*?){re.escape(close_t)}",text,flags=re.DOTALL,)if not tag_matches and open_t != "```py":tag_matches = re.findall(r"```(?:py|python)?\s*\n(.*?)```",text,flags=re.DOTALL | re.IGNORECASE,)if tag_matches:raw_block = tag_matches[-1].strip()converted = _convert_xml_tool_calls(raw_block)inner = converted if converted is not None else raw_blockinner = _guard_unbound_lines(inner)inner = _ensure_observable_output(inner)if "Invalid non-code output." not in inner:inner = _ensure_final_answer_call(inner)try:tree = ast.parse(inner)if not tree.body:inner = _extract_valid_python(raw_block)except SyntaxError:inner = _extract_valid_python(raw_block)return f"{open_t}\n{inner}\n{close_t}"extracted = _extract_valid_python(text)if "Invalid non-code output." not in extracted:extracted = _ensure_final_answer_call(extracted)return f"{open_t}\n{extracted}\n{close_t}"@classmethoddef _validate_message(cls, msg):import json
app.py+47-4