-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_answer.py
More file actions
36 lines (28 loc) · 1017 Bytes
/
generate_answer.py
File metadata and controls
36 lines (28 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
from gradio_client import Client
client1 = Client("http://127.0.0.1:7860/")
def gen_client(model_choice, prompt, temperature):
result1 = client1.predict(
model_choice=model_choice,
prompt=prompt,
temperature=temperature,
api_name="/predict"
)
return result1
# 读取输入文件
input_filename = '测试集-day1.jsonl'
output_filename = '2021030014.jsonl'
with open(input_filename, 'r', encoding='utf-8') as infile, open(output_filename, 'w', encoding='utf-8') as outfile:
for line in infile:
data = json.loads(line)
question = data["question"]
# 调用API生成答案
answer = gen_client("SFT", question, 0.01)
# 构建输出JSONL格式
output_data = {
"question": question,
"answer": answer
}
# 写入输出文件
outfile.write(json.dumps(output_data, ensure_ascii=False) + '\n')
print(f"输出已保存到 {output_filename}")