Files
dsProject/dsLightRag/Test/T5_Fix.py
2025-08-14 15:45:08 +08:00

65 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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'
if __name__ == '__main__':
prompt = """
请针对下面这两段文字【1】和【2】进行评分最高分为10分最低分为0分每1分差别为一个档次。
具体评分标准为:
只要【1】中包含【2】完全相同或者含义相同的内容即从【1】可以推理出【2】即视为正确打10分
【1】中完全没有【2】表达的内容即视为错误打0分趋于中间的按照涵盖程度打分分越高越相似。
请注意:结果展示时,请按照如下标准进行输出:
先展示分析过程然后展示最终得分【最终得分】x分x替换为具体的分数范围从0到10的整数。
"""
wb = load_workbook(excel_file)
ws = wb.active # 获取第一个sheet
for row in range(2, 102): # 行号从2到101
if ws['Q' + str(row)] and ws['Q' + str(row)].value:
print("发现已评估完得分的问题,将跳过,得分:"+ws['Q' + str(row)].value)
continue
# 提示词
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("恭喜,所有任务处理完成!")