jisubae commited on
Commit
ca1e416
Β·
1 Parent(s): 066aab5

feat: random key rotation

Browse files
freshqa/fresheval_parallel.py CHANGED
@@ -93,8 +93,9 @@ class FreshEvalParallel:
93
  """μ›Œμ»€ ν•¨μˆ˜ - 각 μ›Œμ»€λ§ˆλ‹€ 독립적인 FreshEval μΈμŠ€ν„΄μŠ€ 생성"""
94
  row, mode, current_date = args
95
 
96
- # 각 μ›Œμ»€λ§ˆλ‹€ 독립적인 FreshEval μΈμŠ€ν„΄μŠ€ 생성 (λ‘œν…Œμ΄ν„°λ‘œ ν‚€ λΆ„λ°°)
97
- api_key = get_rotator().pick_key()
 
98
  worker_eval = FreshEval(model=self.model, api_key=api_key)
99
 
100
  # κΈ°μ‘΄ evaluate_single_row λ©”μ„œλ“œ μ‚¬μš©
 
93
  """μ›Œμ»€ ν•¨μˆ˜ - 각 μ›Œμ»€λ§ˆλ‹€ 독립적인 FreshEval μΈμŠ€ν„΄μŠ€ 생성"""
94
  row, mode, current_date = args
95
 
96
+ # 각 μ›Œμ»€λ§ˆλ‹€ λžœλ€ν•œ ν‚€λ‘œ μ‹œμž‘ (λΆ€ν•˜ λΆ„μ‚°)
97
+ # 429 μ—λŸ¬ λ°œμƒ μ‹œ FreshEval λ‚΄λΆ€μ—μ„œ μžλ™μœΌλ‘œ λ‹€μŒ ν‚€λ‘œ 순차 λ‘œν…Œμ΄μ…˜
98
+ api_key = get_rotator().pick_key_random()
99
  worker_eval = FreshEval(model=self.model, api_key=api_key)
100
 
101
  # κΈ°μ‘΄ evaluate_single_row λ©”μ„œλ“œ μ‚¬μš©
src/api_key_rotator.py CHANGED
@@ -4,6 +4,7 @@ API ν‚€ λ‘œν…Œμ΄ν„° λͺ¨λ“ˆ
4
  """
5
 
6
  import threading
 
7
  from itertools import count
8
  from typing import List
9
 
@@ -42,6 +43,27 @@ class ApiKeyRotator:
42
  with self._lock:
43
  index = next(self._counter) % len(self.keys)
44
  return self.keys[index]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
 
47
  # μ „μ—­ μΈμŠ€ν„΄μŠ€ (싱글톀 νŒ¨ν„΄)
 
4
  """
5
 
6
  import threading
7
+ import random
8
  from itertools import count
9
  from typing import List
10
 
 
43
  with self._lock:
44
  index = next(self._counter) % len(self.keys)
45
  return self.keys[index]
46
+
47
+ def pick_key_random(self) -> str:
48
+ """
49
+ λžœλ€ν•˜κ²Œ ν‚€λ₯Ό μ„ νƒν•©λ‹ˆλ‹€ (Thread-safe)
50
+
51
+ Returns:
52
+ λžœλ€ν•˜κ²Œ μ„ νƒλœ API ν‚€
53
+
54
+ Example:
55
+ >>> rotator = ApiKeyRotator(["key1", "key2", "key3"])
56
+ >>> rotator.pick_key_random() # "key2" (랜덀)
57
+ >>> rotator.pick_key_random() # "key1" (랜덀)
58
+ >>> rotator.pick_key_random() # "key3" (랜덀)
59
+
60
+ Note:
61
+ - μ›Œμ»€ μ‹œμž‘ μ‹œ 첫 ν‚€λ₯Ό 선택할 λ•Œ μ‚¬μš©ν•˜μ—¬ λΆ€ν•˜λ₯Ό λΆ„μ‚°μ‹œν‚΅λ‹ˆλ‹€.
62
+ - 각 μœ μ €/μ›Œμ»€κ°€ μ„œλ‘œ λ‹€λ₯Έ ν‚€λ‘œ μ‹œμž‘ν•˜μ—¬ νŠΉμ • 킀에 λΆ€ν•˜κ°€ μ§‘μ€‘λ˜λŠ” 것을 λ°©μ§€ν•©λ‹ˆλ‹€.
63
+ """
64
+ with self._lock:
65
+ index = random.randint(0, len(self.keys) - 1)
66
+ return self.keys[index]
67
 
68
 
69
  # μ „μ—­ μΈμŠ€ν„΄μŠ€ (싱글톀 νŒ¨ν„΄)