Add generate level exam endpoint.
This commit is contained in:
16
app.py
16
app.py
@@ -766,6 +766,22 @@ def get_reading_passage_3_question():
|
||||
return str(e)
|
||||
|
||||
|
||||
@app.route('/level', methods=['GET'])
|
||||
@jwt_required()
|
||||
def get_level_exam():
|
||||
try:
|
||||
number_of_exercises = 25
|
||||
exercises = gen_multiple_choice_level(number_of_exercises)
|
||||
return {
|
||||
"exercises": [exercises],
|
||||
"isDiagnostic": False,
|
||||
"minTimer": 25,
|
||||
"module": "level"
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
|
||||
@app.route('/fetch_tips', methods=['POST'])
|
||||
@jwt_required()
|
||||
def fetch_answer_tips():
|
||||
|
||||
@@ -666,3 +666,27 @@ def gen_write_blanks_form_exercise_listening_monologue(text: str, quantity: int,
|
||||
"text": replaced_form,
|
||||
"type": "writeBlanks"
|
||||
}
|
||||
|
||||
|
||||
def gen_multiple_choice_level(quantity: int, start_id=1):
|
||||
gen_multiple_choice_for_text = "Generate " + str(
|
||||
quantity) + " multiple choice questions of 4 options for an english level exam"
|
||||
token_count = count_tokens(gen_multiple_choice_for_text)["n_tokens"] - 300
|
||||
mc_questions = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, gen_multiple_choice_for_text, token_count,
|
||||
None,
|
||||
GEN_QUESTION_TEMPERATURE)
|
||||
parse_mc_questions = "Parse the questions into this json format: {\"questions\": [{\"id\": \"9\", \"options\": [{\"id\": \"A\", \"text\": " \
|
||||
"\"And\"}, {\"id\": \"B\", \"text\": \"Cat\"}, {\"id\": \"C\", \"text\": " \
|
||||
"\"Happy\"}, {\"id\": \"D\", \"text\": \"Jump\"}], " \
|
||||
"\"prompt\": \"Which of the following is a conjunction?\", " \
|
||||
"\"solution\": \"A\", \"variant\": \"text\"}]}. \nThe questions: '" + mc_questions + "'"
|
||||
token_count = count_tokens(parse_mc_questions, model_name=GPT_3_5_TURBO_INSTRUCT)["n_tokens"] - 300
|
||||
question = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
||||
["questions"],
|
||||
GEN_QUESTION_TEMPERATURE)
|
||||
return {
|
||||
"id": str(uuid.uuid4()),
|
||||
"prompt": "Select the appropriate option.",
|
||||
"questions": fix_exercise_ids(question, start_id)["questions"],
|
||||
"type": "multipleChoice",
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user