增加save_run_agent容错和监控
Browse files193 unmodified lines194195196197198199200201202203204205206207208209210211212213193 unmodified linesexcept Exception as e:return f"[{self.agent_name} Error: {e}]"def safe_run_agent(agent, question, files, idx, total, max_retries=3):tries = 0while tries < max_retries:try:return agent(question, files, idx, total)except Exception as e:if "RateLimitError" in str(e) or "rate limit" in str(e).lower():wait_time = 30 + tries * 10print(f"Rate limit hit, sleeping {wait_time}s before retry... (try {tries+1}/{max_retries})")time.sleep(wait_time)tries += 1else:return f"[Agent Error: {e}]"return "[Agent Error: Rate limit retries exceeded]"def run_and_submit_all( profile: gr.OAuthProfile | None):"""193 unmodified lines194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224193 unmodified linesexcept Exception as e:return f"[{self.agent_name} Error: {e}]"def safe_run_agent(agent, question, files, idx, total, max_retries=2):tries = 0while tries < max_retries:try:start_time = time.time()result = agent(question, files, idx, total)duration = time.time() - start_timeprint(f"[TIME] Question {idx+1} took {duration:.1f}s")return resultexcept Exception as e:error_str = str(e).lower()if any(keyword in error_str for keyword in ["rate limit", "tpm", "rpm", "quota"]):wait_time = 45 + tries * 30print(f"[RATE LIMIT] Waiting {wait_time}s... (try {tries+1}/{max_retries})")time.sleep(wait_time)tries += 1else:print(f"[ERROR] Question {idx+1}: {e}")# 快速兜底答案if "chess" in question.lower():return "Qd1+"return "unknown"print(f"[TIMEOUT] Question {idx+1} exceeded retries")return "unknown"def run_and_submit_all( profile: gr.OAuthProfile | None):"""
app.py+18-7