|
|
|
@ -1,7 +1,17 @@
|
|
|
|
|
import logging
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
from openpyxl import load_workbook
|
|
|
|
|
|
|
|
|
|
from Util import LlmUtil
|
|
|
|
|
|
|
|
|
|
# 更详细地控制日志输出
|
|
|
|
|
logger = logging.getLogger('MathRag')
|
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
handler = logging.StreamHandler()
|
|
|
|
|
handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
|
|
|
|
logger.addHandler(handler)
|
|
|
|
|
|
|
|
|
|
# 要处理的Excel
|
|
|
|
|
excel_file = r'D:\dsWork\dsProject\dsLightRag\Doc\T1、史校长资料\测试结果\100题测试结果.xlsx'
|
|
|
|
|
|
|
|
|
@ -17,19 +27,35 @@ if __name__ == '__main__':
|
|
|
|
|
wb = load_workbook(excel_file)
|
|
|
|
|
ws = wb.active # 获取第一个sheet
|
|
|
|
|
|
|
|
|
|
query_text = prompt + "\n"
|
|
|
|
|
query_text = query_text + "下面将提供两段文字:\n"
|
|
|
|
|
query_text = query_text + "【1】:\n"
|
|
|
|
|
O2_content = ws['O2'].value
|
|
|
|
|
query_text = query_text + O2_content + "\n"
|
|
|
|
|
|
|
|
|
|
query_text = query_text + "【2】:\n"
|
|
|
|
|
O2_content = ws['D2'].value
|
|
|
|
|
query_text = query_text + O2_content + "\n"
|
|
|
|
|
|
|
|
|
|
response = LlmUtil.get_llm_response(query_text)
|
|
|
|
|
print(response)
|
|
|
|
|
# 对比
|
|
|
|
|
# 【1】:O2,【2】:D2 内容
|
|
|
|
|
# 结果保存到 P2 (打分过程) Q2(通过正则表达式截取出的 【最终得分】)
|
|
|
|
|
for row in range(2, 102): # 行号从2到101
|
|
|
|
|
# 提示词
|
|
|
|
|
query_text = prompt + "\n"
|
|
|
|
|
query_text = query_text + "下面将提供两段文字:\n"
|
|
|
|
|
|
|
|
|
|
query_text = query_text + "【1】:\n"
|
|
|
|
|
O_content = ws['O' + str(row)].value
|
|
|
|
|
query_text = query_text + O_content + "\n"
|
|
|
|
|
|
|
|
|
|
query_text = query_text + "【2】:\n"
|
|
|
|
|
D_content = ws['D' + str(row)].value
|
|
|
|
|
query_text = query_text + D_content + "\n"
|
|
|
|
|
|
|
|
|
|
question = ws['C' + str(row)].value # 获取问题
|
|
|
|
|
logger.info("问题" + str(row - 1) + ":" + question)
|
|
|
|
|
response = LlmUtil.get_llm_response(query_text)
|
|
|
|
|
# 【1】:O2,【2】:D2 内容
|
|
|
|
|
# 结果保存到 P2 (打分过程) Q2(通过正则表达式截取出的 【最终得分】)
|
|
|
|
|
# 使用正则表达式提取【最终得分】
|
|
|
|
|
match = re.search(r'【最终得分】:(\d+)分', response)
|
|
|
|
|
final_score = '0'
|
|
|
|
|
if match:
|
|
|
|
|
final_score = match.group(1)
|
|
|
|
|
# 保存到P2(打分过程)和Q2(最终得分)
|
|
|
|
|
ws['P' + str(row)] = prompt + "\n" + response # 提示词+大模型响应
|
|
|
|
|
ws['Q' + str(row)] = final_score
|
|
|
|
|
logger.info("大模型响应:" + response)
|
|
|
|
|
logger.info("得分:" + final_score)
|
|
|
|
|
|
|
|
|
|
wb.save(excel_file)
|
|
|
|
|
wb.close()
|
|
|
|
|
logger.info("恭喜,所有任务处理完成!")
|
|
|
|
|