service.preclass.processors.gen_readscript module

class service.preclass.processors.gen_readscript.PPTScriptGenerator(agenda)[source]

Bases: object

PowerPoint Script Generator that processes slides and generates teaching scripts.

This class handles: 1. Processing PowerPoint slides from an agenda structure 2. Generating teaching scripts using LLM for each slide 3. Maintaining conversation context between slides

agenda

The agenda structure containing PPT slides and content

Type:

AgendaStruct

prompt_script

System prompt for the LLM to generate teaching scripts

Type:

str

system

System message configuration for LLM interactions

Type:

list

extract()[source]

Processes the agenda structure and generates scripts for all PPT slides.

Traverses through the agenda using DFS, generates teaching scripts for each PPT slide while maintaining conversation context between consecutive slides.

Returns:

The processed agenda with generated scripts attached to PPT nodes

Return type:

AgendaStruct

format_script(role, message, image_url=None)[source]

Formats messages for LLM input in the required structure.

Parameters:
  • role (str) – Role of the message sender (‘user’ or ‘assistant’)

  • message (str) – The text content of the message

  • image_url (str, optional) – Base64 encoded image URL if present

Returns:

Formatted message structure for LLM input

Return type:

list

iterate_call_script(agent_messages, new_messages, timeout=300)[source]

Makes an LLM call to generate script with conversation context.

Parameters:
  • agent_messages (list) – Previous conversation history

  • new_messages (list) – New messages to process

  • timeout (int) – Maximum time to wait in seconds (default: 300)

Returns:

Generated script response from LLM

Return type:

str

Raises:

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

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

Bases: object

Service class for managing PPT script generation jobs through a message queue.

Handles: 1. Job queue management using RabbitMQ 2. MongoDB storage for job tracking 3. Worker process for script generation

Class Attributes:

_collection: MongoDB collection for job storage _result_collection: MongoDB collection for results _queue_name (str): RabbitMQ queue name _logger: Service logger instance

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

Callback function for processing queue messages.

Handles: 1. Job data retrieval from MongoDB 2. Script generation processing 3. Result storage and parent service notification

Parameters:
  • ch – Channel object

  • method – Delivery method

  • properties – Message properties

  • body – Message body containing job ID

static launch_worker()[source]

Launches the worker process to consume queue messages.

Starts a continuous process that listens for new jobs and processes them using the callback function. Can be terminated with CTRL+C.

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

Triggers a new script generation job.

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

  • lecture_id (ObjectId) – ID of the lecture to process

  • parent_job_id (ObjectId) – ID of the parent job

Returns:

Generated job ID

Return type:

str

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

Returns new datetime object representing current time local to tz.

tz

Timezone object.

If no tz is specified, uses local timezone.