Spaces:
Paused
Paused
OpenAI缩减了免费用户的请求速率限制
Browse files- config.py +4 -3
- crazy_functions/crazy_utils.py +10 -2
config.py
CHANGED
@@ -19,6 +19,10 @@ if USE_PROXY:
|
|
19 |
else:
|
20 |
proxies = None
|
21 |
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# [step 3]>> 以下配置可以优化体验,但大部分场合下并不需要修改
|
24 |
# 对话窗的高度
|
@@ -33,9 +37,6 @@ LAYOUT = "LEFT-RIGHT" # "LEFT-RIGHT"(左右布局) # "TOP-DOWN"(上下布
|
|
33 |
# 发送请求到OpenAI后,等待多久判定为超时
|
34 |
TIMEOUT_SECONDS = 30
|
35 |
|
36 |
-
# 多线程函数插件中,默认允许多少路线程同时访问OpenAI。OpenAI的限制是不能超过20
|
37 |
-
DEFAULT_WORKER_NUM = 8
|
38 |
-
|
39 |
# 网页的端口, -1代表随机端口
|
40 |
WEB_PORT = -1
|
41 |
|
|
|
19 |
else:
|
20 |
proxies = None
|
21 |
|
22 |
+
# 多线程函数插件中,默认允许多少路线程同时访问OpenAI。Free trial users的限制是每分钟3次,提高限制请查询:
|
23 |
+
# https://platform.openai.com/docs/guides/rate-limits/overview
|
24 |
+
DEFAULT_WORKER_NUM = 3
|
25 |
+
|
26 |
|
27 |
# [step 3]>> 以下配置可以优化体验,但大部分场合下并不需要修改
|
28 |
# 对话窗的高度
|
|
|
37 |
# 发送请求到OpenAI后,等待多久判定为超时
|
38 |
TIMEOUT_SECONDS = 30
|
39 |
|
|
|
|
|
|
|
40 |
# 网页的端口, -1代表随机端口
|
41 |
WEB_PORT = -1
|
42 |
|
crazy_functions/crazy_utils.py
CHANGED
@@ -221,13 +221,21 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
|
|
221 |
except:
|
222 |
# 【第三种情况】:其他错误
|
223 |
tb_str = '```\n' + traceback.format_exc() + '```'
|
|
|
224 |
gpt_say += f"[Local Message] 警告,线程{index}在执行过程中遭遇问题, Traceback:\n\n{tb_str}\n\n"
|
225 |
if len(mutable[index][0]) > 0: gpt_say += "此线程失败前收到的回答:\n\n" + mutable[index][0]
|
226 |
if retry_op > 0:
|
227 |
retry_op -= 1
|
228 |
wait = random.randint(5, 20)
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
mutable[index][2] = f"重试中 {retry_times_at_unknown_error-retry_op}/{retry_times_at_unknown_error}"
|
232 |
continue # 返回重试
|
233 |
else:
|
|
|
221 |
except:
|
222 |
# 【第三种情况】:其他错误
|
223 |
tb_str = '```\n' + traceback.format_exc() + '```'
|
224 |
+
print(tb_str)
|
225 |
gpt_say += f"[Local Message] 警告,线程{index}在执行过程中遭遇问题, Traceback:\n\n{tb_str}\n\n"
|
226 |
if len(mutable[index][0]) > 0: gpt_say += "此线程失败前收到的回答:\n\n" + mutable[index][0]
|
227 |
if retry_op > 0:
|
228 |
retry_op -= 1
|
229 |
wait = random.randint(5, 20)
|
230 |
+
if "Rate limit reached" in tb_str:
|
231 |
+
wait = wait * 5
|
232 |
+
fail_info = "OpenAI请求速率限制 "
|
233 |
+
else:
|
234 |
+
fail_info = ""
|
235 |
+
# 也许等待十几秒后,情况会好转
|
236 |
+
for i in range(wait):
|
237 |
+
mutable[index][2] = f"{fail_info}等待重试 {wait-i}"; time.sleep(1)
|
238 |
+
# 开始重试
|
239 |
mutable[index][2] = f"重试中 {retry_times_at_unknown_error-retry_op}/{retry_times_at_unknown_error}"
|
240 |
continue # 返回重试
|
241 |
else:
|