Spaces:
Sleeping
Sleeping
File size: 10,134 Bytes
6c8a2d5 |
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
import os
import argparse
import sys
from backend.CurriculumManager.generate_curriculum import get_completion as generate_curriculum
from backend.LessonManager.generate_lesson import get_completion as generate_lesson
from backend.LessonManager.generate_daily_lesson import get_completion as generate_daily_lesson
from backend.config_manager import Config
from backend.utils import read_json_file, ensure_directory
# Set up paths
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CONFIG_PATH = os.path.join(PROJECT_ROOT, "backend", "config.json")
OUTPUT_DIR = os.path.join(PROJECT_ROOT, "output")
CURRICULUM_PATH = os.path.join(OUTPUT_DIR, "curriculum.json")
LESSON_PATH = os.path.join(OUTPUT_DIR, "lesson.json")
# Ensure output directory exists
ensure_directory(OUTPUT_DIR)
config = Config(CONFIG_PATH)
def parse_args():
parser = argparse.ArgumentParser(description='AI Language Tutor')
parser.add_argument('--mode', choices=['curriculum', 'lesson', 'daily'], required=True,
help='Mode of operation: curriculum, weekly lesson, or daily micro-lessons')
parser.add_argument('--prompt', type=str, required='curriculum' in sys.argv,
help='User prompt for curriculum generation (required for curriculum mode)')
parser.add_argument('--week', type=int, default=0, help='Week number (0-based index)')
parser.add_argument('--day', type=int, default=0, help='Day number (0-based index)')
return parser.parse_args()
def setup_lesson_instruction(args):
"""Setup lesson instruction from curriculum data using specified week."""
curriculum_data = read_json_file(CURRICULUM_PATH)
if curriculum_data is None:
raise FileNotFoundError("Curriculum not found. Please generate curriculum first.")
if args.week >= len(curriculum_data["weeks"]):
raise ValueError(f"Week {args.week} not found. Available weeks: 0-{len(curriculum_data['weeks'])-1}")
language = curriculum_data["language"]
learning_goal = curriculum_data["learning_goal"]
current_level = curriculum_data["current_level"]
week = curriculum_data["weeks"][args.week]
lesson_instruction = """
You are an advanced AI language tutor specializing in personalized language instruction. Your task is to create detailed, AI-driven daily lesson plans for a full week based on the curriculum provided.
Student Profile:
- Target Language: {language}
- Learning Goal: {learning_goal}
- Current Level: {current_level}
Instructions:
1. Create engaging, AI-driven activities for each day of the week (7 days)
2. Focus on interactive, personalized learning experiences
3. Avoid suggesting external resources or tools
4. Ensure activities align with the week's theme and learning objectives
5. Include specific examples and practice scenarios for each day
6. Format your response as a valid JSON object
Output Format:
{{
"week": number,
"theme": "string",
"estimated_duration": "string",
"daily_lessons": [
{{
"day": number,
"focus": "string",
"duration": "string",
"activities": [
{{
"type": "string",
"description": "string"
}}
]
}},
// Repeat for all 7 days
]
}}
Notes:
- Create lessons for all 7 days of the week
- Each day should have a specific focus while maintaining the week's theme
- Weekend lessons (days 6-7) can be lighter but should maintain learning momentum
- All activities should be completable through AI interaction
""".format(
language=language,
learning_goal=learning_goal,
current_level=current_level
)
lesson_prompt = """
Based on the curriculum week {week_num}:
{curriculum}
Generate a detailed, AI-driven lesson plan following the instruction format.
""".format(week_num=args.week + 1, curriculum=week)
config.set("target_language", language)
config.set("lesson_instruction", lesson_instruction)
config.set("lesson_prompt", lesson_prompt)
# Return the generated lesson directly instead of True
return generate_lesson(lesson_prompt)
def setup_daily_lesson(args):
"""Setup and generate daily lesson using specified day"""
lesson_data = read_json_file(LESSON_PATH)
theme = lesson_data["theme"]
lessons = lesson_data["daily_lessons"]
if args.day >= len(lessons):
raise ValueError(f"Day {args.day} not found in lesson plan. Available days: 0-{len(lessons)-1}")
daily_lesson_instruction = """
You are an AI assistant tasked with curating today's lesson to help the user improve their skills in the target language.
Instructions:
1. Determine the target language based on the user's input.
2. Create a bilingual lesson (English and the target language) to enable the user to achieve their learning goal.
3. For vocabulary sections:
- Provide terms in English, their translations in the target language, and example sentences in both languages.
- For character-based languages (e.g., Chinese, Japanese, Korean, Arabic), include phonetic aids alongside the target language:
- Chinese: Include Pinyin for Mandarin terms.
- Japanese: Include Romaji for Japanese terms.
- Korean: Include Romanized Korean (Revised Romanization).
- Arabic: Include transliteration using the Latin alphabet.
- Example format:
- Term: "prototype"
- Translation: "原型" (Chinese), Pinyin: "yuánxíng"
- Example Sentence:
- English: "We've developed a prototype for the new app."
- Target Language: "我们为新应用开发了一个原型。" (Chinese), Pinyin: "Wǒmen wèi xīn yìngyòng kāifāle yígè yuánxíng."
4. For practice activities:
- Include prompts in both English and the target language.
- Provide example responses in both languages, including phonetic aids for character-based languages.
5. Provide feedback on the user's input, focusing on grammar, vocabulary, and fluency. If applicable, include corrections with phonetic aids.
6. Always remember to include both English and the target language for all cases, along with phonetic aids for character-based languages.
The lesson should be engaging, interactive, and tailored to the user's proficiency level.
"""
lesson_prompt = """
Theme: {theme}
Based on today's lesson plan, create a bilingual lesson (English and {target_language}) with the following structure:
Lesson Plan: {lesson_plan}
""".format(
theme=theme,
target_language=config.get("target_language"),
lesson_plan=lessons[args.day]
)
config.set("daily_lesson_instruction", daily_lesson_instruction)
config.set("daily_lesson_prompt", lesson_prompt)
return generate_daily_lesson(lesson_prompt)
def main():
args = parse_args()
if args.mode == 'curriculum':
if not args.prompt:
raise ValueError("--prompt is required for curriculum mode")
generate_curriculum(args.prompt)
elif args.mode == 'lesson':
setup_lesson_instruction(args) # Remove separate generate_lesson call
elif args.mode == 'daily':
setup_daily_lesson(args) # Already generates lesson using internal prompt
if __name__ == "__main__":
main()
# curriculum_data = read_json_file(CURRICULUM_PATH)
# if curriculum_data is None:
# raise FileNotFoundError("Curriculum not found. Please generate curriculum first.")
# if args.week >= len(curriculum_data["weeks"]):
# raise ValueError(f"Week {args.week} not found. Available weeks: 0-{len(curriculum_data['weeks'])-1}")
# language = curriculum_data["language"]
# learning_goal = curriculum_data["learning_goal"]
# current_level = curriculum_data["current_level"]
# week = curriculum_data["weeks"][args.week]
# lesson_instruction = """
# You are an advanced AI language tutor specializing in personalized language instruction. Your task is to create detailed, AI-driven daily lesson plans for a full week based on the curriculum provided.
# Student Profile:
# - Target Language: {language}
# - Learning Goal: {learning_goal}
# - Current Level: {current_level}
# Instructions:
# 1. Create engaging, AI-driven activities for each day of the week (7 days)
# 2. Focus on interactive, personalized learning experiences
# 3. Avoid suggesting external resources or tools
# 4. Ensure activities align with the week's theme and learning objectives
# 5. Include specific examples and practice scenarios for each day
# 6. Format your response as a valid JSON object
# Output Format:
# {{
# "week": number,
# "theme": "string",
# "estimated_duration": "string",
# "daily_lessons": [
# {{
# "day": number,
# "focus": "string",
# "duration": "string",
# "activities": [
# {{
# "type": "string",
# "description": "string"
# }}
# ]
# }},
# // Repeat for all 7 days
# ]
# }}
# Notes:
# - Create lessons for all 7 days of the week
# - Each day should have a specific focus while maintaining the week's theme
# - Weekend lessons (days 6-7) can be lighter but should maintain learning momentum
# - All activities should be completable through AI interaction
# """.format(
# language=language,
# learning_goal=learning_goal,
# current_level=current_level
# )
# lesson_prompt = """
# Based on the curriculum week {week_num}:
# {curriculum}
# Generate a detailed, AI-driven lesson plan following the instruction format.
# """.format(week_num=args.week + 1, curriculum=week)
# config.set("target_language", language)
# config.set("lesson_instruction", lesson_instruction)
# config.set("lesson_prompt", lesson_prompt)
# # Return the generated lesson directly instead of True
# generate_lesson(lesson_prompt) |