Spaces:
Runtime error
Runtime error
Update app.py
Browse files807 unmodified lines808809810811811812813814815816817818819201 unmodified lines102110221023101910201021102210231024102410251026199 unmodified lines122612271228123012291230123112321277 unmodified lines251025112512251425132514251525162517251825192520252125222518251925202521252225233 unmodified lines2527252825292530253125322533253425352536253725382539254025412542254325442538254525462547254864 unmodified lines261326142615260926102616261726182619262094 unmodified lines271527162717271127182719272027219 unmodified lines273127322733272727282729273027312732273327342735273627372738273927342735273627372738273927402741274227432744274527402741274627472748807 unmodified lines return "No results."
def _litellm_route_kwargs(model_name: str, api_key: str) -> dict: return {"model": model_name, "api_key": api_key} route = {"model": model_name, "api_key": api_key} if model_name.startswith("huggingface/"): raw_hf = model_name[len("huggingface/") :] route["model"] = f"openai/{raw_hf}" route["api_base"] = "https://router.huggingface.co/v1" return route
def _is_daily_quota_exhausted(err_lower: str) -> bool: return any(201 unmodified lines continue if _is_daily_quota_exhausted(err_low): rate_limited_providers.add(v_provider) else: with self._state_lock: pool = self.provider_key_pools.get(v_provider) or [] self._provider_key_idx[v_provider] = 0 if hasattr(self, "_sync_provider_env"): self._sync_provider_env(v_provider, pool[0] if pool else "") break break
199 unmodified lines transcript = " ".join(c for c in cues if c) if transcript: lang = tr.get("languageCode", "unknown") sections.append(f"Transcript ({lang}):\n{transcript[:8000]}") sections.append(f"Transcript ({lang}):\n{transcript[:5000]}") has_transcript = True break except Exception as tr_exc:1277 unmodified lines if code_match: cleaned = code_match.group(1).strip()
json_block = re.search( cleaned = re.sub( r'\{\s*["\']tool["\']\s*:\s*["\'][^"\']+["\']\s*,\s*["\']arguments["\']\s*:\s*\{.*?\}\s*\}', "", cleaned, flags=re.DOTALL, ) if json_block: cleaned = (cleaned[: json_block.start()] + cleaned[json_block.end() :]).strip() if not cleaned: return "" ).strip()
cleaned = re.sub(r"(?im)^\s*(?:#\s*)?(?:thought|reasoning|plan)\s*:.*$", "", cleaned).strip()
fa_call = re.search( r"final_answer\(\s*(?:answer\s*=\s*)?(['\"])(.*?)\1\s*\)",3 unmodified lines if fa_call: cleaned = fa_call.group(2).strip()
if "->" in cleaned: tail_part = cleaned.split("->")[-1].strip() quoted_match = re.findall(r'""([^"]+)""|"([^"]+)"', tail_part) if quoted_match: last_q = quoted_match[-1] cleaned = (last_q[0] or last_q[1]).strip() else: cleaned = tail_part.strip(" .\"'")
lines = [ln.strip(" \t\r\n-*•\"'") for ln in cleaned.splitlines() if ln.strip()] if not lines: return "" cleaned = lines[-1]
if re.match( r"^(?:the search results show|this scene is from|the page is quite long|the task doesn't have|the download failed|let me try|let me search|now i need to find|i found the)\b", r"^(?:the wikipedia article|the youtube video|the search results show|this scene is from|the page is quite long|the task doesn't have|the download failed|let me try|let me search|let me check|now i need to find|i found the|the operation is not commutative|the scene occurs)\b", cleaned, flags=re.IGNORECASE, ):64 unmodified lines and not tr_preview.startswith(("Error ", "Audio file not found")) ): prompt += ( f"\n\nTask ID: {task_id}. Audio file '{prefetched_path}' transcription:\n" f"{tr_preview.strip()[:8000]}" f"\n\nTask ID: {task_id}. Attachment '{prefetched_path}' content (truncated):\n" f"{file_preview.strip()[:4000]}" ) tool_hint = "" except Exception as tr_exc:94 unmodified lines built_model.timeout = call_timeout built_model.deadline = deadline run_agent = self._create_code_agent(built_model) run_agent.max_steps = 3 if rem_now > 25.0 else 2 run_agent.max_steps = 4 if rem_now > 40.0 else (3 if rem_now > 20.0 else 2) result = run_agent.run(prompt) print( f"[TRACE] task_id={task_id} model={model_name} "9 unmodified lines last_step = getattr(getattr(run_agent, "memory", None), "steps", None) if last_step: for st in reversed(last_step): for attr in ("action_output", "model_output", "observations"): cand_val = getattr(st, attr, None) if cand_val is None: continue fallback_clean = self._clean_exact_match_answer(str(cand_val)) if ( fallback_clean and not fallback_clean.startswith("AGENT ERROR:") and "\n" not in fallback_clean and len(fallback_clean) <= 220 ): return fallback_clean return "AGENT ERROR: All candidate models failed." cand_val = getattr(st, "action_output", None) if cand_val is None: continue fallback_clean = self._clean_exact_match_answer(str(cand_val)) if ( fallback_clean and not fallback_clean.startswith(("AGENT ERROR:", "Error ", "No attachment")) and "\n" not in fallback_clean and len(fallback_clean) <= 200 ): return fallback_clean return "" blocked_models.add(model_name) break except Exception as exc: llm_err = getattr(built_model, "_last_llm_error", None) if llm_err is not None and llm_err is not exc:app.py+37-33