Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files732 unmodified lines7337347357367377387387397397407417427437441870 unmodified lines2615261626172616261726182619262026212622262326242625262626278 unmodified lines2636263726382639264026412642264326442645264626476 unmodified lines265426552656264426452657265826592660266112 unmodified lines2674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270248 unmodified lines2751275227532718275427552756275715 unmodified lines2773277427752740277627772778277927802781141 unmodified lines29232924292528882926292729282929732 unmodified lines text = ""
if len(text) > 4800: # Najpierw spróbuj znaleźć sekcję Discography i zwróć ją priorytetowo 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] start = max(0, disc_match.start() - 200) disc_section = text[start:start + 4000] text = text[:800] + "\n...\n" + disc_section else: text = text[:2400] + "\n...\n" + text[-2400:]
1870 unmodified lines and 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]}" 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 lines f"\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 lines and 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]}" 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 lines f"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 lines built_model.timeout = call_timeout built_model.deadline = deadline run_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) 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 lines fallback_clean = self._clean_exact_match_answer(str(cand_val)) if ( fallback_clean and not fallback_clean.startswith(("AGENT ERROR:", "Error ", "No attachment")) and not fallback_clean.startswith( ("AGENT ERROR:", "Error ", "No attachment", "No web results", "No Wikipedia") ) and "\n" not in fallback_clean and len(fallback_clean) <= 200 ):141 unmodified lines self._local_state.deadline = None self._task_deadline = None
return "AGENT ERROR: All candidate models failed." return ""
def _trim_tool_output(text: str, max_chars: int = 4000) -> str:app.py+47-9