Add generate level exam endpoint.

This commit is contained in:
Cristiano Ferreira
2023-11-22 23:09:41 +00:00
parent 223a7dfd11
commit 0684314cef
3 changed files with 241 additions and 0 deletions

View File

@@ -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",
}