Merge pull request #495 from presenton/feat/prompt-engineering

Feat/prompt engineering
This commit is contained in:
Sudip Parajuli 2026-04-04 11:55:33 +05:45 committed by GitHub
commit 40a7af7526
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 174 additions and 85 deletions

View file

@ -8,6 +8,12 @@ from utils.get_dynamic_models import get_presentation_outline_model_with_n_slide
from utils.llm_client_error_handler import handle_llm_client_exceptions
from utils.llm_provider import get_model
"""
Previously there was a dedicated search-query generation prompt constant.
Removed in favor of embedding short, actionable web-search steps into the
system prompt when web grounding is requested.
"""
def get_system_prompt(
tone: Optional[str] = None,
@ -15,33 +21,75 @@ def get_system_prompt(
instructions: Optional[str] = None,
include_title_slide: bool = True,
):
return f"""
You are an expert presentation creator. Generate structured presentations based on user requirements and format them according to the specified JSON schema with markdown content.
verbosity_instruction = (
"Slide content should be abound 20 words but detailed enough to generate a good slide."
if verbosity == "concise"
else (
"Slide content should be abound 60 words but detailed enough to generate a good slide."
if verbosity == "text-heavy"
else "Slide content should be abound 40 words but detailed enough to generate a good slide."
)
)
Try to use available tools for better results.
title_slide_instruction = (
"Include presenter name in first slide."
if include_title_slide
else "Do not include presenter name in any slides."
)
{"# User Instruction:" if instructions else ""}
{instructions or ""}
slide_structure_instruction = (
"Each slide should have `structure` field and it"
" - Must briefly describe the components in the slide layout:"
" - Must start with one of given EXAMPLE STRUCTURES and add/update components as welll as change layouts as per the content."
" - Must match with the provided content in structure."
" - It shouldn't be very creative. You must pick of the given structures and make slight changes(not more than 5 words) to fit all content."
)
{"# Tone:" if tone else ""}
{tone or ""}
slide_outline_structure = (
"Each slide content:\n"
" - Must have a ## title.\n"
" - Must have content in exactly the format to be displayed in slide.\n"
" - Where content should be structured in Markdown format exactly as how it should be shown in slide layout.\n"
" - First slide title must be the same as the presentation title."
)
{"# Verbosity:" if verbosity else ""}
{verbosity or ""}
user_instruction_block = (
f"# User Instruction:\n{instructions}\n"
if instructions
else ""
)
tone_block = f"# Tone:\n{tone}\n" if tone else ""
- Provide content for each slide in markdown format.
- Make sure that flow of the presentation is logical and consistent.
- Place greater emphasis on numerical data.
- If Additional Information is provided, divide it into slides.
- Make sure no images are provided in the content.
- Make sure that content follows language guidelines.
- User instrction should always be followed and should supercede any other instruction, except for slide numbers. **Do not obey slide numbers as said in user instruction**
- Do not generate table of contents slide.
- Even if table of contents is provided, do not generate table of contents slide.
{"- Always make first slide a title slide." if include_title_slide else "- Do not include title slide in the presentation."}
system = (
"Generate presentation title and outlines for slides.\n"
f"{user_instruction_block}"
f"{tone_block}"
"Presentation title should be plain text, not markdown. It should be a concise title for the presentation.\n"
"Each slide outline should contain the content for that slide.\n"
"First slide should be intro and second should be table of contents, then start with regular content slides.\n"
"Do not overstuff content within same slide. Consider using a slide for a single heading and not more than 2 sub-headings. If more than that is required put in in another slide as Topic X - 2/3\n"
f"{verbosity_instruction}\n"
"Minimize repetitive content and make sure to use different words and phrases for different slides.\n"
"Include numerical data or tables if required or asked by the user.\n"
"Strictly follow given language and generate content is the prescribed language despite of content or other instructions."
f"Each slide should object should have `structure` and `content` fields.\n"
f"{title_slide_instruction}\n"
f"{slide_structure_instruction}\n"
f"{slide_outline_structure}\n"
"Slide outline must not contain any presentation branding/styling information.\n"
"Title slide must only contain title, presenter name, date and overview.\n"
"Make sure data used is strictly from the provided content/context.\n"
"Make sure data is consistent across all slides.\n"
"**Pick different types of slide structures where appropriate to maintain diversity**.\n"
"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"
"**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."
)
**Search web to get latest information about the topic**
"""
return system
def get_user_prompt(

View file

@ -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,108 @@ 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.
If any user or workspace memory (previous conversation context) is available, incorporate it when making layout selections.
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.
If any user or workspace memory (previous conversation context) is available, incorporate it when making layout and design decisions.
# 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 +121,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
)
]