ginipick commited on
Commit
fae3f6a
·
verified ·
1 Parent(s): cbe7309

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -9
app.py CHANGED
@@ -37,25 +37,44 @@ from httpx import RemoteProtocolError
37
  # ▸ backoff 모듈이 없으면 즉석에서 대체 구현
38
  try:
39
  import backoff
40
- except ImportError: # ← 최초 실행 환경에서 발생
41
  logging.warning("`backoff` 모듈이 없어 간단 대체 데코레이터를 사용합니다.")
42
- def _simple_backoff_on_exception(exc_tuple, max_tries=3, base=2):
 
 
 
 
 
 
 
 
 
 
 
 
43
  def decorator(fn):
44
- def wrapper(*args, **kwargs):
45
- for attempt in range(1, max_tries + 1):
 
46
  try:
47
- return fn(*args, **kwargs)
48
- except exc_tuple as e:
49
- if attempt == max_tries:
 
50
  raise
51
  sleep = base ** attempt
52
- logging.info(f"Retry {attempt}/{max_tries} after {sleep}s ({e})")
 
 
53
  time.sleep(sleep)
54
  return wrapper
55
  return decorator
 
56
  class _DummyBackoff:
57
  on_exception = _simple_backoff_on_exception
58
- backoff = _DummyBackoff() # 동일 API 제공
 
 
59
 
60
  # ─────────────────────────────── Environment Variables / Constants ─────────────────────────
61
 
@@ -2234,6 +2253,7 @@ def process_input(prompt: str, uploaded_files):
2234
  stream=True
2235
  )
2236
 
 
2237
  try:
2238
  stream = safe_stream()
2239
  for chunk in stream:
 
37
  # ▸ backoff 모듈이 없으면 즉석에서 대체 구현
38
  try:
39
  import backoff
40
+ except ImportError:
41
  logging.warning("`backoff` 모듈이 없어 간단 대체 데코레이터를 사용합니다.")
42
+
43
+ def _simple_backoff_on_exception(exceptions, *args, **kwargs):
44
+ """
45
+ 가벼운 지수(backoff=2^n) 재시도 데코레이터.
46
+ backoff.on_exception API의 필수 인자만 흉내냅니다.
47
+ - exceptions : 재시도 대상 예외(tuple 또는 단일)
48
+ - max_tries : kwargs 로 지정(기본 3)
49
+ - base : kwargs 로 지정(기본 2, 지수 배수)
50
+ 기타 인자는 무시합니다.
51
+ """
52
+ max_tries = kwargs.get("max_tries", 3)
53
+ base = kwargs.get("base", 2)
54
+
55
  def decorator(fn):
56
+ def wrapper(*f_args, **f_kwargs):
57
+ attempt = 0
58
+ while True:
59
  try:
60
+ return fn(*f_args, **f_kwargs)
61
+ except exceptions as e:
62
+ attempt += 1
63
+ if attempt >= max_tries:
64
  raise
65
  sleep = base ** attempt
66
+ logging.info(
67
+ f"[retry {attempt}/{max_tries}] {fn.__name__} -> {e} … {sleep}s 대기"
68
+ )
69
  time.sleep(sleep)
70
  return wrapper
71
  return decorator
72
+
73
  class _DummyBackoff:
74
  on_exception = _simple_backoff_on_exception
75
+
76
+ backoff = _DummyBackoff()
77
+
78
 
79
  # ─────────────────────────────── Environment Variables / Constants ─────────────────────────
80
 
 
2253
  stream=True
2254
  )
2255
 
2256
+
2257
  try:
2258
  stream = safe_stream()
2259
  for chunk in stream: