Update app.py
Browse files
app.py
CHANGED
@@ -111,22 +111,22 @@ def ask(query, max_attempt_times=3):
|
|
111 |
return answer
|
112 |
|
113 |
|
114 |
-
def askingChatGPT(qs, qas, min_interval_seconds=10, max_interval_seconds=
|
115 |
|
116 |
for i, q in enumerate(qs):
|
117 |
ask_start_time = time.time()
|
118 |
|
119 |
#a = ask(q)
|
120 |
-
def ask_(q):
|
121 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
122 |
future = executor.submit(ask, q) # 提交函数调用任务
|
123 |
try:
|
124 |
-
a = future.result(timeout=
|
125 |
return a
|
126 |
except concurrent.futures.TimeoutError:
|
127 |
-
print('ask call timed out after',
|
128 |
-
return ask_(q) # 当超时时,重新调用函数
|
129 |
-
a = ask_(q)
|
130 |
|
131 |
qas.append({"q":q, "a":a})
|
132 |
|
|
|
111 |
return answer
|
112 |
|
113 |
|
114 |
+
def askingChatGPT(qs, qas, min_interval_seconds=10, max_interval_seconds=30):
|
115 |
|
116 |
for i, q in enumerate(qs):
|
117 |
ask_start_time = time.time()
|
118 |
|
119 |
#a = ask(q)
|
120 |
+
def ask_(q, timeout):
|
121 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
122 |
future = executor.submit(ask, q) # 提交函数调用任务
|
123 |
try:
|
124 |
+
a = future.result(timeout=timeout) # 等待函数调用任务完成,超时时间为30秒
|
125 |
return a
|
126 |
except concurrent.futures.TimeoutError:
|
127 |
+
print('ask call timed out after', timeout, 'seconds, retrying...')
|
128 |
+
return ask_(q, timeout*2) # 当超时时,重新调用函数
|
129 |
+
a = ask_(q, max_interval_seconds)
|
130 |
|
131 |
qas.append({"q":q, "a":a})
|
132 |
|