fix: allow --question to be a string instead of file path
This commit is contained in:
parent
5abb6a47e8
commit
9de97bddf1
@ -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()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user