Delete make_qas_comparison.py
Browse files- make_qas_comparison.py +0 -61
make_qas_comparison.py
DELETED
@@ -1,61 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import json
|
3 |
-
import pandas as pd
|
4 |
-
import openpyxl
|
5 |
-
from tqdm import tqdm
|
6 |
-
from win32com.client import Dispatch
|
7 |
-
|
8 |
-
def just_open(filename):
|
9 |
-
xlApp = Dispatch("Excel.Application")
|
10 |
-
xlApp.Visible = False
|
11 |
-
xlBook = xlApp.Workbooks.Open(os.path.abspath(filename))
|
12 |
-
xlBook.Save()
|
13 |
-
xlBook.Close()
|
14 |
-
|
15 |
-
win_rate_prompt = """
|
16 |
-
考虑以下问题:
|
17 |
-
“{prompt}”
|
18 |
-
我们认定一个好的回复需要形式简约、内容详尽、回答正确,请判断以下哪一个回复更好地回答了这个问题?
|
19 |
-
回复A:
|
20 |
-
“{A}”
|
21 |
-
回复B:
|
22 |
-
“{B}”
|
23 |
-
请首先用一句话具体比较以上两个回复,阐述哪一个回复更好以及为什么。然后,在新的一行,写明(且仅写出)“A”或“B”以明确指示哪个回复在你的比较中胜出。按以下格式给出你的答复:
|
24 |
-
具体比较:
|
25 |
-
胜出的回复:<"A"或"B">
|
26 |
-
""".strip()
|
27 |
-
|
28 |
-
def make_query(prompt,A,B):
|
29 |
-
q = win_rate_prompt.format(prompt=prompt.strip(), A=A.strip(), B=B.strip())
|
30 |
-
a = None
|
31 |
-
return {"q":q, "a":a}
|
32 |
-
|
33 |
-
def read_excel(file):
|
34 |
-
just_open(filename=file)
|
35 |
-
workbook: openpyxl.Workbook = openpyxl.load_workbook(filename=file, read_only=True, data_only=True, keep_links=False, keep_vba=False)
|
36 |
-
sheet = workbook.active
|
37 |
-
qas = []
|
38 |
-
for row in tqdm(sheet.iter_rows(min_row=2, max_row=sheet.max_row,
|
39 |
-
min_col=1, max_col=5, values_only=True), total=sheet.max_row-1):
|
40 |
-
assert all([_ is not None for _ in row])
|
41 |
-
prompt, A, B, C, D = row
|
42 |
-
qas.append(make_query(prompt, A, B))
|
43 |
-
qas.append(make_query(prompt, C, A))
|
44 |
-
qas.append(make_query(prompt, A, D))
|
45 |
-
qas.append(make_query(prompt, B, C))
|
46 |
-
qas.append(make_query(prompt, D, B))
|
47 |
-
qas.append(make_query(prompt, C, D))
|
48 |
-
print(f"include {len(qas)} qas from {file}")
|
49 |
-
return qas
|
50 |
-
|
51 |
-
input_dir = "./"
|
52 |
-
qas = []
|
53 |
-
for file in os.listdir(input_dir):
|
54 |
-
if file.startswith("~$"):
|
55 |
-
continue
|
56 |
-
if not file.endswith(".xlsx"):
|
57 |
-
continue
|
58 |
-
qas += read_excel(f"{input_dir}/{file}")
|
59 |
-
|
60 |
-
with open(f"{input_dir}/qas.json", "w", encoding="utf-8") as f:
|
61 |
-
f.write(json.dumps(qas, ensure_ascii=False))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|