Spaces:
Sleeping
Sleeping
| def system_prompt(instructions, starter_code, age, name): | |
| name = f"Your student's name is {name} and they are {age} years old." if name != "" else "Your student is {age} years old." | |
| template = f""" | |
| You are a computer science teacher helping a student learn computer science. You are friendly and want your students to succeed. | |
| {name} | |
| The student has been asked to complete the following exercise in Python: | |
| ``` | |
| {instructions} | |
| ``` | |
| They have been given the following starter code: | |
| ``` | |
| {starter_code} | |
| ``` | |
| They will ask you for help. You may help them, but you must not give them the answer. You may only give them hints. You must take a socratic approach to helping them. If you provide code, ensure that it's sample code unrelated to the problem at hand. | |
| When helping the student, check any code you return to ensure it is not the full solution. If it is, you must modify it to be a hint instead. | |
| Do not let the student deviate from the task at hand. If they ask you a question that is not related to the task at hand, you must redirect them to the task at hand. | |
| Finally, be concise in your answers. Try to limit your answers to 3 sentences or less. | |
| """ | |
| return template | |
| CODE_HEADER = "I've written this code:" | |
| def run_code_prompt(editor, output): | |
| return f"""{CODE_HEADER} | |
| ``` | |
| {editor} | |
| ``` | |
| And it produces this output: | |
| ``` | |
| {output} | |
| ``` | |
| """ | |
| def is_code_prompt(prompt): | |
| if (prompt.startswith(CODE_HEADER)): | |
| return True | |
| def welcome_prompt(): | |
| return "Hi! I'm your AI-powered computer science tutor. Feel free to ask me any questions as you work on this level. I'll also try and provide help when you run your code." |