import random from app.configs.constants import EducationalContent, GPTModels, TemperatureSettings from app.services.abc import ILLMService class BlankSpace: def __init__(self, llm: ILLMService, mc_variants: dict): self._llm = llm self._mc_variants = mc_variants async def gen_blank_space_text_utas( self, quantity: int, start_id: int, size: int, topic=None ): if not topic: topic = random.choice(EducationalContent.MTI_TOPICS) json_template = self._mc_variants["blank_space_text"] messages = [ { "role": "system", "content": f'You are a helpful assistant designed to output JSON on this format: {json_template}' }, { "role": "user", "content": f'Generate a text of at least {size} words about the topic {topic}.' }, { "role": "user", "content": ( f'From the generated text choose {quantity} words (cannot be sequential words) to replace ' 'once with {{id}} where id starts on ' + str(start_id) + ' and is incremented for each word. ' 'The ids must be ordered throughout the text and the words must be replaced only once. ' 'Put the removed words and respective ids on the words array of the json in the correct order.' ) } ] question = await self._llm.prediction( GPTModels.GPT_4_O, messages, ["question"], TemperatureSettings.GEN_QUESTION_TEMPERATURE ) return question["question"]