Fix level exam generation
This commit is contained in:
@@ -6,7 +6,7 @@ import uuid
|
||||
|
||||
from helper.api_messages import QuestionType
|
||||
from helper.firebase_helper import get_all
|
||||
from helper.openai_interface import make_openai_instruct_call
|
||||
from helper.openai_interface import make_openai_instruct_call, make_openai_call
|
||||
from helper.token_counter import count_tokens
|
||||
from helper.constants import *
|
||||
from wonderwords import RandomWord
|
||||
@@ -682,47 +682,58 @@ def gen_multiple_choice_level(quantity: int, start_id=1):
|
||||
"questions and some advanced questions. Ensure that the questions cover a range of topics such as " \
|
||||
"verb tense, subject-verb agreement, pronoun usage, sentence structure, and punctuation. Make sure " \
|
||||
"every question only has 1 correct answer."
|
||||
|
||||
messages = [{
|
||||
"role": "user",
|
||||
"content": gen_multiple_choice_for_text
|
||||
}]
|
||||
|
||||
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,
|
||||
mc_questions = make_openai_call(GPT_4_PREVIEW, messages, token_count,
|
||||
None,
|
||||
GEN_QUESTION_TEMPERATURE)
|
||||
split_mc_questions = mc_questions.split('13')
|
||||
if not '25' in mc_questions:
|
||||
return gen_multiple_choice_level(quantity, start_id)
|
||||
else:
|
||||
split_mc_questions = mc_questions.split('13')
|
||||
|
||||
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: "' + split_mc_questions[0] + '"')
|
||||
token_count = count_tokens(parse_mc_questions, model_name=GPT_3_5_TURBO_INSTRUCT)["n_tokens"]
|
||||
question = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
||||
["questions"],
|
||||
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: "' + '13' + split_mc_questions[1] + '"')
|
||||
token_count = count_tokens(parse_mc_questions, model_name=GPT_3_5_TURBO_INSTRUCT)["n_tokens"]
|
||||
question_2 = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
||||
["questions"],
|
||||
GEN_QUESTION_TEMPERATURE)
|
||||
question["questions"].extend(question_2["questions"])
|
||||
parse_mc_questions = ('Parse the questions into this json format: \n\'{"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"}]}\'\n '
|
||||
'\nThe questions: "' + split_mc_questions[0] + '"')
|
||||
token_count = count_tokens(parse_mc_questions, model_name=GPT_3_5_TURBO_INSTRUCT)["n_tokens"]
|
||||
question = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
||||
["questions"],
|
||||
GEN_QUESTION_TEMPERATURE)
|
||||
print(question)
|
||||
parse_mc_questions = ('Parse the questions into this json format: \n\'{"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"}]}\'\n '
|
||||
'\nThe questions: "' + '13' + split_mc_questions[1] + '"')
|
||||
token_count = count_tokens(parse_mc_questions, model_name=GPT_3_5_TURBO_INSTRUCT)["n_tokens"]
|
||||
question_2 = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, parse_mc_questions, token_count,
|
||||
["questions"],
|
||||
GEN_QUESTION_TEMPERATURE)
|
||||
print(question_2)
|
||||
question["questions"].extend(question_2["questions"])
|
||||
|
||||
all_exams = get_all("level")
|
||||
seen_keys = set()
|
||||
for i in range(len(question["questions"])):
|
||||
question["questions"][i], seen_keys = replace_exercise_if_exists(all_exams, question["questions"][i], question,
|
||||
seen_keys)
|
||||
return {
|
||||
"id": str(uuid.uuid4()),
|
||||
"prompt": "Select the appropriate option.",
|
||||
"questions": fix_exercise_ids(question, start_id)["questions"],
|
||||
"type": "multipleChoice",
|
||||
}
|
||||
all_exams = get_all("level")
|
||||
seen_keys = set()
|
||||
for i in range(len(question["questions"])):
|
||||
question["questions"][i], seen_keys = replace_exercise_if_exists(all_exams, question["questions"][i], question,
|
||||
seen_keys)
|
||||
return {
|
||||
"id": str(uuid.uuid4()),
|
||||
"prompt": "Select the appropriate option.",
|
||||
"questions": fix_exercise_ids(question, start_id)["questions"],
|
||||
"type": "multipleChoice",
|
||||
}
|
||||
|
||||
|
||||
def replace_exercise_if_exists(all_exams, current_exercise, current_exam, seen_keys):
|
||||
|
||||
Reference in New Issue
Block a user