From 9de97bddf16d58b3622ab9cb20295ac0cb27799d Mon Sep 17 00:00:00 2001 From: sit002 Date: Mon, 1 Dec 2025 23:46:38 +0800 Subject: [PATCH] fix: allow --question to be a string instead of file path --- .autograde/llm_grade.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.autograde/llm_grade.py b/.autograde/llm_grade.py index 22238cd..f9aea73 100644 --- a/.autograde/llm_grade.py +++ b/.autograde/llm_grade.py @@ -24,6 +24,16 @@ def read_file(path): return "" +def read_file_or_string(value): + """ + 如果 value 是一个存在的文件路径,读取文件内容; + 否则直接返回 value 作为字符串。 + """ + if os.path.exists(value): + return open(value, 'r', encoding='utf-8').read() + return value # 当作字符串直接返回 + + PROMPT_TEMPLATE = """你是严格且一致的助教,按提供的评分量表为学生的简答题评分。 - 只依据量表,不做主观延伸;允许多样表述。 @@ -126,8 +136,10 @@ def main(): if not args.api_key: print("Warning: LLM_API_KEY not set. LLM grading may fail.", file=sys.stderr) - # 读取文件 - question = read_file(args.question).strip() + # 读取文件或字符串 + # question 可以是文件路径或直接的问题字符串 + question = read_file_or_string(args.question).strip() + # answer 和 rubric 必须是文件路径 answer = read_file(args.answer).strip() rubric_text = read_file(args.rubric).strip()