File size: 1,977 Bytes
95a008c |
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 37 38 39 40 41 42 43 44 |
from .utils import format_prompt_for_hint, format_prompt_for_followup
from .model_handler import generate_hint, generate_follow_up, generate_feedback # Add generate_feedback
import re # Import regex module
def clean_task_description(description: str) -> str:
"""Removes common example, constraint, input/output format sections by finding the first occurrence."""
lines = description.splitlines()
cleaned_lines = []
skip_keywords = ["Example:", "Input:", "Output:", "Constraints:", "Input Format:", "Output Format:", "Explanation:"]
first_skip_index = -1
# Find the index of the first line starting with a skip keyword
for i, line in enumerate(lines):
line_stripped_lower = line.strip().lower()
if any(line_stripped_lower.startswith(keyword.lower()) for keyword in skip_keywords):
first_skip_index = i
break # Stop at the first occurrence
# If a skip keyword was found, take lines before it
if first_skip_index != -1:
cleaned_lines = lines[:first_skip_index]
# Otherwise, keep all lines (no skip keywords found)
else:
cleaned_lines = lines
# Join back the relevant lines and strip whitespace
return "\n".join(cleaned_lines).strip()
def get_hint(code, task_description, mode='concise'): # Add mode
cleaned_description = clean_task_description(task_description)
# Pass mode to generate_hint
return generate_hint(code, cleaned_description, mode)
def get_feedback(code, task_description, mode='concise'): # New function
cleaned_description = clean_task_description(task_description)
# Call generate_feedback with mode
return generate_feedback(code, cleaned_description, mode)
def get_follow_up_question(code, task_description):
cleaned_description = clean_task_description(task_description)
# Pass code to generate_follow_up (already updated in model_handler)
return generate_follow_up(cleaned_description, code) # Pass both args
|