Anupriya commited on
Commit
34771bf
·
1 Parent(s): c46cf2c

Generate Question

Browse files
Files changed (2) hide show
  1. generateQuestion.py +44 -101
  2. writting.py +29 -6
generateQuestion.py CHANGED
@@ -63,20 +63,27 @@ COHERE_API_URL = 'https://api.cohere.ai/v1/generate'
63
  def validate_topic(topic):
64
 
65
  validation_prompt = f"""
66
- You are an AI grammar expert. Your task is to determine if a given topic is related to **English grammar** or not.
67
-
68
- **Input:** "{topic}"
69
-
70
- ### **Rules:**
71
- - If the input is **in the form of a question** (e.g., it asks for an explanation or definition), return `"ask grammar topics"`, even if the topic is related to grammar.
72
- - If the topic is **related to English grammar concepts** such as **parts of speech**, **verb tenses**, **sentence structure**, etc., return `"Grammar"`.
73
- - If the topic is **not related to grammar**, such as general knowledge, science, math, history, or topics from other fields, return `"Not Grammar"`.
74
- - Your response must be based purely on whether the topic relates to grammar, and **not** based on specific words, phrases, or examples.
75
-
76
- **Your response must be exactly either "Grammar", "Not Grammar", or "ask grammar topics". No extra text.**
 
 
 
 
 
 
77
  """
78
 
79
 
 
80
 
81
 
82
 
@@ -135,48 +142,14 @@ def generate_questions_test():
135
  Generate five **completely new and unique** very basic-level fill-in-the-blank grammar questions **every time** on the topic '{topic}'.
136
 
137
  ### Rules:
138
- - **Each question must have a different theme**, ensuring variety.
139
- - **Do not repeat** themes from previous generations.
140
- - Use **different sentence structures**, avoiding predictable patterns.
141
- - **Avoid long words or abstract concepts**
142
- - **Focus on the topic '{topic}'**, and ensure the blank is the key part of speech.
143
- - Each question should contain **one blank represented by '_______'**, with the correct answer provided in parentheses at the end.
144
- - The vocabulary should be **simple and suitable for beginners**.
145
- - Ensure that the questions are **always new and distinct**, avoiding previously used themes.
146
-
147
- Do not include any explanations or instructions in the response—only the five unique questions.
148
- """
149
-
150
- elif difficulty == 'elementary':
151
- prompt = f"""
152
- Generate five **completely new and unique** elementary-level fill-in-the-blank grammar questions **every time** on the topic '{topic}'.
153
-
154
- ### Rules:
155
- - The questions should be **slightly more challenging than basic-level questions**, incorporating **a wider range of sentence structures and vocabulary**.
156
- - **Each question must have a different theme**, ensuring variety.
157
- - **Use varied sentence structures**, making them slightly more complex than basic-level questions.
158
- - **Ensure that the vocabulary is still simple but slightly broader** than basic-level questions.
159
- - **Focus on the topic '{topic}'**, and ensure the blank is the key part of speech.
160
- - Each question should contain **one blank represented by '_______'**, with the correct answer provided in parentheses at the end.
161
- - Ensure that the questions are **always new and distinct**, avoiding previously used themes.
162
-
163
- Do not include any explanations or instructions in the response—only the five unique questions.
164
- """
165
-
166
- elif difficulty == 'pre-intermediate':
167
- prompt = f"""
168
- Generate five **completely new and unique** pre-intermediate-level fill-in-the-blank grammar questions **every time** on the topic '{topic}'.
169
-
170
- ### Rules:
171
- - The questions should be **more challenging than elementary-level questions**, incorporating **more varied sentence structures and an expanded vocabulary**.
172
- - **Each question must have a different theme**, ensuring variety.
173
- - **Ensure that the vocabulary is broader than elementary-level**, while keeping it understandable for learners.
174
- - **Sentences should be longer and more descriptive** but still clear.
175
- - **Focus on the topic '{topic}'**, and ensure the blank is the key part of speech.
176
- - Each question should contain **one blank represented by '_______'**, with the correct answer provided in parentheses at the end.
177
- - Ensure that the questions are **always new and distinct**, avoiding previously used themes.
178
-
179
- Do not include any explanations or instructions in the response—only the five unique questions.
180
  """
181
 
182
  elif difficulty == 'intermediate':
@@ -184,62 +157,32 @@ def generate_questions_test():
184
  Generate five **completely new and unique** intermediate-level fill-in-the-blank grammar questions **every time** on the topic '{topic}'.
185
 
186
  ### Rules:
187
- - The questions should be **more complex than pre-intermediate-level questions**, incorporating **a wider range of vocabulary and sentence structures**.
188
- - **Each question must have a different theme**, ensuring variety.
189
- - **Ensure that the vocabulary is more advanced than pre-intermediate-level** while keeping it natural for learners.
190
- - **Sentences should be longer and include more detail**, improving reading comprehension.
191
- - **Focus on the topic '{topic}'**, and ensure the blank is the key part of speech.
192
- - Each question should contain **one blank represented by '_______'**, with the correct answer provided in parentheses at the end.
193
- - Ensure that the questions are **always new and distinct**, avoiding previously used themes.
194
-
195
- Do not include any explanations or instructions in the response—only the five unique questions.
196
- """
197
-
198
- elif difficulty == 'upper-intermediate':
199
- prompt = f"""
200
- Generate five **completely new and unique** upper-intermediate-level fill-in-the-blank grammar questions **every time** on the topic '{topic}'.
201
-
202
- ### Rules:
203
- - The questions should be **more complex than intermediate-level questions**, incorporating **more advanced sentence structures and vocabulary**.
204
- - **Each question must have a different theme**, ensuring variety.
205
- - **Ensure that the vocabulary is more refined and diverse** but still understandable for upper-intermediate learners.
206
- - **Sentences should be longer and may introduce more nuanced contexts**, requiring a deeper understanding.
207
- - **Focus on the topic '{topic}'**, and ensure the blank is the key part of speech.
208
- - Each question should contain **one blank represented by '_______'**, with the correct answer provided in parentheses at the end.
209
- - Ensure that the questions are **always new and distinct**, avoiding previously used themes.
210
-
211
- Do not include any explanations or instructions in the response—only the five unique questions.
212
  """
