Spaces:
Runtime error
Runtime error
feat:
Browse files- add endpoint for bare question generation
- decrease length of variables
- make imports excplicit
app.py
CHANGED
|
@@ -2,7 +2,9 @@
|
|
| 2 |
To run locally use 'uvicorn app:app --host localhost --port 7860'
|
| 3 |
"""
|
| 4 |
import ast
|
| 5 |
-
import
|
|
|
|
|
|
|
| 6 |
|
| 7 |
from fastapi import FastAPI, Request
|
| 8 |
from fastapi.responses import JSONResponse
|
|
@@ -15,10 +17,6 @@ from pydantic import BaseModel
|
|
| 15 |
from mathtext_fastapi.logging import prepare_message_data_for_logging
|
| 16 |
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 |
-
from scripts.quiz.questions import generate_question_answer_pair
|
| 21 |
-
from scripts.quiz.questions import generate_numbers_by_level
|
| 22 |
|
| 23 |
app = FastAPI()
|
| 24 |
|
|
@@ -132,11 +130,11 @@ async def ask_math_question(request: Request):
|
|
| 132 |
"""
|
| 133 |
data_dict = await request.json()
|
| 134 |
message_data = ast.literal_eval(data_dict.get('message_data', '').get('message_body', ''))
|
| 135 |
-
|
| 136 |
-
|
| 137 |
level = message_data['level']
|
| 138 |
|
| 139 |
-
return JSONResponse(start_interactive_math(
|
| 140 |
|
| 141 |
|
| 142 |
@app.post("/hint")
|
|
@@ -175,7 +173,7 @@ async def get_hint(request: Request):
|
|
| 175 |
level = message_data['level']
|
| 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")
|
|
@@ -199,4 +197,30 @@ async def get_numbers_by_level(request: Request):
|
|
| 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))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
To run locally use 'uvicorn app:app --host localhost --port 7860'
|
| 3 |
"""
|
| 4 |
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
|
|
|
|
| 17 |
from mathtext_fastapi.logging import prepare_message_data_for_logging
|
| 18 |
from mathtext_fastapi.conversation_manager import manage_conversation_response
|
| 19 |
from mathtext_fastapi.nlu import evaluate_message_with_nlu
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
app = FastAPI()
|
| 22 |
|
|
|
|
| 130 |
"""
|
| 131 |
data_dict = await request.json()
|
| 132 |
message_data = ast.literal_eval(data_dict.get('message_data', '').get('message_body', ''))
|
| 133 |
+
right_answers = message_data['number_correct']
|
| 134 |
+
wrong_answers = message_data['number_incorrect']
|
| 135 |
level = message_data['level']
|
| 136 |
|
| 137 |
+
return JSONResponse(generators.start_interactive_math(right_answers, wrong_answers, level))
|
| 138 |
|
| 139 |
|
| 140 |
@app.post("/hint")
|
|
|
|
| 173 |
level = message_data['level']
|
| 174 |
hints_used = message_data['hints_used']
|
| 175 |
|
| 176 |
+
return JSONResponse(hints.generate_hint(question_numbers, right_answer, number_correct, number_incorrect, level, hints_used))
|
| 177 |
|
| 178 |
|
| 179 |
@app.post("/numbers_by_level")
|
|
|
|
| 197 |
data_dict = await request.json()
|
| 198 |
message_data = ast.literal_eval(data_dict.get('message_data', '').get('message_body', ''))
|
| 199 |
level = message_data['level']
|
| 200 |
+
return JSONResponse(questions.generate_numbers_by_level(level))
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
@app.post("/generate_question")
|
| 204 |
+
async def generate_question(request: Request):
|
| 205 |
+
"""Generates a hint and returns it as response along with hint data
|
| 206 |
+
|
| 207 |
+
Input
|
| 208 |
+
request.body: json - level
|
| 209 |
+
{
|
| 210 |
+
'level': 'easy'
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
Output
|
| 214 |
+
context: dict - the information for the current state
|
| 215 |
+
{
|
| 216 |
+
"question": "Let's count up by 2s. What number is next if we start from 10",
|
| 217 |
+
"current_number": 10,
|
| 218 |
+
"ordinal_number": 2,
|
| 219 |
+
"answer": 12
|
| 220 |
+
}
|
| 221 |
+
"""
|
| 222 |
+
data_dict = await request.json()
|
| 223 |
+
message_data = ast.literal_eval(data_dict.get('message_data', '').get('message_body', ''))
|
| 224 |
+
level = message_data['level']
|
| 225 |
+
|
| 226 |
+
return JSONResponse(questions.generate_question_data(level)['question'])
|