diff --git a/dsLightRag/Config/Config.py b/dsLightRag/Config/Config.py index b5ff471e..c20acad6 100644 --- a/dsLightRag/Config/Config.py +++ b/dsLightRag/Config/Config.py @@ -3,15 +3,15 @@ ALY_AK = 'LTAI5tE4tgpGcKWhbZg6C4bh' ALY_SK = 'oizcTOZ8izbGUouboC00RcmGE8vBQ1' # 大模型 【DeepSeek深度求索官方】训练时用这个 -LLM_API_KEY = "sk-44ae895eeb614aa1a9c6460579e322f1" -LLM_BASE_URL = "https://api.deepseek.com" -LLM_MODEL_NAME = "deepseek-chat" +#LLM_API_KEY = "sk-44ae895eeb614aa1a9c6460579e322f1" +#LLM_BASE_URL = "https://api.deepseek.com" +#LLM_MODEL_NAME = "deepseek-chat" # # 阿里云提供的大模型服务 【阿里云在处理文字材料时,容易引发绿网拦截,导致数据上报异常】 -# LLM_API_KEY = "sk-f6da0c787eff4b0389e4ad03a35a911f" -# LLM_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1" -# LLM_MODEL_NAME = "qwen-plus" # 不要使用通义千问,会导致化学方程式不正确! -# #LLM_MODEL_NAME = "deepseek-v3" +LLM_API_KEY = "sk-f6da0c787eff4b0389e4ad03a35a911f" +LLM_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1" +LLM_MODEL_NAME = "qwen-plus" # 不要使用通义千问,会导致化学方程式不正确! +#LLM_MODEL_NAME = "deepseek-v3" # 嵌入向量模型 EMBED_MODEL_NAME = "BAAI/bge-m3" diff --git a/dsLightRag/Config/__pycache__/Config.cpython-310.pyc b/dsLightRag/Config/__pycache__/Config.cpython-310.pyc index c6d5e1ad..6f95c86a 100644 Binary files a/dsLightRag/Config/__pycache__/Config.cpython-310.pyc and b/dsLightRag/Config/__pycache__/Config.cpython-310.pyc differ diff --git a/dsLightRag/Doc/T1、史校长资料/测试结果/100题测试结果.xlsx b/dsLightRag/Doc/T1、史校长资料/测试结果/100题测试结果.xlsx index 88638885..ca90e7b0 100644 Binary files a/dsLightRag/Doc/T1、史校长资料/测试结果/100题测试结果.xlsx and b/dsLightRag/Doc/T1、史校长资料/测试结果/100题测试结果.xlsx differ diff --git a/dsLightRag/Test/T2_AnswerFromRAG.py b/dsLightRag/Test/T2_AnswerFromRAG.py index 10a93cd0..9c7081a8 100644 --- a/dsLightRag/Test/T2_AnswerFromRAG.py +++ b/dsLightRag/Test/T2_AnswerFromRAG.py @@ -31,19 +31,23 @@ def getAnswer(query_text): return None +# 要处理的Excel excel_file = r'D:\dsWork\dsProject\dsLightRag\Doc\T1、史校长资料\测试结果\100题测试结果.xlsx' if __name__ == '__main__': - # query_text = '什么是数学的性质命题' - # print(getAnswer(query_text)) - wb = load_workbook(excel_file) ws = wb.active # 获取第一个sheet # 读取C列第2行到101行的数据 idx = 1 for row in range(2, 102): # 行号从2到101 - cell_value = ws[f'C{row}'].value - logger.info("问题{}:{}".format(idx, cell_value)) + query_text = ws[f'C{row}'].value + logger.info("问题{}:{}".format(idx, query_text)) + # 知识库作答 + rag_answer = getAnswer(query_text) + logger.info("成功完成问题{}:{}".format(idx, query_text)) + # 回写到Excel表中 + ws['O'+str(idx+1)] = rag_answer idx = idx + 1 - + # 保存修改 + wb.save(excel_file) wb.close() diff --git a/dsLightRag/Test/T3_LLM.py b/dsLightRag/Test/T3_LLM.py new file mode 100644 index 00000000..147e4489 --- /dev/null +++ b/dsLightRag/Test/T3_LLM.py @@ -0,0 +1,6 @@ +from Util import LlmUtil + +if __name__ == '__main__': + query_text = '你是谁?' + response = LlmUtil.get_llm_response(query_text) + print(response) diff --git a/dsLightRag/Test/T4_Score.py b/dsLightRag/Test/T4_Score.py new file mode 100644 index 00000000..37eb21d1 --- /dev/null +++ b/dsLightRag/Test/T4_Score.py @@ -0,0 +1,35 @@ +from openpyxl import load_workbook + +from Util import LlmUtil + +# 要处理的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 + + 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(通过正则表达式截取出的 【最终得分】) + wb.close() diff --git a/dsLightRag/Util/LlmUtil.py b/dsLightRag/Util/LlmUtil.py new file mode 100644 index 00000000..8a9d1856 --- /dev/null +++ b/dsLightRag/Util/LlmUtil.py @@ -0,0 +1,15 @@ +from openai import OpenAI +from Config.Config import * + +def get_llm_response(query_text:str): + # 获取大模型的响应 + client = OpenAI( + api_key=LLM_API_KEY, + base_url=LLM_BASE_URL, + ) + completion = client.chat.completions.create( + model=LLM_MODEL_NAME, + messages=[{'role': 'system', 'content': 'You are a helpful assistant.'}, + {'role': 'user', 'content': query_text}] + ) + return completion.choices[0].message.content \ No newline at end of file diff --git a/dsLightRag/Util/__pycache__/LlmUtil.cpython-310.pyc b/dsLightRag/Util/__pycache__/LlmUtil.cpython-310.pyc new file mode 100644 index 00000000..3c65256c Binary files /dev/null and b/dsLightRag/Util/__pycache__/LlmUtil.cpython-310.pyc differ