Spaces:
Sleeping
Sleeping
Update question_handler.py
Browse files- question_handler.py +23 -0
question_handler.py
CHANGED
|
@@ -26,3 +26,26 @@ def generate_detailed_prompt(question_metadata):
|
|
| 26 |
f"\nPlease create a real-world interview question based on this information. "
|
| 27 |
f"Include sections for problem description, code template, sample input, and expected output."
|
| 28 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
f"\nPlease create a real-world interview question based on this information. "
|
| 27 |
f"Include sections for problem description, code template, sample input, and expected output."
|
| 28 |
)
|
| 29 |
+
def extract_code_and_test_case(response):
|
| 30 |
+
import re
|
| 31 |
+
|
| 32 |
+
code_template = ""
|
| 33 |
+
sample_test_case = ""
|
| 34 |
+
expected_output = ""
|
| 35 |
+
|
| 36 |
+
# Extract Python code block
|
| 37 |
+
code_match = re.search(r'```python(.*?)```', response, re.DOTALL)
|
| 38 |
+
if code_match:
|
| 39 |
+
code_template = code_match.group(1).strip()
|
| 40 |
+
|
| 41 |
+
# Extract test case and expected output
|
| 42 |
+
test_case_match = re.search(r'Sample Input:\s*(.*?)\n', response, re.DOTALL)
|
| 43 |
+
expected_output_match = re.search(r'Expected Output:\s*(.*?)\n', response, re.DOTALL)
|
| 44 |
+
|
| 45 |
+
if test_case_match:
|
| 46 |
+
sample_test_case = test_case_match.group(1).strip()
|
| 47 |
+
|
| 48 |
+
if expected_output_match:
|
| 49 |
+
expected_output = expected_output_match.group(1).strip()
|
| 50 |
+
|
| 51 |
+
return code_template, sample_test_case, expected_output
|