|
|
|
|
|
import os |
|
import json |
|
from datetime import datetime |
|
|
|
current_dir = os.path.dirname(__file__) |
|
logs_dir = os.path.join(current_dir, "..", "results", "logs") |
|
os.makedirs(logs_dir, exist_ok=True) |
|
|
|
def log_output(dataset, model_name, prompt_method, question_id, log_data): |
|
""" |
|
记录推理过程日志,写入 results/logs 目录(按模型/方法/数据集分类) |
|
""" |
|
filename = f"{dataset}_{model_name}_{prompt_method}.log" |
|
file_path = os.path.join(logs_dir, filename) |
|
|
|
log_entry = { |
|
"id": question_id, |
|
"timestamp": datetime.now().isoformat(), |
|
**log_data |
|
} |
|
|
|
with open(file_path, "a", encoding="utf-8") as f: |
|
f.write(json.dumps(log_entry, ensure_ascii=False) + "\n") |
|
|