add timeout=30s
Browse files- app.py +15 -7
- dialogues_set/qas.json +2 -2
app.py
CHANGED
@@ -89,7 +89,8 @@ def ask(query, max_attempt_times=3):
|
|
89 |
answer = None
|
90 |
attempt_times = 0
|
91 |
while answer is None and attempt_times<max_attempt_times:
|
92 |
-
|
|
|
93 |
try:
|
94 |
answer = openai.ChatCompletion.create(
|
95 |
model="gpt-3.5-turbo",
|
@@ -103,15 +104,17 @@ def ask(query, max_attempt_times=3):
|
|
103 |
idx = openai.api_keys.index(openai.api_key)
|
104 |
idx = (idx + 1) % len(openai.api_keys)
|
105 |
openai.api_key = openai.api_keys[idx]
|
106 |
-
attempt_times
|
107 |
print(f"switch api_key")
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
111 |
return answer
|
112 |
|
113 |
|
114 |
-
def askingChatGPT(qs, qas, min_interval_seconds=3, max_interval_seconds=
|
115 |
|
116 |
for i, q in enumerate(qs):
|
117 |
ask_start_time = time.time()
|
@@ -127,7 +130,12 @@ def askingChatGPT(qs, qas, min_interval_seconds=3, max_interval_seconds=30):
|
|
127 |
print('ask call timed out after', timeout, 'seconds, retrying...')
|
128 |
executor.shutdown(wait=False)
|
129 |
return ask_(q, timeout*2) # 当超时时,重新调用函数
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
qas.append({"q":q, "a":a})
|
133 |
|
|
|
89 |
answer = None
|
90 |
attempt_times = 0
|
91 |
while answer is None and attempt_times<max_attempt_times:
|
92 |
+
wait_time = int(attempt_times*10)
|
93 |
+
time.sleep(wait_time)
|
94 |
try:
|
95 |
answer = openai.ChatCompletion.create(
|
96 |
model="gpt-3.5-turbo",
|
|
|
104 |
idx = openai.api_keys.index(openai.api_key)
|
105 |
idx = (idx + 1) % len(openai.api_keys)
|
106 |
openai.api_key = openai.api_keys[idx]
|
107 |
+
attempt_times += 0
|
108 |
print(f"switch api_key")
|
109 |
+
elif "Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=600)" in str(e):
|
110 |
+
attempt_times += 1000
|
111 |
+
else:
|
112 |
+
attempt_times += 1
|
113 |
+
print(f"retry in {attempt_times*10} seconds...")
|
114 |
return answer
|
115 |
|
116 |
|
117 |
+
def askingChatGPT(qs, qas, min_interval_seconds=3, max_interval_seconds=15, max_retry_times=3):
|
118 |
|
119 |
for i, q in enumerate(qs):
|
120 |
ask_start_time = time.time()
|
|
|
130 |
print('ask call timed out after', timeout, 'seconds, retrying...')
|
131 |
executor.shutdown(wait=False)
|
132 |
return ask_(q, timeout*2) # 当超时时,重新调用函数
|
133 |
+
|
134 |
+
retry_times = 0
|
135 |
+
a = None
|
136 |
+
while a is None and retry_times<max_retry_times:
|
137 |
+
a = ask_(q, max_interval_seconds)
|
138 |
+
retry_times += 1
|
139 |
|
140 |
qas.append({"q":q, "a":a})
|
141 |
|
dialogues_set/qas.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5d9eb4ab3d7f781cc43111beaebc295c888b625f02f61d6407a3f6e610c8f2a4
|
3 |
+
size 24089657
|