service.preclass.processors.gen_askquestion module

class service.preclass.processors.gen_askquestion.QAGenerator(agenda)[source]

Bases: object

Generator for creating AskQuestion functions during preclass generation.

This class processes an agenda structure and generates multiple-choice questions based on the teaching content (scripts) found within the agenda nodes.

Parameters:

agenda (AgendaStruct) – The agenda structure containing teaching content and nodes

extract()[source]

Processes the agenda structure to generate and insert questions at appropriate nodes.

Traverses the agenda tree, identifies nodes requiring questions, generates Q&A content using the LLM, and attaches AskQuestion functions to the nodes.

Returns:

The modified agenda structure with added question functions

Return type:

AgendaStruct

gen_qa(recent_scripts, use_cache=True, timeout=300)[source]

Generates questions and answers using an LLM based on the provided scripts.

Parameters:
  • recent_scripts (list[str]) – List of recent teaching scripts

  • use_cache (bool, optional) – Whether to use cached LLM responses. Defaults to True

  • timeout (int, optional) – Maximum time to wait in seconds. Defaults to 300

Returns:

Raw LLM response containing generated questions and answers

Return type:

str

Raises:

TimeoutError – If the response is not received within the timeout period

get_prompt(recent_scripts)[source]

Generates a prompt for the LLM to create multiple-choice questions.

Parameters:

recent_scripts (list[str]) – List of recent teaching scripts, with the last one being the current content to focus on

Returns:

The formatted prompt for question generation, or None if input is invalid

Return type:

str

class service.preclass.processors.gen_askquestion.SERVICE[source]

Bases: object

Service class for managing the question generation workflow using RabbitMQ.

Handles job queuing, processing, and result storage for the question generation service. Uses MongoDB for persistent storage and RabbitMQ for job queue management.

static callback(ch, method, properties, body)[source]

Callback function for processing question generation jobs from RabbitMQ.

Parameters:
  • ch – RabbitMQ channel

  • method – RabbitMQ method frame

  • properties – RabbitMQ properties

  • body – Message body containing the job ID

static launch_worker()[source]

Launches the worker process to consume and process jobs from the RabbitMQ queue.

The worker runs continuously until interrupted with CTRL+C.

static trigger(parent_service, lecture_id, parent_job_id)[source]

Triggers a new question generation job.

Parameters:
  • parent_service (str) – Name of the parent service

  • lecture_id (ObjectId) – ID of the lecture being processed

  • parent_job_id (ObjectId) – ID of the parent job

Returns:

ID of the created job

Return type:

str

service.preclass.processors.gen_askquestion.now(tz=None)

Returns new datetime object representing current time local to tz.

tz

Timezone object.

If no tz is specified, uses local timezone.