Skip to content

Commit f4916b0

Browse files
committed
给OpenAIAgent的验证探测也实施速率限制
1 parent bc3fa19 commit f4916b0

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

core/models/agent.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def validate(self) -> bool:
112112
if self.api_key:
113113
try:
114114
client = self._init()
115+
# 应用速率限制
116+
self._wait_for_rate_limit()
117+
115118
res = client.with_options(max_retries=3).chat.completions.create(
116119
extra_headers=self.EXTRA_HEADERS,
117120
model=self.model,
@@ -152,8 +155,6 @@ def detect_model_limit(self, force=False) -> int:
152155
if not force and self.max_tokens > 0:
153156
return self.max_tokens
154157

155-
# test_range = [1024, 4096, 8192, 16384, 32768, 65536, 128000, 200000, 400000, 500000, 1000000]
156-
157158
# 二分搜索找到确切限制
158159
def binary_search_limit(low, high):
159160
"""使用二分搜索找到确切的token限制"""
@@ -163,6 +164,8 @@ def binary_search_limit(low, high):
163164
mid = (low + high) // 2
164165

165166
try:
167+
# 应用速率限制
168+
self._wait_for_rate_limit()
166169
# 使用最小的测试内容减少token消耗
167170
response = self._init().chat.completions.create(
168171
extra_headers=self.EXTRA_HEADERS,

0 commit comments

Comments
 (0)