Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files461 unmodified lines46246346446546646746846947047147247311 unmodified lines485486487488489490461 unmodified linesclass SafeLiteLLMModel(LiteLLMModel):@staticmethoddef _validate_message(msg):content = getattr(msg, "content", None) if msg is not None else Noneif 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)return msgif hasattr(LiteLLMModel, "generate"):11 unmodified linesmodel_id=self.model_id,api_key=self.gemini_key,max_tokens=8192,num_retries=1,timeout=5,)461 unmodified lines46246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450511 unmodified lines517518519520521522523461 unmodified linesclass SafeLiteLLMModel(LiteLLMModel):@staticmethoddef _sanitize_code_tags(text: str) -> str:import reif 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,)@classmethoddef _validate_message(cls, msg):content = getattr(msg, "content", None) if msg is not None else Noneif content is None or not str(content).strip():raise RuntimeError("Error in generating model output: empty model response (content=None)")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 = cleanedreturn msgif hasattr(LiteLLMModel, "generate"):11 unmodified linesmodel_id=self.model_id,api_key=self.gemini_key,max_tokens=8192,reasoning_effort="low",num_retries=1,timeout=5,)
app.py+36-3