Spaces:
Running
Running
Upload teacher_tasks.py
Browse files- jobs/teacher_tasks.py +16 -7
jobs/teacher_tasks.py
CHANGED
|
@@ -180,17 +180,26 @@ class TeacherFatal(RuntimeError):
|
|
| 180 |
|
| 181 |
|
| 182 |
def classify_error(exc: BaseException) -> tuple[str, str]:
|
| 183 |
-
"""-> (genre, explication en français). genre : 'fatal' | 'model' (essayer le modèle suivant) | 'transient'.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
status = getattr(getattr(exc, "response", None), "status_code", None)
|
| 185 |
-
text =
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
return "fatal", ("jeton refusé : ajoutez le droit « Inference Providers » (Make calls to Inference Providers) "
|
| 188 |
"au jeton HF_TOKEN")
|
| 189 |
-
if
|
| 190 |
return "fatal", "crédits Inference Providers épuisés : rechargez le solde ou changez de modèle maître"
|
| 191 |
-
if status in (404, 400, 422) or "not found" in text or "not supported" in text or "no provider" in text \
|
| 192 |
-
or "model_not" in text or "does not exist" in text:
|
| 193 |
-
return "model", "modèle maître indisponible chez les fournisseurs : passage au modèle suivant de la liste"
|
| 194 |
return "transient", "erreur passagère (réseau, surcharge) : nouvel essai"
|
| 195 |
|
| 196 |
|
|
|
|
| 180 |
|
| 181 |
|
| 182 |
def classify_error(exc: BaseException) -> tuple[str, str]:
|
| 183 |
+
"""-> (genre, explication en français). genre : 'fatal' | 'model' (essayer le modèle suivant) | 'transient'.
|
| 184 |
+
|
| 185 |
+
Le code HTTP décide quand il est connu. Sinon, on cherche les codes comme mots entiers : un identifiant de
|
| 186 |
+
requête (« ...de3403a878c ») contient souvent « 403 » ou « 401 » et ne doit pas passer pour un refus du jeton.
|
| 187 |
+
Un modèle non proposé par les fournisseurs activés est testé en premier : c'est un 400, pas un problème de jeton.
|
| 188 |
+
"""
|
| 189 |
+
import re
|
| 190 |
+
|
| 191 |
status = getattr(getattr(exc, "response", None), "status_code", None)
|
| 192 |
+
text = str(exc).lower()
|
| 193 |
+
codes = {int(c) for c in re.findall(r"(?<![\w-])(4\d\d)(?![\w-])", text)}
|
| 194 |
+
code = status if status is not None else next((c for c in (401, 403, 402, 404, 400, 422) if c in codes), None)
|
| 195 |
+
if any(k in text for k in ("not supported by any provider", "not supported", "no provider", "model_not",
|
| 196 |
+
"does not exist", "not found")) or code in (400, 404, 422):
|
| 197 |
+
return "model", "modèle maître indisponible chez les fournisseurs activés : passage au modèle suivant de la liste"
|
| 198 |
+
if code in (401, 403) or "forbidden" in text or "unauthorized" in text:
|
| 199 |
return "fatal", ("jeton refusé : ajoutez le droit « Inference Providers » (Make calls to Inference Providers) "
|
| 200 |
"au jeton HF_TOKEN")
|
| 201 |
+
if code == 402 or "payment required" in text or "credit" in text or "quota" in text:
|
| 202 |
return "fatal", "crédits Inference Providers épuisés : rechargez le solde ou changez de modèle maître"
|
|
|
|
|
|
|
|
|
|
| 203 |
return "transient", "erreur passagère (réseau, surcharge) : nouvel essai"
|
| 204 |
|
| 205 |
|