from typing import List, Optional from fastapi import HTTPException from pydantic import BaseModel, Field from models.presentation_structure_model import PresentationStructureModel class SlideLayoutModel(BaseModel): id: str name: Optional[str] = None description: Optional[str] = None json_schema: dict class PresentationLayoutModel(BaseModel): name: str ordered: bool = Field(default=False) slides: List[SlideLayoutModel] def get_slide_layout_index(self, slide_layout_id: str) -> int: for index, slide in enumerate(self.slides): if slide.id == slide_layout_id: return index raise HTTPException( status_code=404, detail=f"Slide layout {slide_layout_id} not found" ) def to_presentation_structure(self): return PresentationStructureModel( slides=[index for index in range(len(self.slides))] ) def to_string(self): message = f"## Presentation Layout\n\n" for index, slide in enumerate(self.slides): message += f"### Slide Layout: {index}: \n" message += f"- Name: {slide.name or slide.json_schema.get('title')} \n" message += f"- Description: {slide.description} \n\n" return message def to_catalog_string(self) -> str: """Richer layout catalog for LLM layout-selection prompts. Includes placeholder field names and their character limits so the LLM can make more informed layout choices based on content type. """ lines = ["## Available Slide Layouts\n"] for index, slide in enumerate(self.slides): name = slide.name or slide.json_schema.get("title", f"Layout {index}") lines.append(f"### Layout {index}: {name}") if slide.description: lines.append(f"Purpose: {slide.description}") # Extract field names + constraints from json_schema props = slide.json_schema.get("properties", {}) fields = [] for field_name, field_def in props.items(): if field_name.startswith("__"): continue # skip internal fields max_len = field_def.get("maxLength") or field_def.get("maxItems") constraint = f" (max {max_len})" if max_len else "" fields.append(f"{field_name}{constraint}") if fields: lines.append(f"Fields: {', '.join(fields)}") lines.append("") return "\n".join(lines)