Spaces:
Runtime error
Runtime error
add endpoint for 'numbers by level' function
Browse files
app.py
CHANGED
@@ -17,6 +17,8 @@ from mathtext_fastapi.conversation_manager import manage_conversation_response
|
|
17 |
from mathtext_fastapi.nlu import evaluate_message_with_nlu
|
18 |
from scripts.quiz.generators import start_interactive_math
|
19 |
from scripts.quiz.hints import generate_hint
|
|
|
|
|
20 |
|
21 |
app = FastAPI()
|
22 |
|
@@ -142,7 +144,7 @@ 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,
|
@@ -174,3 +176,27 @@ async def get_hint(request: Request):
|
|
174 |
hints_used = message_data['hints_used']
|
175 |
|
176 |
return JSONResponse(generate_hint(question_numbers, right_answer, number_correct, number_incorrect, level, hints_used))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
from mathtext_fastapi.nlu import evaluate_message_with_nlu
|
18 |
from scripts.quiz.generators import start_interactive_math
|
19 |
from scripts.quiz.hints import generate_hint
|
20 |
+
from scripts.quiz.questions import generate_question_answer_pair
|
21 |
+
from scripts.quiz.questions import generate_numbers_by_level
|
22 |
|
23 |
app = FastAPI()
|
24 |
|
|
|
144 |
"""Generates a hint and returns it as response along with hint data
|
145 |
|
146 |
Input
|
147 |
+
request.body:
|
148 |
{
|
149 |
'question_numbers': [1,2,3], # 2 or 3 numbers
|
150 |
'right_answer': 3,
|
|
|
176 |
hints_used = message_data['hints_used']
|
177 |
|
178 |
return JSONResponse(generate_hint(question_numbers, right_answer, number_correct, number_incorrect, level, hints_used))
|
179 |
+
|
180 |
+
|
181 |
+
@app.post("/numbers_by_level")
|
182 |
+
async def get_numbers_by_level(request: Request):
|
183 |
+
"""Generates a hint and returns it as response along with hint data
|
184 |
+
|
185 |
+
Input
|
186 |
+
request.body: json - level
|
187 |
+
{
|
188 |
+
'level': 'easy'
|
189 |
+
}
|
190 |
+
|
191 |
+
Output
|
192 |
+
context: dict - three generated numbers for specified level
|
193 |
+
{
|
194 |
+
"current_number": 10,
|
195 |
+
"ordinal_number": 2,
|
196 |
+
"times": 1
|
197 |
+
}
|
198 |
+
"""
|
199 |
+
data_dict = await request.json()
|
200 |
+
message_data = ast.literal_eval(data_dict.get('message_data', '').get('message_body', ''))
|
201 |
+
level = message_data['level']
|
202 |
+
return JSONResponse(generate_numbers_by_level(level))
|