Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files732 unmodified lines7337347357367377387397407417421870 unmodified lines261326142615261626172618261926208 unmodified lines2629263026312632263326346 unmodified lines2641264226432644264526462647264812 unmodified lines26612662266326642665266648 unmodified lines271527162717271827192720272115 unmodified lines2737273827392740274127422743141 unmodified lines2885288628872888288928902891732 unmodified linestext = ""if len(text) > 4800:disc_match = re.search(r"(?i)\bdiscography\b", text)if disc_match:start_pos = max(0, disc_match.start() - 300)text = text[:1200] + "\n...\n" + text[start_pos : start_pos + 3600]else:text = text[:2400] + "\n...\n" + text[-2400:]1870 unmodified linesand not tr_preview.startswith(("Error ", "Audio file not found"))):prompt += (f"\n\nTask ID: {task_id}. Attachment '{prefetched_path}' content (truncated):\n"f"{file_preview.strip()[:4000]}")tool_hint = ""except Exception as tr_exc:8 unmodified linesf"\n\nTask ID: {task_id}. The task attachment is downloaded at '{prefetched_path}'. "f"Call inspect_image(image_path='{prefetched_path}', question=...) immediately.")else:tool_hint = f"Call read_local_file(file_path='{prefetched_path}') immediately."read_fn = getattr(self, "_read_local_file", None) or tools_map.get("read_local_file")6 unmodified linesand not file_preview.startswith(("Error ", "File not found"))):prompt += (f"\n\nTask ID: {task_id}. Attachment '{prefetched_path}' content:\n"f"{file_preview.strip()[:12000]}")tool_hint = ""except Exception as rd_exc:12 unmodified linesf"call download_task_file(task_id='{task_id}', preferred_filename='{clean_file_name}') first.")blocked_models = set(self._dead_models)blocked_providers = set()48 unmodified linesbuilt_model.timeout = call_timeoutbuilt_model.deadline = deadlinerun_agent = self._create_code_agent(built_model)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} "15 unmodified linesfallback_clean = self._clean_exact_match_answer(str(cand_val))if (fallback_cleanand not fallback_clean.startswith(("AGENT ERROR:", "Error ", "No attachment"))and "\n" not in fallback_cleanand len(fallback_clean) <= 200):141 unmodified linesself._local_state.deadline = Noneself._task_deadline = Nonereturn "AGENT ERROR: All candidate models failed."def _trim_tool_output(text: str, max_chars: int = 4000) -> str:732 unmodified lines7337347357367377387397407417427437441870 unmodified lines26152616261726182619262026212622262326242625262626278 unmodified lines2636263726382639264026412642264326442645264626476 unmodified lines2654265526562657265826592660266112 unmodified lines2674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270248 unmodified lines275127522753275427552756275715 unmodified lines277327742775277627772778277927802781141 unmodified lines2923292429252926292729282929732 unmodified linestext = ""if len(text) > 4800:# Najpierw spróbuj znaleźć sekcję Discography i zwróć ją priorytetowodisc_match = re.search(r"(?i)\bdiscography\b", text)if disc_match:start = max(0, disc_match.start() - 200)disc_section = text[start:start + 4000]text = text[:800] + "\n...\n" + disc_sectionelse:text = text[:2400] + "\n...\n" + text[-2400:]1870 unmodified linesand not tr_preview.startswith(("Error ", "Audio file not found"))):prompt += (f"\n\nTask ID: {task_id}. Audio transcription:\n"f"{tr_preview.strip()[:5000]}")prompt += ("\n\nIMPORTANT for audio tasks: Base your answer ONLY on the transcription above. ""If it is empty or missing, call transcribe_audio again. ""Never guess names, numbers, or dates—quote them directly from the transcript.")tool_hint = ""except Exception as tr_exc:8 unmodified linesf"\n\nTask ID: {task_id}. The task attachment is downloaded at '{prefetched_path}'. "f"Call inspect_image(image_path='{prefetched_path}', question=...) immediately.")prompt += ("\n\nIMPORTANT for image tasks: Extract ALL visible numbers, labels, and text first. ""For tables/charts, read row/column headers and data cells before answering. ""For chess positions, identify piece placement and whose turn it is. ""Do not describe the image generally—answer the specific question asked.")else:tool_hint = f"Call read_local_file(file_path='{prefetched_path}') immediately."read_fn = getattr(self, "_read_local_file", None) or tools_map.get("read_local_file")6 unmodified linesand not file_preview.startswith(("Error ", "File not found"))):prompt += (f"\n\nTask ID: {task_id}. Attachment '{prefetched_path}' content (truncated):\n"f"{file_preview.strip()[:4000]}")tool_hint = ""except Exception as rd_exc:12 unmodified linesf"call download_task_file(task_id='{task_id}', preferred_filename='{clean_file_name}') first.")prompt_lower = prompt.lower()if "table" in prompt_lower or "|*|" in prompt or "commutative" in prompt_lower:prompt += ("\n\nIMPORTANT: For table/operation tasks, write Python that builds a dict of dicts, ""then loops over all pairs (x,y) and checks table[x][y] != table[y][x]. ""Collect all elements from pairs where this is true into a set, sort alphabetically, ""and output as comma-separated string. Do NOT use undefined variables.")if "youtube.com" in prompt or "youtu.be" in prompt or " video" in prompt_lower:prompt += ("\n\nIMPORTANT for video tasks: Call inspect_youtube first. ""If it returns 'Transcript/Video Analysis Status: unavailable', do NOT guess. ""Immediately use web_search with the video title/channel or search_wikipedia for the quoted dialogue. ""Answer only from retrieved text, never invent.")if "between" in prompt_lower and ("album" in prompt_lower or "published" in prompt_lower):prompt += ("\n\nIMPORTANT: Extract the Discography/Studio albums table from the Wikipedia text. ""Count entries where the year is >= start_year and <= end_year. ""If the table is not visible in the provided text, call search_wikipedia again with ""the exact article title + ' discography' to get the full section.")blocked_models = set(self._dead_models)blocked_providers = set()48 unmodified linesbuilt_model.timeout = call_timeoutbuilt_model.deadline = deadlinerun_agent = self._create_code_agent(built_model)run_agent.max_steps = 4 if rem_now > 45.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} "15 unmodified linesfallback_clean = self._clean_exact_match_answer(str(cand_val))if (fallback_cleanand not fallback_clean.startswith(("AGENT ERROR:", "Error ", "No attachment", "No web results", "No Wikipedia"))and "\n" not in fallback_cleanand len(fallback_clean) <= 200):141 unmodified linesself._local_state.deadline = Noneself._task_deadline = Nonereturn ""def _trim_tool_output(text: str, max_chars: int = 4000) -> str:
app.py+47-9