Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files461 unmodified lines46246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349446549549649749846947049950050150250350450511 unmodified lines517518519520521522523461 unmodified lines
class SafeLiteLLMModel(LiteLLMModel): @staticmethod def _sanitize_code_tags(text: str) -> str: import re
if re.search(r"<code>.*?</code>", text, flags=re.DOTALL | re.IGNORECASE): def _clean_html_block(match): inner = match.group(1) inner = re.sub(r"```(?:py|python)?\s*\n?", "", inner, flags=re.IGNORECASE) inner = re.sub(r"\n?```", "", inner) inner = re.sub(r"</?code[^>]*>", "", inner, flags=re.IGNORECASE) return f"<code>\n{inner.strip()}\n</code>"
return re.sub( r"<code>(.*?)</code>", _clean_html_block, text, flags=re.DOTALL | re.IGNORECASE, )
def _clean_md_block(match): inner = re.sub(r"</?code[^>]*>", "", match.group(1), flags=re.IGNORECASE) return f"```py\n{inner.strip()}\n```"
return re.sub( r"```(?:py|python)?\s*\n(.*?)```", _clean_md_block, text, flags=re.DOTALL | re.IGNORECASE, )
@classmethod def _validate_message(msg): def _validate_message(cls, msg): content = getattr(msg, "content", None) if msg is not None else None if content is None or not str(content).strip(): raise RuntimeError("Error in generating model output: empty model response (content=None)") if not isinstance(content, str): msg.content = str(content) cleaned = cls._sanitize_code_tags(str(content)) if not cleaned.strip(): raise RuntimeError("Error in generating model output: empty model response after sanitization") msg.content = cleaned return msg
if hasattr(LiteLLMModel, "generate"):11 unmodified lines model_id=self.model_id, api_key=self.gemini_key, max_tokens=8192, reasoning_effort="low", num_retries=1, timeout=5, )app.py+36-3