43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
|
|
|||
|
import os
|
|||
|
import qianfan
|
|||
|
from qianfan.resources.console.data import Data
|
|||
|
import pandas as pd
|
|||
|
import re
|
|||
|
|
|||
|
# 使用安全认证AK/SK鉴权,通过环境变量方式初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
|
|||
|
os.environ["QIANFAN_ACCESS_KEY"] = "ALTxxxxxx"
|
|||
|
os.environ["QIANFAN_SECRET_KEY"] = "95fxxxxxxxx"
|
|||
|
|
|||
|
|
|||
|
chat_comp = qianfan.ChatCompletion()
|
|||
|
|
|||
|
question = []
|
|||
|
with open("/home/zhangxj/WorkFile/LCA-GPT/QA/filters/question.txt","r",encoding="utf-8") as file:
|
|||
|
for line in file.readlines():
|
|||
|
question.append(line.strip())
|
|||
|
|
|||
|
answers = []
|
|||
|
|
|||
|
for ques in question:
|
|||
|
# 指定特定模型
|
|||
|
content = ("你是生命周期领域富有经验和知识的专家。根据你所掌握的知识只用1句话回答问题。不要列出几点来回答,不需要换行"+ques)
|
|||
|
resp = chat_comp.do(model="ERNIE-3.5-8K", messages=[
|
|||
|
{
|
|||
|
"role": "user",
|
|||
|
"content": content
|
|||
|
}])
|
|||
|
|
|||
|
ans = resp["body"]["result"]
|
|||
|
line = re.sub(r'\s+', '', ans)
|
|||
|
print(line)
|
|||
|
answers.append(line)
|
|||
|
|
|||
|
data = {"ans":answers}
|
|||
|
df = pd.DataFrame(data)
|
|||
|
df.to_csv("/home/zhangxj/WorkFile/LCA-GPT/QA/eval/baidu.csv",index=False)
|
|||
|
|
|||
|
with open("/home/zhangxj/WorkFile/LCA-GPT/QA/eval/ERNIEpred.txt","w",encoding="utf-8") as file:
|
|||
|
for ans in answers:
|
|||
|
line = re.sub(r'\s+', '', ans)
|
|||
|
file.write(line+"\n")
|