class_factory.beamer_bot package

class_factory.beamer_bot.BeamerBot module

BeamerBot Module

The BeamerBot module provides a framework for generating structured LaTeX Beamer slides based on lesson objectives, readings, and prior lesson presentations. By using a language model (LLM), BeamerBot automates the process of slide creation, ensuring a consistent slide structure while allowing for custom guidance and validation.

Key Functionalities

  1. Automated Slide Generation: - BeamerBot generates a LaTeX Beamer presentation for each lesson, incorporating:

    • A title page with consistent author and institution information

    • “Where We Came From” and “Where We Are Going” slides

    • Lesson objectives with highlighted action verbs (e.g., textbf{Analyze} key events)

    • Discussion questions and in-class exercises

    • Summary slides with key takeaways

  2. Previous Lesson Integration: - Retrieves and references prior lesson presentations to maintain consistent formatting and flow - Preserves author and institution information across presentations

  3. Prompt Customization and Validation: - Supports custom prompts and specific guidance for tailored slide content - Validates generated LaTeX for correct formatting and content quality - Provides multiple retry attempts if validation fails

Dependencies

This module requires:

  • langchain_core: For LLM chain creation and prompt handling

  • pathlib: For file path management

  • Custom utility modules for: - Document loading (load_documents) - LaTeX validation (llm_validator) - Response parsing (response_parsers) - Slide pipeline utilities (slide_pipeline_utils)

Usage

  1. Initialize BeamerBot: ```python beamer_bot = BeamerBot(

    lesson_no=10, llm=llm, course_name=”Political Science”, lesson_loader=lesson_loader, output_dir=output_dir

  2. Generate Slides: `python # Optional specific guidance guidance = "Focus on comparing democratic and authoritarian systems" slides = beamer_bot.generate_slides(specific_guidance=guidance) `

  3. Save the Slides: `python beamer_bot.save_slides(slides) `

class class_factory.beamer_bot.BeamerBot.BeamerBot(lesson_no: int, llm, course_name: str, lesson_loader: LessonLoader, output_dir: Path | str = None, verbose: bool = False, slide_dir: Path | str = None, lesson_objectives: dict = None)[source]

Bases: BaseModel

A class to generate LaTeX Beamer slides for a specified lesson using a language model (LLM).

BeamerBot automates the slide generation process, creating structured presentations based on lesson readings, objectives, and content from prior presentations when available. Each slide is crafted following a consistent format, and the generated LaTeX is validated for correctness.

lesson_no

Lesson number for which to generate slides.

Type:

int

llm

Language model instance for generating slides.

course_name

Name of the course for slide context.

Type:

str

lesson_loader

Loader for accessing lesson readings and objectives.

Type:

LessonLoader

output_dir

Directory to save the generated Beamer slides.

Type:

Path

slide_dir

Directory containing existing Beamer slides.

Type:

Optional[Path]

llm_response

Stores the generated LaTeX response from the LLM.

Type:

str

prompt

Generated prompt for the LLM.

Type:

str

lesson_objectives

user-provided lesson objectives if syllabus not available.

Type:

optional, dict

generate_slides(specific_guidance

str = None, latex_compiler: str = “pdflatex”) -> str: Generates Beamer slides as LaTeX code for the specified lesson.

save_slides(latex_content

str) -> None: Saves the generated LaTeX content to a .tex file.

set_user_objectives(objectives

Union[List[str], Dict[str, str]]): Initialize user-defined lesson objectives, converting lists to dictionaries if needed. Inherited from BaseModel.

Internal Methods:
_format_readings_for_prompt() -> str:

Combines readings across lessons into a single string for the LLM prompt.

_find_prior_lesson(lesson_no: int, max_attempts: int = 3) -> Path:

Finds the most recent prior lesson’s Beamer file to use as a template.

_load_prior_lesson() -> str:

Loads the LaTeX content of a prior lesson’s Beamer presentation as a string.

_generate_prompt() -> str:

Constructs the LLM prompt using lesson objectives, readings, and prior lesson content.

_validate_llm_response(generated_slides: str, objectives: str, readings: str, last_presentation: str,

prompt_specific_guidance: str = “”, additional_guidance: str = “”) -> Dict[str, Any]:

Validates the generated LaTeX for quality and accuracy.

generate_slides(specific_guidance: str = None, lesson_objectives: dict = None, latex_compiler: str = 'pdflatex') str[source]

Generate LaTeX Beamer slides for the lesson using the language model.

Parameters:
  • specific_guidance (str, optional) – Custom instructions for slide content and structure

  • lesson_objectives (dict, optional) – Override default objectives with custom ones Format: {lesson_number: “objective text”}

  • latex_compiler (str, optional) – LaTeX compiler to use for validation. Defaults to “pdflatex”

Returns:

Complete LaTeX content for the presentation, including preamble

Return type:

str

Raises:
  • ValueError – If validation fails after maximum retry attempts

  • FileNotFoundError – If required prior lesson files cannot be located

Note

The method includes multiple validation steps: 1. Content quality validation through LLM 2. LaTeX syntax validation using specified compiler 3. Up to 3 retry attempts if validation fails

save_slides(latex_content: str)[source]

Save the generated LaTeX content to a .tex file.

Parameters:

latex_content (str) – The LaTeX content to save.