service.preclass.processors.gen_description module
- class service.preclass.processors.gen_description.SERVICE[source]
Bases:
object
Service class for generating descriptions of lecture slides using GPT-4 Vision.
This service processes lecture slides by analyzing both text content and images, generating concise Chinese descriptions using GPT-4 Vision API. It maintains job state in MongoDB and communicates through RabbitMQ for job processing.
- static callback(ch, method, properties, body)[source]
Process a description generation job from the queue.
Handles the processing of individual slides, managing the conversation context with GPT-4 Vision, and storing the generated descriptions in the database.
- Parameters:
ch – RabbitMQ channel
method – RabbitMQ method frame
properties – RabbitMQ properties
body – Message body containing the job ID
- static launch_worker()[source]
Launch the RabbitMQ worker to process description generation jobs.
Starts consuming messages from the queue and handles graceful shutdown on keyboard interrupt.
- static trigger(parent_service, lecture_id, parent_job_id)[source]
Trigger a new description generation job.
- Parameters:
parent_service (str) – Name of the parent service that triggered this job
lecture_id (ObjectId) – MongoDB ID of the lecture to process
parent_job_id (ObjectId) – MongoDB ID of the parent job
- Returns:
The ID of the newly created job
- Return type:
str
- service.preclass.processors.gen_description.format_script(role, message, image_url=None)[source]
Format a message for GPT conversation with optional image support.
- Parameters:
role (str) – The role of the message sender (‘system’, ‘user’, or ‘assistant’)
message (str) – The text content of the message
image_url (str, optional) – Base64 encoded image data. Defaults to None.
- Returns:
A list containing a single dictionary with the formatted message
- Return type:
list
- service.preclass.processors.gen_description.now(tz=None)
Returns new datetime object representing current time local to tz.
- tz
Timezone object.
If no tz is specified, uses local timezone.