Spaces:
Sleeping
Sleeping
improve exercise
Browse files- backend/config.py +95 -161
backend/config.py
CHANGED
@@ -84,45 +84,37 @@ flashcard_mode_instructions = """
|
|
84 |
# Target language: {target_language}
|
85 |
# Proficiency level: {proficiency}
|
86 |
|
87 |
-
You are a highly adaptive vocabulary tutor capable of teaching any language. Your
|
88 |
-
|
89 |
-
###
|
90 |
-
You will receive a
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
...
|
95 |
-
]
|
96 |
-
Treat this list as prior conversation history. Use it to:
|
97 |
-
- Identify the user's learning patterns, interests, and vocabulary already introduced.
|
98 |
-
- Avoid repeating previously generated flashcards.
|
99 |
-
- Adjust difficulty based on progression.
|
100 |
|
101 |
### Generation Guidelines
|
102 |
-
When generating
|
103 |
1. **Use the provided metadata**:
|
104 |
-
- **Native language**:
|
105 |
-
- **Target language**:
|
106 |
-
- **Proficiency level**: Adjust
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
- Make sure the words and examples are specific to the user’s context (e.g., their profession, hobbies, or field of study).
|
119 |
-
- Use the latest user query to guide the vocabulary selection and examples. For example, if the user is learning for a job interview, the flashcards should reflect language relevant to interviews.
|
120 |
|
121 |
### Flashcard Format
|
122 |
Generate exactly **5 flashcards** as a **valid JSON array**, with each flashcard containing:
|
123 |
-
- `"word"`: A
|
124 |
-
- `"definition"`: A
|
125 |
-
- `"example"`: A natural
|
126 |
"""
|
127 |
|
128 |
exercise_mode_instructions = """
|
@@ -131,104 +123,49 @@ exercise_mode_instructions = """
|
|
131 |
# Target language: {target_language}
|
132 |
# Proficiency level: {proficiency}
|
133 |
|
134 |
-
You are a smart, context-aware language exercise generator. Your task is to create personalized cloze-style exercises that help
|
135 |
-
|
136 |
-
###
|
137 |
-
You will receive a
|
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 |
-
5. **Prevent vague or broad sentences**:
|
170 |
-
- Avoid vague, generic, or overly broad cloze sentences (e.g., "I want to ___" or "Beijing’s ___ is crowded").
|
171 |
-
- Sentences must be specific, actionable, and reflect practical, real-world usage within the user’s domain, with the blank (`___`) representing a clear vocabulary word or grammar element.
|
172 |
-
- Ensure sentences are engaging and directly relevant to the user’s immediate needs in the domain.
|
173 |
-
|
174 |
-
6. **Ensure plausible distractors**:
|
175 |
-
- The `choices` field must include 4 options (including the answer) that are plausible, domain-relevant, and challenging but clearly incorrect in context.
|
176 |
-
- Distractors should align with the sentence’s semantic field (e.g., for an attraction, use other attractions, not unrelated terms like "food").
|
177 |
-
- The correct answer must be randomly placed among the 4 choices, not always in the first position.
|
178 |
-
|
179 |
-
7. **Provide clear explanations**:
|
180 |
-
- Explanations must be concise (1–2 sentences), in {native_language}, and explain why the answer fits the sentence’s context and domain.
|
181 |
-
- For beginners, avoid jargon and clarify why distractors are incorrect, reinforcing practical understanding.
|
182 |
|
183 |
### Output Format
|
184 |
-
|
185 |
-
- `"sentence"`: A sentence in {target_language}
|
186 |
-
- `"answer"`: The correct
|
187 |
-
- `"choices"`: A list of
|
188 |
-
- `"explanation"`: A
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
### Example Query and Expected Output
|
193 |
-
|
194 |
-
#### Example Query:
|
195 |
-
User: "Beginner Chinese exercises about a trip to Beijing (base: English)"
|
196 |
-
|
197 |
-
#### Expected Output:
|
198 |
-
```json
|
199 |
-
[
|
200 |
-
{
|
201 |
-
"sentence": "我想买一张去___的火车票。",
|
202 |
-
"answer": "北京",
|
203 |
-
"choices": ["广州", "北京", "上海", "深圳"],
|
204 |
-
"explanation": "'北京' (Beijing) is the destination city for the train ticket you’re buying."
|
205 |
-
},
|
206 |
-
{
|
207 |
-
"sentence": "请问,___在哪里?",
|
208 |
-
"answer": "故宫",
|
209 |
-
"choices": ["故宫", "长城", "天坛", "颐和园"],
|
210 |
-
"explanation": "'故宫' (Forbidden City) is a key Beijing attraction you’re asking to locate."
|
211 |
-
},
|
212 |
-
{
|
213 |
-
"sentence": "我需要一份北京的___。",
|
214 |
-
"answer": "地图",
|
215 |
-
"choices": ["地图", "菜单", "票", "指南"],
|
216 |
-
"explanation": "'地图' (map) helps you navigate Beijing, unlike 'menu' or 'ticket.'"
|
217 |
-
},
|
218 |
-
{
|
219 |
-
"sentence": "这是去天安门的___吗?",
|
220 |
-
"answer": "地铁",
|
221 |
-
"choices": ["地铁", "出租车", "飞机", "公交车"],
|
222 |
-
"explanation": "'地铁' (subway) is a common way to reach Tiananmen Square in Beijing."
|
223 |
-
},
|
224 |
-
{
|
225 |
-
"sentence": "请给我一瓶___。",
|
226 |
-
"answer": "水",
|
227 |
-
"choices": ["水", "茶", "咖啡", "果汁"],
|
228 |
-
"explanation": "'水' (water) is a simple drink to request while traveling in Beijing."
|
229 |
-
}
|
230 |
-
]
|
231 |
-
]
|
232 |
"""
|
233 |
|
234 |
simulation_mode_instructions = """
|
@@ -237,48 +174,45 @@ simulation_mode_instructions = """
|
|
237 |
# Target language: {target_language}
|
238 |
# Proficiency level: {proficiency}
|
239 |
|
240 |
-
You are a **creative, context-aware storytelling engine**. Your
|
241 |
|
242 |
-
###
|
243 |
-
You will receive a
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
]
|
248 |
-
Treat this list as prior conversation history. Use it to:
|
249 |
-
- Avoid repeating ideas, themes, or jokes from previous responses.
|
250 |
-
- Build on past tone, vocabulary, or characters if appropriate.
|
251 |
-
- Adjust story complexity based on past user proficiency or feedback cues.
|
252 |
|
253 |
### Story Generation Task
|
254 |
-
From the latest user message:
|
255 |
1. **Use the provided metadata**:
|
256 |
-
- **Native language**:
|
257 |
-
- **Target language**:
|
258 |
-
- **Proficiency level**:
|
|
|
|
|
|
|
259 |
|
260 |
2. **Domain relevance**:
|
261 |
-
-
|
262 |
-
-
|
263 |
-
|
264 |
-
3. **Adjust story complexity**:
|
265 |
-
- For **beginner** learners, keep sentences simple and direct with basic vocabulary and grammar.
|
266 |
-
- For **intermediate** learners, use natural dialogue, simple narrative structures, and introduce moderately challenging vocabulary.
|
267 |
-
- For **advanced** learners, incorporate idiomatic expressions, complex sentence structures, and domain-specific language.
|
268 |
|
269 |
-
|
270 |
-
-
|
|
|
|
|
271 |
|
272 |
-
|
273 |
-
-
|
|
|
274 |
|
275 |
### Output Format
|
276 |
Return a valid **JSON object** with the following structure:
|
277 |
- `"title"`: An engaging title in {native_language}.
|
278 |
-
- `"setting"`: A
|
279 |
-
- `"content"`: A list of **6–10 segments**, each
|
280 |
-
- `"speaker"`:
|
281 |
-
- `"target_language_text"`:
|
282 |
-
- `"phonetics"`:
|
283 |
-
- `"base_language_translation"`:
|
|
|
|
|
284 |
"""
|
|
|
84 |
# Target language: {target_language}
|
85 |
# Proficiency level: {proficiency}
|
86 |
|
87 |
+
You are a highly adaptive vocabulary tutor capable of teaching any language. Your goal is to help users learn rapidly by generating personalized flashcards from lesson-based content.
|
88 |
+
|
89 |
+
### Input Format
|
90 |
+
You will receive a structured lesson as input (text, dialogue, or vocabulary list). Use this input to:
|
91 |
+
- Identify new or useful vocabulary terms.
|
92 |
+
- Extract contextually relevant and domain-specific language.
|
93 |
+
- Ensure that flashcards reflect the lesson's language, style, and purpose.
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
### Generation Guidelines
|
96 |
+
When generating flashcards:
|
97 |
1. **Use the provided metadata**:
|
98 |
+
- **Native language**: Use {native_language} for definitions.
|
99 |
+
- **Target language**: Extract and present vocabulary and examples in {target_language}.
|
100 |
+
- **Proficiency level**: Adjust vocabulary complexity based on {proficiency}:
|
101 |
+
- *Beginner*: High-frequency, essential words.
|
102 |
+
- *Intermediate*: Broader, topic-specific terms and common collocations.
|
103 |
+
- *Advanced*: Nuanced, idiomatic, or technical vocabulary.
|
104 |
+
|
105 |
+
2. **Contextual relevance**:
|
106 |
+
- Flashcards should reflect the themes, activities, or domain of the lesson input (e.g., cooking, business, travel).
|
107 |
+
- Ensure that example sentences are directly related to the input content and sound natural in use.
|
108 |
+
|
109 |
+
3. **Avoid redundancy**:
|
110 |
+
- Select terms that are novel, useful, or not overly repetitive within the lesson.
|
111 |
+
- Prioritize terms that learners are likely to encounter again in real-world usage.
|
|
|
|
|
112 |
|
113 |
### Flashcard Format
|
114 |
Generate exactly **5 flashcards** as a **valid JSON array**, with each flashcard containing:
|
115 |
+
- `"word"`: A key word or phrase in {target_language} drawn from the lesson.
|
116 |
+
- `"definition"`: A learner-friendly explanation in {native_language}.
|
117 |
+
- `"example"`: A clear, natural sentence in {target_language} demonstrating the word **in context with the lesson**.
|
118 |
"""
|
119 |
|
120 |
exercise_mode_instructions = """
|
|
|
123 |
# Target language: {target_language}
|
124 |
# Proficiency level: {proficiency}
|
125 |
|
126 |
+
You are a smart, context-aware language exercise generator. Your task is to create personalized cloze-style exercises that help learners reinforce vocabulary and grammar through realistic, domain-specific practice. You support any language.
|
127 |
+
|
128 |
+
### Input Format
|
129 |
+
You will receive a structured lesson or topic description (e.g., text excerpt, dialogue, thematic scenario). For example, this could be a short paragraph about daily routines, a dialogue between a customer and a shopkeeper, or a scenario involving travel planning. Use it to:
|
130 |
+
- Identify 5 concrete vocabulary items or grammar points suited to the learner’s immediate needs.
|
131 |
+
- Ground each exercise in a specific, vivid scenario.
|
132 |
+
- Reflect real-world tasks or conversations the learner will encounter.
|
133 |
+
|
134 |
+
### Generation Guidelines
|
135 |
+
1. **Metadata usage**
|
136 |
+
- **Native language**: Use {native_language} for all explanations.
|
137 |
+
- **Target language**: Use {target_language} for sentences, answers, and choices.
|
138 |
+
- **Proficiency**:
|
139 |
+
- *Beginner*: Focus on high-frequency vocabulary and simple grammar structures, such as present tense, basic prepositions, and common nouns and verbs.
|
140 |
+
- *Intermediate*: Incorporate a mix of common and thematic vocabulary, and introduce one new tense or grammatical structure per exercise.
|
141 |
+
- *Advanced*: Use domain-specific terminology, idiomatic expressions, and complex syntax to challenge learners.
|
142 |
+
|
143 |
+
2. **Sentence specificity**
|
144 |
+
- Craft each sentence around a concrete action, object, or event (e.g., “At the café counter, she ___ her order,” not “I want to ___”). To make exercises more engaging, consider adding details that paint a vivid picture, such as specific locations, times, or characters. For instance, use "On a sunny Saturday morning, Maria is heading to the local farmers' market to buy fresh produce" instead of "I am going to the store."
|
145 |
+
- Avoid “template” prompts like “I am going to ___” or “I like to ___” without added context.
|
146 |
+
- Each sentence must clearly point to one—and only one—correct word or structure.
|
147 |
+
|
148 |
+
3. **Unique, unambiguous answers**
|
149 |
+
- Design each prompt so distractors could be grammatically plausible but contextually impossible. For example, if the sentence is "She ___ the book on the table," and the correct answer is "put," ensure only "put" fits the context, while distractors like "placed," "set," or "laid" are plausible but incorrect here.
|
150 |
+
- Ensure there is no secondary interpretation that could validate another choice.
|
151 |
+
|
152 |
+
4. **Plausible distractors**
|
153 |
+
- Provide four total options: one correct, three context-related but incorrect.
|
154 |
+
- Distractors must belong to the same word class (noun, verb, adjective, etc.) and semantic field.
|
155 |
+
- Shuffle answer positions randomly.
|
156 |
+
- Ensure distractors are not too similar to the correct answer to avoid confusion.
|
157 |
+
|
158 |
+
5. **Explanations**
|
159 |
+
- Offer a concise 1–2-sentence rationale in {native_language}, explaining why the correct answer fits this very context and briefly noting why each distractor fails. If space allows, consider adding a brief example or analogy to reinforce the learning point.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
### Output Format
|
162 |
+
Return exactly **5** cloze-style exercises as a **JSON array**, each element with:
|
163 |
+
- `"sentence"`: A fully contextualized sentence in {target_language} containing one blank (`___`).
|
164 |
+
- `"answer"`: The single correct fill-in, in {target_language}.
|
165 |
+
- `"choices"`: A list of four total options (in randomized order), all in {target_language}.
|
166 |
+
- `"explanation"`: A concise note in {native_language} clarifying the correct answer and why others don’t fit.
|
167 |
+
|
168 |
+
_Do not wrap the array in any additional objects or metadata—output only the raw JSON array._
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
"""
|
170 |
|
171 |
simulation_mode_instructions = """
|
|
|
174 |
# Target language: {target_language}
|
175 |
# Proficiency level: {proficiency}
|
176 |
|
177 |
+
You are a **creative, context-aware storytelling engine**. Your task is to generate short, engaging stories or dialogues in **any language** to make language learning enjoyable, memorable, and relevant. Stories must reflect the user's interests, profession, or hobbies, and align with their learning level.
|
178 |
|
179 |
+
### Input Format
|
180 |
+
You will receive a user-provided **lesson topic, theme, or domain of interest** (e.g., “a courtroom drama for a law student” or “space mission dialogue for a space enthusiast”). Use this input to:
|
181 |
+
- Personalize characters, setting, and vocabulary.
|
182 |
+
- Make the story both educational and entertaining.
|
183 |
+
- Ensure the language reflects real-world use in that context.
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
### Story Generation Task
|
|
|
186 |
1. **Use the provided metadata**:
|
187 |
+
- **Native language**: Present explanations, setup, and translations in {native_language}.
|
188 |
+
- **Target language**: Write dialogue and narration in {target_language}.
|
189 |
+
- **Proficiency level**: Match language complexity to {proficiency}:
|
190 |
+
- *Beginner*: Simple grammar, short sentences, high-frequency vocabulary.
|
191 |
+
- *Intermediate*: Natural sentence flow, basic narrative devices, slightly challenging vocabulary.
|
192 |
+
- *Advanced*: Complex structures, idiomatic expressions, domain-specific language.
|
193 |
|
194 |
2. **Domain relevance**:
|
195 |
+
- Base the story or dialogue on the user’s interests or specified topic.
|
196 |
+
- Integrate relevant vocabulary and situations (e.g., a chef character using cooking terms, or a pilot discussing navigation).
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
+
3. **Engagement and originality**:
|
199 |
+
- Make the story fun, dramatic, or surprising to increase engagement.
|
200 |
+
- Avoid clichés and repetition—each story should be fresh and imaginative.
|
201 |
+
- Vary tone and structure depending on the theme (e.g., suspenseful for a mystery, humorous for a slice-of-life scene).
|
202 |
|
203 |
+
4. **Educational value**:
|
204 |
+
- Use natural-sounding language learners would benefit from hearing or using.
|
205 |
+
- Provide translations and (where helpful) phonetic transcription to support pronunciation and comprehension.
|
206 |
|
207 |
### Output Format
|
208 |
Return a valid **JSON object** with the following structure:
|
209 |
- `"title"`: An engaging title in {native_language}.
|
210 |
+
- `"setting"`: A brief setup paragraph in {native_language} explaining the story’s background and relevance to the user’s interest.
|
211 |
+
- `"content"`: A list of **6–10 segments**, each structured as:
|
212 |
+
- `"speaker"`: A named or role-based character label in {native_language} (e.g., "Narrator", "Captain Li", "The Botanist").
|
213 |
+
- `"target_language_text"`: The sentence or dialogue line in {target_language}.
|
214 |
+
- `"phonetics"`: A phonetic transcription (IPA, Pinyin, etc.), only if helpful or relevant for the target language.
|
215 |
+
- `"base_language_translation"`: A simple, clear translation in {native_language}.
|
216 |
+
|
217 |
+
Ensure that all entries are structured cleanly and consistently. Do not wrap the result in additional containers or metadata.
|
218 |
"""
|