enonce_info.py
This commit is contained in:
+7
-18
@@ -1,5 +1,6 @@
|
||||
from pathlib import Path
|
||||
import io
|
||||
import utils
|
||||
|
||||
main_prompt = """I'm giving you an image of several written answers to an exam.
|
||||
|
||||
@@ -85,26 +86,14 @@ Here is a possible correct answer :
|
||||
You are asked to score the question or exercice labeled `<<label>>`,
|
||||
do not score or give feedback to any other question."""
|
||||
|
||||
from utils import get_label_text_content, get_label_sol_content, get_label_persp_content
|
||||
|
||||
def make_prompt(input_dir,full_label):
|
||||
def read_longest_prefix_file(subdir):
|
||||
dir_path = input_dir / subdir
|
||||
if not dir_path.exists():
|
||||
if subdir != "Persp":
|
||||
print("Warning !! Directory doesn't exist : ", dir_path)
|
||||
return ""
|
||||
matches = [f for f in dir_path.iterdir()
|
||||
if f.is_file()
|
||||
and full_label.startswith(f.name)
|
||||
and f.suffix not in [".pdf", ".tex"]]
|
||||
if not matches:
|
||||
return ""
|
||||
return max(matches, key=lambda f: len(f.name)).read_text(encoding="utf-8", errors="replace")
|
||||
text = get_label_text_content(input_dir, full_label)
|
||||
corr = get_label_sol_content(input_dir, full_label)
|
||||
persp = get_label_persp_content(input_dir, full_label)
|
||||
|
||||
text = read_longest_prefix_file("Text")
|
||||
corr = read_longest_prefix_file("Sol")
|
||||
persp = read_longest_prefix_file("Persp")
|
||||
|
||||
if persp != "":
|
||||
if persp and persp != "":
|
||||
persp = "\n\nHere are additional scoring instructions : \n\n```\n" + persp +"\n```\n"
|
||||
return main_prompt.replace("<<text>>", text).replace("<<corr>>", corr).replace("<<persp>>", persp).replace("<<label>>", full_label)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user