question-generator / server /utils /questions_parser.py
lucas-wa
Refactoring server
6558cd8
raw
history blame contribute delete
975 Bytes
from langchain_core.documents import Document
def parse_question(question_str):
# Extract content
content_start = question_str.find('"""') + 3
content_end = question_str.rfind('"""', content_start)
content = question_str[content_start:content_end].strip()
# Extract correct option
correct_option_start = question_str.find('opcao_correta=') + 15
correct_option_end = correct_option_start + 1
correct_option = question_str[correct_option_start:correct_option_end]
# Extract metadata
metadata_start = question_str.find("metadados=") + 10
metadata_end = question_str.find("}", metadata_start) + 1
metadata_str = question_str[metadata_start:metadata_end]
metadata = eval(metadata_str)
topico, assunto, dificuldade, tipo = metadata.values()
return Document(page_content="##Questão\n" + content, metadata={"correct_option":correct_option, "topico":topico, "assunto":assunto, "dificuldade":dificuldade, "tipo":tipo})