Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files994 unmodified lines99599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052994 unmodified linesreturn textdef __call__(self, question: str, task_id: str = "") -> str:prompt = question.strip()if task_id:prompt += (f"\n\nTask ID: {task_id}. If the question references an attached file "f"or image, use download_task_file(task_id='{task_id}') to inspect it.")blocked_models = getattr(self, "_blocked_models", None)if blocked_models is None:blocked_models = set()self._blocked_models = blocked_modelsmodels_to_try = list(getattr(self, "working_models", []) or [self.model_id])if self.model_id and self.model_id not in models_to_try:models_to_try.append(self.model_id)models_to_try = [m for m in models_to_tryif m not in blocked_modelsand not (m.startswith("openrouter/") and not self.provider_keys.get("openrouter"))]for model_name in models_to_try:if not hasattr(self, "_build_model") or not hasattr(self, "agent"):breaktry:self.model_id = model_nameself.agent.model = self._build_model(model_name)result = self.agent.run(prompt)cleaned = self._clean_exact_match_answer("" if result is None else str(result).strip())if cleaned and not cleaned.startswith("AGENT ERROR:"):return cleanedexcept Exception as exc:err_text = str(exc)err_lower = err_text.lower()print(f"[AGENT ERROR] task_id={task_id} model={model_name}: {err_text}")if any(marker in err_lowerfor marker in ("429","quota","resource_exhausted","401","403","authentication","insufficient permissions","empty model response",)):blocked_models.add(model_name)return "AGENT ERROR: All candidate models failed."def run_and_submit_all(profile: gr.OAuthProfile | None):994 unmodified lines99599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064994 unmodified linesreturn textdef __call__(self, question: str, task_id: str = "") -> str:prompt = question.strip()if task_id:prompt += (f"\n\nTask ID: {task_id}. If the question references an attached file "f"or image, use download_task_file(task_id='{task_id}') to inspect it.")blocked_models = getattr(self, "_blocked_models", None)if blocked_models is None:blocked_models = set()self._blocked_models = blocked_modelsblocked_providers = getattr(self, "_blocked_providers", None)if blocked_providers is None:blocked_providers = set()self._blocked_providers = blocked_providersmodels_to_try = list(getattr(self, "working_models", []) or [self.model_id])if self.model_id and self.model_id not in models_to_try:models_to_try.append(self.model_id)models_to_try = [m for m in models_to_tryif m not in blocked_modelsand (m.split("/", 1)[0].lower() if "/" in m else "gemini") not in blocked_providersand bool(self._get_api_key(m))]for model_name in models_to_try:if not hasattr(self, "_build_model") or not hasattr(self, "agent"):breakprovider = model_name.split("/", 1)[0].lower() if "/" in model_name else "gemini"if provider in blocked_providers:continuetry:self.model_id = model_nameself.agent.model = self._build_model(model_name)result = self.agent.run(prompt)cleaned = self._clean_exact_match_answer("" if result is None else str(result).strip())if cleaned and not cleaned.startswith("AGENT ERROR:"):return cleanedexcept Exception as exc:err_text = str(exc)err_lower = err_text.lower()print(f"[AGENT ERROR] task_id={task_id} model={model_name}: {err_text}")if any(marker in err_lowerfor marker in ("401","403","authentication","missing authentication header","insufficient permissions",)):blocked_providers.add(provider)blocked_models.add(model_name)elif any(marker in err_lowerfor marker in ("429", "quota", "resource_exhausted", "empty model response")):blocked_models.add(model_name)return "AGENT ERROR: All candidate models failed."def run_and_submit_all(profile: gr.OAuthProfile | None):
app.py+62-50