213
 
214
- elif difficulty == 'advanced':
215
  prompt = f"""
216
  Generate five **completely new and unique** advanced-level (C1) fill-in-the-blank grammar questions **every time** on the topic '{topic}'.
217
 
218
  ### Rules:
219
- - The questions should be **more challenging than upper-intermediate (B2) level**, requiring a deep understanding of grammar, context, and vocabulary.
220
- - **Ensure varied and sophisticated vocabulary**, avoiding basic words.
221
- - **Each question should require nuanced comprehension**, testing knowledge of advanced grammar patterns.
222
- - **The blank must be the key part of the sentence** (not an obvious answer).
223
- - Each question should contain **one blank represented by '_______'**, with the correct answer provided in parentheses at the end.
224
- - Ensure that the questions are **always new and distinct**, avoiding repetition of themes.
225
-
226
- Do not include any explanations or instructions in the response—only the five unique questions.
227
  """
228
 
229
- elif difficulty == 'hard':
230
- prompt = f"""
231
- Generate five **completely new and unique** hard-level (C2) fill-in-the-blank grammar questions **every time** on the topic '{topic}'.
232
-
233
- ### Rules:
234
- - The questions should be **more challenging than advanced(C1) level**, requiring a deep understanding of grammar, context, and vocabulary.
235
- - **Ensure varied and sophisticated vocabulary**, avoiding basic words.
236
- - **Each question should require nuanced comprehension**, testing knowledge of advanced grammar patterns.
237
- - **The blank must be the key part of the sentence** (not an obvious answer).
238
- - Each question should contain **one blank represented by '_______'**, with the correct answer provided in parentheses at the end.
239
- - Ensure that the questions are **always new and distinct**, avoiding repetition of themes.
240
-
241
- Do not include any explanations or instructions in the response—only the five unique questions.
242
- """
243
 
244
  else:
245
  return jsonify({"error": "Invalid difficulty level"}), 400
 
63
  def validate_topic(topic):
64
 
65
  validation_prompt = f"""
66
+ ou are a highly knowledgeable AI grammar expert. Your task is to evaluate whether the given topic relates to **English grammar** or not.
67
+
68
+ **Input Topic:** "{topic}"
69
+
70
+ ### **Instructions:**
71
+ - If the input **exactly refers to** grammar concepts (such as **parts of speech**, **verb tenses**, **sentence structure**, **grammar rules**, etc.), respond with `"Grammar"`.
72
+ - If the input **seems to be a general question or concept** that is **not directly related to grammar**, such as general knowledge, science, history, or unrelated fields, respond with `"Not Grammar"`.
73
+ - If the input is in the form of a **question** (e.g., "What is subject-verb agreement?"), respond with `"ask grammar topics"`.
74
+ - If the topic refers to a **specific grammar concept** (e.g., **noun**, **verb**, **preposition**, **past tense**, etc.), always classify it as `"Grammar"`.
75
+ - **Do not include any explanations or examples**. Your answer must only be `"Grammar"`, `"Not Grammar"`, or `"ask grammar topics"`, depending on whether the topic is relevant to grammar.
76
+ - If the input is **unclear**, err on the side of classifying it as `"Not Grammar"` rather than `"Grammar"`.
77
+
78
+ Your response must only be one of these three options:
79
+ - `"Grammar"`
80
+ - `"Not Grammar"`
81
+ - `"ask grammar topics"`
82
+ No extra text or explanation.
83
  """
84
 
85
 
86
+
87
 
88
 
