Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files124 unmodified lines1251261271281291303 unmodified lines134135136137138139140124 unmodified lines)print("CodeAgent initialized with LiteLLMModel.")def __call__(self, question: str, task_id: str = "") -> str:prompt = question.strip()if task_id:3 unmodified lines)try:result = self.agent.run(prompt)return "" if result is None else str(result).strip()except Exception as exc:return f"AGENT ERROR: {exc}"124 unmodified lines1251261271281291301311321331341351361371381391401411421431441451461471481491501511521531543 unmodified lines158159160161162163164165124 unmodified lines)print("CodeAgent initialized with LiteLLMModel.")def _clean_exact_match_answer(raw_answer: str) -> str:import retext = (raw_answer or "").strip()if not text or text.startswith("AGENT ERROR:"):return texttext = re.sub(r"(?im)^\s*(final\s*answer|answer)\s*:\s*", "", text).strip()lines = [line.strip() for line in text.splitlines() if line.strip()]if lines:text = lines[-1]if text.startswith("```") and text.endswith("```"):text = text.strip("`").strip()if len(text) >= 2 and ((text[0] == '"' and text[-1] == '"') or (text[0] == "'" and text[-1] == "'")):text = text[1:-1].strip()if len(text) > 1 and text.endswith(".") and not re.search(r"\d\.$", text):text = text[:-1].strip()return textdef __call__(self, question: str, task_id: str = "") -> str:prompt = question.strip()if task_id:3 unmodified lines)try:result = self.agent.run(prompt)raw_text = "" if result is None else str(result).strip()return _clean_exact_match_answer(raw_text)except Exception as exc:return f"AGENT ERROR: {exc}"
app.py+26-1