Skip to content

Commit 79e2d81

Browse files
committed
refactor: Update comments and documentation in config, llm, and rate_limiter modules for clarity and consistency
1 parent 8d515cb commit 79e2d81

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

sources/gc-qa-rag-etl/etlapp/common/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LlmConfig:
1919
api_key: str
2020
api_base: str
2121
model_name: str
22-
max_rpm: int = 100 # 每分钟最大请求数,默认100
22+
max_rpm: int = 100 # Maximum requests per minute, default 100
2323

2424

2525
@dataclass
@@ -66,7 +66,7 @@ def from_environment(cls, environment: str) -> "Config":
6666
api_key=config_raw["llm"]["api_key"],
6767
api_base=config_raw["llm"]["api_base"],
6868
model_name=config_raw["llm"]["model_name"],
69-
max_rpm=config_raw["llm"].get("max_rpm", 60), # 默认60 RPM
69+
max_rpm=config_raw["llm"].get("max_rpm", 100),
7070
),
7171
embedding=EmbeddingConfig(api_key=config_raw["embedding"]["api_key"]),
7272
vector_db=VectorDbConfig(host=config_raw["vector_db"]["host"]),

sources/gc-qa-rag-etl/etlapp/common/llm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def __init__(
2020
self.system_prompt = system_prompt
2121
self.temperature = temperature
2222
self.top_p = top_p
23-
# 初始化限流器
23+
# Initialize rate limiter
2424
self.rate_limiter = RateLimiter(max_requests=max_rpm, window_seconds=60)
2525

2626
def _create_completion(self, messages: List[Dict[str, str]]) -> str:
27-
# 在发送请求前进行限流
27+
# Apply rate limiting before sending request
2828
self.rate_limiter.wait_and_acquire()
2929

3030
completion = self.client.chat.completions.create(
@@ -47,10 +47,10 @@ def chat_with_messages(self, messages: List[Dict[str, str]]) -> str:
4747

4848
def get_rate_limit_status(self) -> dict:
4949
"""
50-
获取当前限流状态
50+
Get current rate limit status
5151
5252
Returns:
53-
dict: 包含剩余请求数和重置时间的状态信息
53+
dict: Status information containing remaining requests and reset time
5454
"""
5555
remaining = self.rate_limiter.get_remaining_requests()
5656
reset_time = self.rate_limiter.get_reset_time()

sources/gc-qa-rag-etl/etlapp/common/rate_limiter.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
class RateLimiter:
88
"""
9-
线程安全的速率限制器,支持RPM(每分钟请求数)限制
9+
Thread-safe rate limiter with RPM (requests per minute) support
1010
"""
1111

1212
def __init__(self, max_requests: int, window_seconds: int = 60):
1313
"""
14-
初始化速率限制器
14+
Initialize rate limiter
1515
1616
Args:
17-
max_requests: 在指定时间窗口内允许的最大请求数
18-
window_seconds: 时间窗口大小(秒),默认60秒(1分钟)
17+
max_requests: Maximum number of requests allowed within the specified time window
18+
window_seconds: Time window size in seconds, default is 60 seconds (1 minute)
1919
"""
2020
self.max_requests = max_requests
2121
self.window_seconds = window_seconds
@@ -24,74 +24,74 @@ def __init__(self, max_requests: int, window_seconds: int = 60):
2424

2525
def acquire(self, timeout: Optional[float] = None) -> bool:
2626
"""
27-
尝试获取请求许可
27+
Try to acquire request permission
2828
2929
Args:
30-
timeout: 超时时间(秒),None表示无限等待
30+
timeout: Timeout in seconds, None means infinite wait
3131
3232
Returns:
33-
bool: 是否成功获取许可
33+
bool: Whether permission was successfully acquired
3434
"""
3535
start_time = time.time()
3636

3737
while True:
3838
with self._lock:
3939
current_time = time.time()
4040

41-
# 清理过期的请求记录
41+
# Clean up expired request records
4242
while self.requests and current_time - self.requests[0] > self.window_seconds:
4343
self.requests.popleft()
4444

45-
# 检查是否可以发送请求
45+
# Check if request can be sent
4646
if len(self.requests) < self.max_requests:
4747
self.requests.append(current_time)
4848
return True
4949

50-
# 检查超时
50+
# Check timeout
5151
if timeout is not None and time.time() - start_time >= timeout:
5252
return False
5353

54-
# 等待一小段时间再重试
54+
# Wait a short time before retrying
5555
time.sleep(0.1)
5656

5757
def wait_and_acquire(self) -> None:
5858
"""
59-
等待直到可以获取请求许可(阻塞式)
59+
Wait until request permission can be acquired (blocking)
6060
"""
6161
self.acquire(timeout=None)
6262

6363
def get_remaining_requests(self) -> int:
6464
"""
65-
获取当前时间窗口内剩余的请求数
65+
Get remaining requests in current time window
6666
6767
Returns:
68-
int: 剩余请求数
68+
int: Number of remaining requests
6969
"""
7070
with self._lock:
7171
current_time = time.time()
7272

73-
# 清理过期的请求记录
73+
# Clean up expired request records
7474
while self.requests and current_time - self.requests[0] > self.window_seconds:
7575
self.requests.popleft()
7676

7777
return max(0, self.max_requests - len(self.requests))
7878

7979
def get_reset_time(self) -> Optional[float]:
8080
"""
81-
获取下次可以发送请求的时间戳
81+
Get timestamp when next request can be sent
8282
8383
Returns:
84-
Optional[float]: 下次可发送请求的时间戳,None表示立即可发送
84+
Optional[float]: Timestamp when next request can be sent, None means can send immediately
8585
"""
8686
with self._lock:
8787
current_time = time.time()
8888

89-
# 清理过期的请求记录
89+
# Clean up expired request records
9090
while self.requests and current_time - self.requests[0] > self.window_seconds:
9191
self.requests.popleft()
9292

9393
if len(self.requests) < self.max_requests:
9494
return None
9595

96-
# 返回最早请求过期的时间
96+
# Return the expiration time of the earliest request
9797
return self.requests[0] + self.window_seconds

0 commit comments

Comments
 (0)