Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files2440 unmodified lines2441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249924812482248324842485248624872488248924902491249224932494249524962497249824992500250125022440 unmodified lines print("CodeAgent initialized with LiteLLMModel.")
def _clean_exact_match_answer(self, text: str) -> str: import re, json
if text is None: return "" cleaned = str(text).strip() if not cleaned or cleaned.startswith("AGENT ERROR:"): return cleaned
# 1. usuń tagi code i markdown cleaned = re.sub(r"</?code[^>]*>", "", cleaned, flags=re.IGNORECASE) cleaned = re.sub(r"^```(?:\w+)?\s*|\s*```$", "", cleaned.strip(), flags=re.MULTILINE).strip()
# 2. final_answer(...) → wartość fa = re.fullmatch(r"final_answer\s*\(\s*(?:answer\s*=\s*)?(.*?)\s*\)", cleaned, flags=re.DOTALL) if fa: inner = fa.group(1).strip() if (inner.startswith('"') and inner.endswith('"')) or (inner.startswith("'") and inner.endswith("'")): try: cleaned = json.loads(inner) if inner.startswith('"') else inner[1:-1] except Exception: cleaned = inner.strip("\"'") else: cleaned = inner
# 3. jedna linia = odpowiedź; wiele linii = ostatnia niepusta lines = [ln.strip() for ln in cleaned.splitlines() if ln.strip()] if len(lines) > 1: for ln in reversed(lines): m = re.match(r"^(?:\*\*)?(?:final\s+answer|answer|result)\s*:?\s*(.+)$", ln, re.IGNORECASE) if m: cleaned = m.group(1).strip() break import re, json if text is None: return "" cleaned = str(text).strip() if not cleaned or cleaned.startswith("AGENT ERROR:"): return cleaned # 1. usuń tagi code i markdown cleaned = re.sub(r"</?code[^>]*>", "", cleaned, flags=re.IGNORECASE) cleaned = re.sub(r"^```(?:\w+)?\s*|\s*```$", "", cleaned.strip(), flags=re.MULTILINE).strip() # 2. final_answer(...) → wartość fa = re.fullmatch(r"final_answer\s*\(\s*(?:answer\s*=\s*)?(.*?)\s*\)", cleaned, flags=re.DOTALL) if fa: inner = fa.group(1).strip() if (inner.startswith('"') and inner.endswith('"')) or (inner.startswith("'") and inner.endswith("'")): try: cleaned = json.loads(inner) if inner.startswith('"') else inner[1:-1] except Exception: cleaned = inner.strip("\"'") else: cleaned = inner # 3. jedna linia = odpowiedź; wiele linii = ostatnia niepusta lines = [ln.strip() for ln in cleaned.splitlines() if ln.strip()] if len(lines) > 1: for ln in reversed(lines): m = re.match(r"^(?:\*\*)?(?:final\s+answer|answer|result)\s*:?\s*(.+)$", ln, re.IGNORECASE) if m: cleaned = m.group(1).strip() break else: cleaned = lines[-1] elif lines: cleaned = lines[0] else: cleaned = lines[-1] elif lines: cleaned = lines[0] else: return ""
# 4. zdejmij otaczające cudzysłowy / bold / backtick if len(cleaned) >= 2 and ( (cleaned[0] == cleaned[-1] and cleaned[0] in "\"'`") or (cleaned.startswith("**") and cleaned.endswith("**")) or (cleaned.startswith("__") and cleaned.endswith("__")) ): cleaned = cleaned.strip("\"'`").strip("*_").strip()
# 5. liczby: usuń separatory tysięcy, zostaw kropkę dziesiętną if re.fullmatch(r"-?\d{1,3}(?:,\d{3})+(?:\.\d+)?", cleaned): cleaned = cleaned.replace(",", "")
# 6. usuń końcową kropkę (poza skrótami) if cleaned.endswith(".") and not re.search(r"\b(?:Mr|Mrs|Ms|Dr|St|Jr|Sr|Inc|Ltd|vs|etc)\.$", cleaned): cleaned = cleaned[:-1].strip()
return cleaned return "" # 4. zdejmij otaczające cudzysłowy / bold / backtick if len(cleaned) >= 2 and ( (cleaned[0] == cleaned[-1] and cleaned[0] in "\"'`") or (cleaned.startswith("**") and cleaned.endswith("**")) or (cleaned.startswith("__") and cleaned.endswith("__")) ): cleaned = cleaned.strip("\"'`").strip("*_").strip() # 5. liczby: usuń separatory tysięcy, zostaw kropkę dziesiętną if re.fullmatch(r"-?\d{1,3}(?:,\d{3})+(?:\.\d+)?", cleaned): cleaned = cleaned.replace(",", "") # 6. usuń końcową kropkę (poza skrótami) if cleaned.endswith(".") and not re.search(r"\b(?:Mr|Mrs|Ms|Dr|St|Jr|Sr|Inc|Ltd|vs|etc)\.$", cleaned): cleaned = cleaned[:-1].strip() return cleaned
def __call__(self, question: str, task_id: str = "", file_name: str = "") -> str: import timeapp.py+55-55