Validate the generated outline. Raises: ValueError: If the outline is invalid.
(self, outline: dict, retry: int = 0)
| 199 | return outline |
| 200 | |
| 201 | def _valid_outline(self, outline: dict, retry: int = 0) -> dict: |
| 202 | """ |
| 203 | Validate the generated outline. |
| 204 | |
| 205 | Raises: |
| 206 | ValueError: If the outline is invalid. |
| 207 | """ |
| 208 | try: |
| 209 | for slide in outline.values(): |
| 210 | layout_sim = torch.cosine_similarity( |
| 211 | get_text_embedding(slide["layout"], self.text_model), |
| 212 | self.layout_embeddings, |
| 213 | ) |
| 214 | if layout_sim.max() < 0.7: |
| 215 | raise ValueError( |
| 216 | f"Layout `{slide['layout']}` not found, must be one of {self.layout_names}" |
| 217 | ) |
| 218 | slide["layout"] = self.layout_names[layout_sim.argmax().item()] |
| 219 | if any( |
| 220 | not {"layout", "subsections", "description"}.issubset(set(slide.keys())) |
| 221 | for slide in outline.values() |
| 222 | ): |
| 223 | raise ValueError( |
| 224 | "Invalid outline structure, must be a dict with layout, subsections, description" |
| 225 | ) |
| 226 | except ValueError as e: |
| 227 | print(outline, e) |
| 228 | if retry < self.retry_times: |
| 229 | new_outline = self.staffs["planner"].retry( |
| 230 | str(e), traceback.format_exc(), retry + 1 |
| 231 | ) |
| 232 | return self._valid_outline(new_outline, retry + 1) |
| 233 | else: |
| 234 | raise ValueError("Failed to generate outline, tried too many times") |
| 235 | return outline |
| 236 | |
| 237 | def _hire_staffs(self, record_cost: bool, **kwargs) -> dict[str, Role]: |
| 238 | """ |
no test coverage detected