sviddo commited on
Commit
247946c
1 Parent(s): 685a923

update app module

Browse files
Files changed (1) hide show
  1. app.py +55 -10
app.py CHANGED
@@ -5,6 +5,7 @@ import ast
5
  import scripts.quiz.generators as generators
6
  import scripts.quiz.hints as hints
7
  import scripts.quiz.questions as questions
 
8
 
9
  from fastapi import FastAPI, Request
10
  from fastapi.responses import JSONResponse
@@ -107,7 +108,7 @@ async def evaluate_user_message_with_nlu_api(request: Request):
107
 
108
  @app.post("/question")
109
  async def ask_math_question(request: Request):
110
- """Generates a question and returns it as response along with question data
111
 
112
  Input
113
  request.body: json - amount of correct and incorrect answers in the account
@@ -121,7 +122,7 @@ async def ask_math_question(request: Request):
121
  context: dict - the information for the current state
122
  {
123
  'text': 'What is 1+2?',
124
- 'question_numbers': [1,2,3], #2 or 3 numbers
125
  'right_answer': 3,
126
  'number_correct': 0,
127
  'number_incorrect': 0,
@@ -139,12 +140,12 @@ async def ask_math_question(request: Request):
139
 
140
  @app.post("/hint")
141
  async def get_hint(request: Request):
142
- """Generates a hint and returns it as response along with hint data
143
 
144
  Input
145
  request.body:
146
  {
147
- 'question_numbers': [1,2,3], # 2 or 3 numbers
148
  'right_answer': 3,
149
  'number_correct': 0,
150
  'number_incorrect': 0,
@@ -178,7 +179,7 @@ async def get_hint(request: Request):
178
 
179
  @app.post("/generate_question")
180
  async def generate_question(request: Request):
181
- """Generates a hint and returns it as response along with hint data
182
 
183
  Input
184
  request.body: json - level
@@ -189,10 +190,8 @@ async def generate_question(request: Request):
189
  Output
190
  context: dict - the information for the current state
191
  {
192
- "question": "Let's count up by 2s. What number is next if we start from 10",
193
- "current_number": 10,
194
- "ordinal_number": 2,
195
- "answer": 12
196
  }
197
  """
198
  data_dict = await request.json()
@@ -204,7 +203,7 @@ async def generate_question(request: Request):
204
 
205
  @app.post("/numbers_by_level")
206
  async def get_numbers_by_level(request: Request):
207
- """Generates a hint and returns it as response along with hint data
208
 
209
  Input
210
  request.body: json - level
@@ -224,3 +223,49 @@ async def get_numbers_by_level(request: Request):
224
  message_data = ast.literal_eval(data_dict.get('message_data', '').get('message_body', ''))
225
  level = message_data['level']
226
  return JSONResponse(questions.generate_numbers_by_level(level))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  import scripts.quiz.generators as generators
6
  import scripts.quiz.hints as hints
7
  import scripts.quiz.questions as questions
8
+ import scripts.quiz.utils as utils
9
 
10
  from fastapi import FastAPI, Request
11
  from fastapi.responses import JSONResponse
 
108
 
109
  @app.post("/question")
110
  async def ask_math_question(request: Request):
111
+ """Generate a question and return it as response along with question data
112
 
113
  Input
114
  request.body: json - amount of correct and incorrect answers in the account
 
122
  context: dict - the information for the current state
123
  {
124
  'text': 'What is 1+2?',
125
+ 'question_numbers': [1,2,3], #3 numbers - current number, ordinal number, times
126
  'right_answer': 3,
127
  'number_correct': 0,
128
  'number_incorrect': 0,
 
140
 
141
  @app.post("/hint")
142
  async def get_hint(request: Request):
143
+ """Generate a hint and return it as response along with hint data
144
 
145
  Input
146
  request.body:
147
  {
148
+ 'question_numbers': [1,2,3], #3 numbers - current number, ordinal number, times
149
  'right_answer': 3,
150
  'number_correct': 0,
151
  'number_incorrect': 0,
 
179
 
180
  @app.post("/generate_question")
181
  async def generate_question(request: Request):
182
+ """Generate a bare question and return it as response
183
 
184
  Input
185
  request.body: json - level
 
190
  Output
191
  context: dict - the information for the current state
192
  {
193
+ "question": "Let's count up by 2s. What number is next if we start from 10?
194
+ 6 8 10 ..."
 
 
195
  }
196
  """
197
  data_dict = await request.json()
 
203
 
204
  @app.post("/numbers_by_level")
205
  async def get_numbers_by_level(request: Request):
206
+ """Generate three numbers and return them as response
207
 
208
  Input
209
  request.body: json - level
 
223
  message_data = ast.literal_eval(data_dict.get('message_data', '').get('message_body', ''))
224
  level = message_data['level']
225
  return JSONResponse(questions.generate_numbers_by_level(level))
226
+
227
+
228
+ @app.post("/number_sequence")
229
+ async def get_number_sequence(request: Request):
230
+ """Generate a number sequence
231
+
232
+ Input
233
+ request.body: json - level
234
+ {
235
+ "current_number": 10,
236
+ "ordinal_number": 2,
237
+ "times": 1
238
+ }
239
+
240
+ Output
241
+ one of following strings with (numbers differ):
242
+ ... 1 2 3
243
+ 1 2 3 ...
244
+ """
245
+ data_dict = await request.json()
246
+ message_data = ast.literal_eval(data_dict.get('message_data', '').get('message_body', ''))
247
+ cur_num = message_data['current_number']
248
+ ord_num = message_data['ordinal_number']
249
+ times = message_data['times']
250
+ return JSONResponse(questions.generate_number_sequence(cur_num, ord_num, times))
251
+
252
+
253
+ @app.post("/level")
254
+ async def get_next_level(request: Request):
255
+ """Depending on current level and desire to level up/down return next level
256
+
257
+ Input
258
+ request.body: json - level
259
+ {
260
+ "current_level": "easy",
261
+ "level_up": True
262
+ }
263
+
264
+ Output
265
+ Literal - "easy", "medium" or "hard"
266
+ """
267
+ data_dict = await request.json()
268
+ message_data = ast.literal_eval(data_dict.get('message_data', '').get('message_body', ''))
269
+ cur_level = message_data['current_level']
270
+ level_up = message_data['level_up']
271
+ return JSONResponse(utils.get_next_level(cur_level, level_up))