From 124d05eb829d30dc0a0fa049607ca588ce54f0b6 Mon Sep 17 00:00:00 2001 From: sudipnext Date: Sat, 4 Apr 2026 09:08:48 +0545 Subject: [PATCH] refactor: streamline system prompts for presentation generation and enhance layout selection guidelines --- .../generate_presentation_outlines.py | 8 +- .../generate_presentation_structure.py | 167 +++++++++++------- 2 files changed, 105 insertions(+), 70 deletions(-) diff --git a/electron/servers/fastapi/utils/llm_calls/generate_presentation_outlines.py b/electron/servers/fastapi/utils/llm_calls/generate_presentation_outlines.py index 6d3bc81d..b18ab467 100644 --- a/electron/servers/fastapi/utils/llm_calls/generate_presentation_outlines.py +++ b/electron/servers/fastapi/utils/llm_calls/generate_presentation_outlines.py @@ -84,12 +84,8 @@ def get_system_prompt( "If language is arabic then generate content is Modern Standard English (MSA).\n" "If instructed to generate a template then leave spaces with '____' in the content. Do not add arbitrary content, just add fillers." "**Never give out chinese text/content.**\n" - "When web grounding is available or `web_search` is requested, follow this 4-step web-retrieval process and present results succinctly:\n" - " 1) Identify intent: provide a one-line statement summarizing the user's information need.\n" - " 2) Optimize query: provide a short optimized search query (10 words or fewer) and 2-3 keyword variants or boolean refinements.\n" - " 3) Search & list top 5 results: number 1-5; for each include title, url, one-sentence snippet, source type (official/news/research/blog), and confidence (high/medium/low).\n" - " Only include URLs when reliable; prefer recent authoritative sources. Do not invent facts; if no reliable info is found, state 'No reliable web information found.'\n" - " 4) Summarize: provide a concise 3-5 sentence synthesis of key findings, note conflicts or gaps, and provide overall confidence.\n" + "**Search web to get latest information about the topic**\n" + "**Use Memory if available should be used to make presentation more personalized and engaging.**\n" "User instruction should always be followed and should supercede any other instruction, except for slide numbers." ) diff --git a/electron/servers/fastapi/utils/llm_calls/generate_presentation_structure.py b/electron/servers/fastapi/utils/llm_calls/generate_presentation_structure.py index f56004be..bbe26172 100644 --- a/electron/servers/fastapi/utils/llm_calls/generate_presentation_structure.py +++ b/electron/servers/fastapi/utils/llm_calls/generate_presentation_structure.py @@ -1,4 +1,5 @@ -from typing import Optional +from typing import Optional, Dict + from models.llm_message import LLMSystemMessage, LLMUserMessage from models.presentation_layout import PresentationLayoutModel from models.presentation_outline_model import PresentationOutlineModel @@ -9,58 +10,106 @@ from utils.get_dynamic_models import get_presentation_structure_model_with_n_sli from models.presentation_structure_model import PresentationStructureModel +STRUCTURE_FROM_SLIDES_MARKDOWN_SYSTEM_PROMPT = """ +You will be given available slide layouts and content for each slide. +You need to select a layout for each slide based on the mentioned guidelines. + +# Steps +1. Analyze all available slide layouts. +2. Analyze content for each slide. +3. Select a layout for each slide one by one by following the selection rules. + +# Analyzing Slide Layouts +- Identify what each layout contains based on provided schema markdown. + +# Analyzing Content +- Identify how the content is structured. +- Identify if the content contains tables. + +# Selection Rules +- If content contains table, then select either table layout or graph layout. +- Don't select layout with image unless content contains image. +- Don't select table layout if content does not contain table. +- You are allowed to select same layout for multiple slides. + +# Table Layout Selection Rules +- Must select table layout if the content contains table with text data. +- Must only select a layout with table if the table only contains text data. + +# Graph Layout Selection Rules +- Must only select a layout with chart if the content contains table with numeric data. +- Identify how many columns are present in the table. +- Must select a layout that supports n-1 charts for n columns. +- Must prioritize layouts that support multiple charts. +- Don't select metrics layout for content containing table with numeric data. +- For example, if content contains table with 3 columns, then select a layout that supports 2 charts. + +{user_instructions} + +# Output Rules: +- One layout index for each slide. +- Example: [0, 1, 2, 3, 4] + +{presentation_layout} +""" + + +GET_MESSAGES_SYSTEM_PROMPT = """ +You're a professional presentation designer with creative freedom to design engaging presentations. + +# DESIGN PHILOSOPHY +- Create visually compelling and varied presentations +- Match layout to content purpose and audience needs + +# Layout Selection Guidelines +1. **Content-driven choices**: Let the slide's purpose guide layout selection +- Opening/closing → Title layouts +- Processes/workflows → Visual process layouts +- Comparisons/contrasts → Side-by-side layouts +- Data/metrics → Chart/graph layouts +- Concepts/ideas → Image + text layouts +- Key insights → Emphasis layouts + +2. **Visual variety**: Aim for diverse slide layouts across the presentation. +- Don't use same layout for multiple slides unless necessary. +- Mix text-heavy and visual-heavy slides naturally +- Use your judgment on when repetition serves the content +- Balance information density across slides +- Adjacent slide layouts should be different unless instructed/necessary otherwise. + +3. **Audience experience**: Consider how slides work together +- Create natural transitions between topics + +4. **Table of contents**: +- Must only use table of contents layout if slide content contains table of contents. + +{user_instruction_header} + +User instruction should be taken into account while creating the presentation structure, except for number of slides. + +Select layout index for each of the {n_slides} slides based on what will best serve the presentation's goals. + +""" + + def get_messages( presentation_layout: PresentationLayoutModel, n_slides: int, data: str, instructions: Optional[str] = None, ): + system_prompt = GET_MESSAGES_SYSTEM_PROMPT.format( + user_instruction_header="# User Instruction:" if instructions else "", + n_slides=n_slides, + ) + return [ - LLMSystemMessage( - content=f""" - You're a professional presentation designer with creative freedom to design engaging presentations. - - {presentation_layout.to_string()} - - # DESIGN PHILOSOPHY - - Create visually compelling and varied presentations - - Match layout to content purpose and audience needs - - Prioritize engagement over rigid formatting rules - - # Layout Selection Guidelines - 1. **Content-driven choices**: Let the slide's purpose guide layout selection - - Opening/closing → Title layouts - - Processes/workflows → Visual process layouts - - Comparisons/contrasts → Side-by-side layouts - - Data/metrics → Chart/graph layouts - - Concepts/ideas → Image + text layouts - - Key insights → Emphasis layouts - - 2. **Visual variety**: Aim for diverse, engaging presentation flow - - Mix text-heavy and visual-heavy slides naturally - - Use your judgment on when repetition serves the content - - Balance information density across slides - - 3. **Audience experience**: Consider how slides work together - - Create natural transitions between topics - - Use layouts that enhance comprehension - - Design for maximum impact and retention - - **Trust your design instincts. Focus on creating the most effective presentation for the content and audience.** - - {"# User Instruction:" if instructions else ""} - {instructions or ""} - - User intruction should be taken into account while creating the presentation structure, except for number of slides. - - Select layout index for each of the {n_slides} slides based on what will best serve the presentation's goals. - """, - ), - LLMUserMessage( - content=f""" - {data} - """, - ), + LLMSystemMessage(content=system_prompt), + LLMUserMessage(content=( + f"{presentation_layout.to_string()}\n\n" + "--------------------------------------\n\n" + f"{data}" + )), ] @@ -70,28 +119,18 @@ def get_messages_for_slides_markdown( data: str, instructions: Optional[str] = None, ): + system_prompt = STRUCTURE_FROM_SLIDES_MARKDOWN_SYSTEM_PROMPT.format( + user_instructions=instructions or "", + presentation_layout=presentation_layout.to_string(with_schema=True), + ) + return [ LLMSystemMessage( - content=f""" - You're a professional presentation designer with creative freedom to design engaging presentations. - - {"# User Instruction:" if instructions else ""} - {instructions or ""} - - {presentation_layout.to_string()} - - Select layout that best matches the content of the slides. - - User intruction should be taken into account while creating the presentation structure, except for number of slides. - - Select layout index for each of the {n_slides} slides based on what will best serve the presentation's goals. - """, + content=system_prompt ), LLMUserMessage( - content=f""" - {data} - """, - ), + content=data + ) ]