| 6 | |
| 7 | |
| 8 | def batch_eval(query_file, result1_file, result2_file, output_file_path): |
| 9 | client = OpenAI() |
| 10 | |
| 11 | with open(query_file, "r") as f: |
| 12 | data = f.read() |
| 13 | |
| 14 | queries = re.findall(r"- Question \d+: (.+)", data) |
| 15 | |
| 16 | with open(result1_file, "r") as f: |
| 17 | answers1 = json.load(f) |
| 18 | answers1 = [i["result"] for i in answers1] |
| 19 | |
| 20 | with open(result2_file, "r") as f: |
| 21 | answers2 = json.load(f) |
| 22 | answers2 = [i["result"] for i in answers2] |
| 23 | |
| 24 | requests = [] |
| 25 | for i, (query, answer1, answer2) in enumerate(zip(queries, answers1, answers2)): |
| 26 | sys_prompt = """ |
| 27 | ---Role--- |
| 28 | You are an expert tasked with evaluating two answers to the same question based on three criteria: **Comprehensiveness**, **Diversity**, and **Empowerment**. |
| 29 | """ |
| 30 | |
| 31 | prompt = f""" |
| 32 | You will evaluate two answers to the same question based on three criteria: **Comprehensiveness**, **Diversity**, and **Empowerment**. |
| 33 | |
| 34 | - **Comprehensiveness**: How much detail does the answer provide to cover all aspects and details of the question? |
| 35 | - **Diversity**: How varied and rich is the answer in providing different perspectives and insights on the question? |
| 36 | - **Empowerment**: How well does the answer help the reader understand and make informed judgments about the topic? |
| 37 | |
| 38 | For each criterion, choose the better answer (either Answer 1 or Answer 2) and explain why. Then, select an overall winner based on these three categories. |
| 39 | |
| 40 | Here is the question: |
| 41 | {query} |
| 42 | |
| 43 | Here are the two answers: |
| 44 | |
| 45 | **Answer 1:** |
| 46 | {answer1} |
| 47 | |
| 48 | **Answer 2:** |
| 49 | {answer2} |
| 50 | |
| 51 | Evaluate both answers using the three criteria listed above and provide detailed explanations for each criterion. |
| 52 | |
| 53 | Output your evaluation in the following JSON format: |
| 54 | |
| 55 | {{ |
| 56 | "Comprehensiveness": {{ |
| 57 | "Winner": "[Answer 1 or Answer 2]", |
| 58 | "Explanation": "[Provide explanation here]" |
| 59 | }}, |
| 60 | "Empowerment": {{ |
| 61 | "Winner": "[Answer 1 or Answer 2]", |
| 62 | "Explanation": "[Provide explanation here]" |
| 63 | }}, |
| 64 | "Overall Winner": {{ |
| 65 | "Winner": "[Answer 1 or Answer 2]", |