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: