Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files960 unmodified lines961962963964965966967968969965970971972968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997973974975976977978979980981960 unmodified lines 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_models
models_to_try = list(getattr(self, "working_models", []) or [self.model_id]) if self.model_id not in models_to_try: if self.model_id and self.model_id not in models_to_try: models_to_try.append(self.model_id)
for model_name in models_to_try: api_key = self._get_api_key(model_name) if hasattr(self, "_get_api_key") else None if not api_key: continue for attempt in range(2): try: response = litellm.completion( model=model_name, api_key=api_key, messages=[ { "role": "system", "content": ( "Answer with ONLY the concise exact answer value itself. " "No explanation, no markdown, no prefix." ), }, {"role": "user", "content": prompt}, ], max_tokens=512, timeout=25, ) content = (response.choices[0].message.content or "").strip() if content: self.model_id = model_name return self._clean_exact_match_answer(content) except Exception as exc: print(f"[DIRECT FALLBACK] task_id={task_id} model={model_name} attempt={attempt + 1}: {exc}") if attempt == 0: time.sleep(1.5) models_to_try = [ m for m in models_to_try if m not in blocked_models and not (m.startswith("openrouter/") and not self.provider_keys.get("openrouter")) ] models_to_try.sort(key=lambda m: (1 if m.startswith("gemini/") else 0))
try: result = self.agent.run(prompt)app.py+12-31