瀏覽代碼

added timeout capture

master
Evgeniy Ierusalimov 2 週之前
父節點
當前提交
2897749ee3
共有 2 個檔案被更改,包括 10 行新增2 行删除
  1. 1
    1
      src/image_ocr.py
  2. 9
    1
      src/postprocess/qwen_client.py

+ 1
- 1
src/image_ocr.py 查看文件

@@ -185,7 +185,7 @@ def image_to_latex(
185 185
         filtered: list[Path] = []
186 186
         for p in image_paths:
187 187
             if (out / (p.stem + RAW_EXTENSION)).exists():
188
-                logger.info("Пропуск %s (уже есть .json)", p.name)
188
+                logger.info("Пропуск %s (уже есть %s)", p.name, RAW_EXTENSION)
189 189
                 skipped += 1
190 190
             else:
191 191
                 filtered.append(p)

+ 9
- 1
src/postprocess/qwen_client.py 查看文件

@@ -54,7 +54,7 @@ def call_qwen_vlm(
54 54
                 API_URL,
55 55
                 headers={"x-api-key": _api_key(), "anthropic-version": "2023-06-01", "Content-Type": "application/json"},
56 56
                 json={"model": model, "max_tokens": max_tokens, "messages": messages},
57
-                timeout=120,
57
+                timeout=300,
58 58
             )
59 59
             r.raise_for_status()
60 60
             data = r.json()
@@ -76,6 +76,14 @@ def call_qwen_vlm(
76 76
                 continue
77 77
             logger.warning("Qwen API: ошибка — %s", e)
78 78
             return None, {}
79
+        except (requests.Timeout, requests.ConnectionError) as e:
80
+            if attempt < 3:
81
+                delay = 5 * attempt
82
+                logger.info("Qwen API: таймаут/соединение, ожидание %dс и повтор...", delay)
83
+                _time.sleep(delay)
84
+                continue
85
+            logger.warning("Qwen API: ошибка — %s", e)
86
+            return None, {}
79 87
         except (requests.RequestException, KeyError, IndexError) as e:
80 88
             logger.warning("Qwen API: ошибка — %s", e)
81 89
             return None, {}

Loading…
取消
儲存