89
 
 
142
  Generate five **completely new and unique** very basic-level fill-in-the-blank grammar questions **every time** on the topic '{topic}'.
143
 
144
  ### Rules:
145
+ - Generate five unique fill-in-the-blank grammar questions based on the topic '{topic}'.
146
+ - Each question must have exactly one blank represented by '_______' (not two blanks or underscores inside the sentence).
147
+ - Each question must have a different theme for variety.
148
+ - Use different sentence structures; avoid predictable patterns.
149
+ - Avoid long words or abstract concepts.
150
+ - Focus on the topic '{topic}', and ensure the blank is the key part of speech.
151
+ - Each question must include the correct answer in parentheses at the end.
152
+ - Do not include any explanations or instructions—only the five questions.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  """
154
 
155
  elif difficulty == 'intermediate':
 
157
  Generate five **completely new and unique** intermediate-level fill-in-the-blank grammar questions **every time** on the topic '{topic}'.
158
 
159
  ### Rules:
160
+ - Generate five unique fill-in-the-blank grammar questions based on the topic '{topic}'.
161
+ - Each question must have exactly one blank represented by '_______'.
162
+ - Slightly more challenging than basic-level; use a wider range of sentence structures and vocabulary.
163
+ - Each question must have a different theme.
164
+ - Sentences should be longer and include more detail.
165
+ - Focus on the topic '{topic}', and ensure the blank is the key part of speech.
166
+ - Each question must include the correct answer in parentheses at the end.
167
+ - Do not include any explanations or instructions—only the five questions.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  """
169
 
170
+ elif difficulty == 'expert':
171
  prompt = f"""
172
  Generate five **completely new and unique** advanced-level (C1) fill-in-the-blank grammar questions **every time** on the topic '{topic}'.
173
 
174
  ### Rules:
175
+ - Generate five unique fill-in-the-blank grammar questions based on the topic '{topic}'.
176
+ - Each question must have exactly one blank represented by '_______'.
177
+ - More challenging than intermediate (C1); require expert-level mastery of grammar and context.
178
+ - Ensure varied and sophisticated vocabulary; avoid basic words.
179
+ - Each question should require nuanced comprehension; test advanced grammar patterns.
180
+ - The blank must be the key part of the sentence (not an obvious answer).
181
+ - Each question must include the correct answer in parentheses at the end.
182
+ - Do not include any explanations or instructions—only the five questions.
183
  """
184
 
185
+
 
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
  else:
188
  return jsonify({"error": "Invalid difficulty level"}), 400
writting.py CHANGED
@@ -109,12 +109,35 @@ def validate_response():
109
  return jsonify({"error": "Both 'topic' and 'response' fields are required."}), 400
110
 
111
  # Define the prompt for GPT to evaluate the response
112
- validation_prompt = (
113
- f"You are a writing teacher. Evaluate the sentence formation, grammar, and overall writing quality of the following response. "
114
- f"Provide constructive feedback highlighting any errors in grammar, spelling, punctuation, and sentence structure. "
115
- f"If the response is well-written, acknowledge its strengths. "
116
- f"Topic: '{topic}'. Response: '{response_text}'."
117
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  messages = [
120
  {"role": "system", "content": "You are a helpful writing teacher."},
 
109
  return jsonify({"error": "Both 'topic' and 'response' fields are required."}), 400
110
 
111
  # Define the prompt for GPT to evaluate the response
112
+ # validation_prompt = (
113
+ # f"You are a writing teacher. Evaluate the sentence formation, grammar, and overall writing quality of the following response. "
114
+ # f"Provide constructive feedback highlighting any errors in grammar, spelling, punctuation, and sentence structure. "
115
+ # f"If the response is well-written, acknowledge its strengths. "
116
+ # f"Topic: '{topic}'. Response: '{response_text}'."
117
+ # )
118
+
119
+
120
+
121
+ validation_prompt = (
122
+ "You are a kind writing teacher for children (age 9–12). "
123
+ "Use very simple English (CEFR A2). "
124
+ "Give feedback in at most 8 lines; each line under 12 words. "
125
+ "Use active voice. Avoid hard words (no 'analyze', 'implications', etc.). "
126
+ "If the student copied the topic or wrote too little, say: "
127
+ "'Please write in your own words.' and give one starter line. "
128
+ "Format EXACTLY like this:\n"
129
+ "Title: Simple Feedback\n"
130
+ "What is good:\n"
131
+ "- <two short points>\n"
132
+ "Needs fixing:\n"
133
+ "- <two short points>\n"
134
+ "Example fix:\n"
135
+ "- <rewrite one short sentence>\n"
136
+ "Score: <number>/10\n"
137
+ "Rules: Do not use angle brackets in the output. "
138
+ f"Topic: {topic}\n"
139
+ f"Student response: {response_text}"
140
+ )
141
 
142
  messages = [
143
  {"role": "system", "content": "You are a helpful writing teacher."},