LCA-LLM/LCA_RAG/补充答案.py

42 lines
1.6 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 os
import qianfan
from qianfan.resources.console.data import Data
import pandas as pd
import re
# 使用安全认证AK/SK鉴权通过环境变量方式初始化替换下列示例中参数安全认证Access Key替换your_iam_akSecret Key替换your_iam_sk
os.environ["QIANFAN_ACCESS_KEY"] = "ALTAK8Mo2gY80BAW8RjEtHX3SS"
os.environ["QIANFAN_SECRET_KEY"] = "95f6ac794fcb45b7805d5780bec589dc"
chat_comp = qianfan.ChatCompletion()
question = []
with open("/home/zhangxj/WorkFile/LCA-GPT/QA/split/question/ques0.txt","r",encoding="utf-8") as file:
for line in file.readlines():
question.append(line.strip())
answers = []
with open("/home/zhangxj/WorkFile/LCA-GPT/QA/split/answer/ans0.txt","r",encoding="utf-8") as file:
for line in file.readlines():
answers.append(line.strip())
answer_new = []
for ques,ans in zip(question,answers):
# 指定特定模型
content = f"你是生命周期领域富有经验和知识的专家。我会为你提供一个问题和对应的答案,根据你所掌握的知识简要补充答案内容。不要列出几点来回答,不需要换行。问题是:“{ques}”。答案是:“{ans}"
resp = chat_comp.do(model="ERNIE-4.0-8K", messages=[
{
"role": "user",
"content": content
}])
ans = resp["body"]["result"]
line = re.sub(r'\s+', '', ans)
print("问题:",ques)
print(line)
answer_new.append(line)
with open("/home/zhangxj/WorkFile/LCA-GPT/QA/filters/answer_100.txt","w",encoding="utf-8") as file:
for ans in answer_new:
file.write(ans+"\n")