ignore queries too long
Browse files- app.py +3 -1
- merge_qas.py +8 -13
- questions/qas.json +3 -0
app.py
CHANGED
@@ -85,7 +85,7 @@ def ask(query, timeout=600):
|
|
85 |
answer = None
|
86 |
dead_time = time.time() + timeout
|
87 |
attempt_times = 0
|
88 |
-
while answer is None and time.time()<dead_time:
|
89 |
try:
|
90 |
answer = openai.ChatCompletion.create(
|
91 |
model="gpt-3.5-turbo",
|
@@ -102,6 +102,8 @@ def ask(query, timeout=600):
|
|
102 |
openai.api_key = openai.api_keys[idx]
|
103 |
attempt_times += 0
|
104 |
print(f"switch api_key")
|
|
|
|
|
105 |
else:
|
106 |
attempt_times += 1
|
107 |
wait_time = int(attempt_times*10)
|
|
|
85 |
answer = None
|
86 |
dead_time = time.time() + timeout
|
87 |
attempt_times = 0
|
88 |
+
while answer is None and time.time()<dead_time and attempt_times<10:
|
89 |
try:
|
90 |
answer = openai.ChatCompletion.create(
|
91 |
model="gpt-3.5-turbo",
|
|
|
102 |
openai.api_key = openai.api_keys[idx]
|
103 |
attempt_times += 0
|
104 |
print(f"switch api_key")
|
105 |
+
elif "Please reduce the length of the messages." in str(e):
|
106 |
+
return None
|
107 |
else:
|
108 |
attempt_times += 1
|
109 |
wait_time = int(attempt_times*10)
|
merge_qas.py
CHANGED
@@ -3,28 +3,23 @@ import json
|
|
3 |
import collections
|
4 |
|
5 |
def read_qs():
|
6 |
-
qs = []
|
7 |
-
directory = "./
|
8 |
filenames = [
|
9 |
-
'
|
10 |
-
'
|
11 |
-
'
|
12 |
-
'dialogues_natural.json',
|
13 |
-
'dialogues_taobao.json',
|
14 |
-
'dialogues_travel_kd.json'
|
15 |
]
|
16 |
for filename in filenames:
|
17 |
with open(f"{directory}/{filename}", "r", encoding="utf-8") as f:
|
18 |
for idx,line in enumerate(f):
|
19 |
-
|
20 |
-
query = idx2query[str(idx)]
|
21 |
-
qs.append(query)
|
22 |
print(f"read {len(qs)} queries from files")
|
23 |
return qs
|
24 |
|
25 |
def read_qas():
|
26 |
qas = []
|
27 |
-
directory = "./
|
28 |
|
29 |
for filename in os.listdir(directory):
|
30 |
if filename.endswith(".json") and "qas" in filename:
|
@@ -53,5 +48,5 @@ if __name__ == "__main__":
|
|
53 |
qs = read_qs()
|
54 |
qas = read_qas()
|
55 |
qas = merge(qs, qas)
|
56 |
-
with open("./
|
57 |
f.write(json.dumps(qas, ensure_ascii=False, indent=2))
|
|
|
3 |
import collections
|
4 |
|
5 |
def read_qs():
|
6 |
+
qs, qas = [], []
|
7 |
+
directory = "./questions"
|
8 |
filenames = [
|
9 |
+
'math_question.txt',
|
10 |
+
'qa_question.txt',
|
11 |
+
'summarization_question.txt',
|
|
|
|
|
|
|
12 |
]
|
13 |
for filename in filenames:
|
14 |
with open(f"{directory}/{filename}", "r", encoding="utf-8") as f:
|
15 |
for idx,line in enumerate(f):
|
16 |
+
qs.append(line.replace("ηζζθ¦","ηζδΈζζθ¦"))
|
|
|
|
|
17 |
print(f"read {len(qs)} queries from files")
|
18 |
return qs
|
19 |
|
20 |
def read_qas():
|
21 |
qas = []
|
22 |
+
directory = "./questions"
|
23 |
|
24 |
for filename in os.listdir(directory):
|
25 |
if filename.endswith(".json") and "qas" in filename:
|
|
|
48 |
qs = read_qs()
|
49 |
qas = read_qas()
|
50 |
qas = merge(qs, qas)
|
51 |
+
with open("./questions/qas.json", "w", encoding="utf-8") as f:
|
52 |
f.write(json.dumps(qas, ensure_ascii=False, indent=2))
|
questions/qas.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f3070a38076e44280b5e007a32255000d86488d5b52037a8a7a3917cdaec3450
|
3 |
+
size 10170736
|