You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
7.3 KiB

3 weeks ago
"""
Prompt templates for multimodal content processing
Contains all prompt templates used in modal processors for analyzing
different types of content (images, tables, equations, etc.)
"""
from __future__ import annotations
from typing import Any
PROMPTS: dict[str, Any] = {}
# System prompts for different analysis types
PROMPTS["IMAGE_ANALYSIS_SYSTEM"] = (
"You are an expert image analyst. Provide detailed, accurate descriptions."
)
PROMPTS["IMAGE_ANALYSIS_FALLBACK_SYSTEM"] = (
"You are an expert image analyst. Provide detailed analysis based on available information."
)
PROMPTS["TABLE_ANALYSIS_SYSTEM"] = (
"You are an expert data analyst. Provide detailed table analysis with specific insights."
)
PROMPTS["EQUATION_ANALYSIS_SYSTEM"] = (
"You are an expert mathematician. Provide detailed mathematical analysis."
)
PROMPTS["GENERIC_ANALYSIS_SYSTEM"] = (
"You are an expert content analyst specializing in {content_type} content."
)
# Image analysis prompt template
PROMPTS[
"vision_prompt"
] = """Please analyze this image in detail and provide a JSON response with the following structure:
{{
"detailed_description": "A comprehensive and detailed visual description of the image following these guidelines:
- Describe the overall composition and layout
- Identify all objects, people, text, and visual elements
- Explain relationships between elements
- Note colors, lighting, and visual style
- Describe any actions or activities shown
- Include technical details if relevant (charts, diagrams, etc.)
- Always use specific names instead of pronouns",
"entity_info": {{
"entity_name": "{entity_name}",
"entity_type": "image",
"summary": "concise summary of the image content and its significance (max 100 words)"
}}
}}
Additional context:
- Image Path: {image_path}
- Captions: {captions}
- Footnotes: {footnotes}
Focus on providing accurate, detailed visual analysis that would be useful for knowledge retrieval."""
# Image analysis prompt with text fallback
PROMPTS["text_prompt"] = """Based on the following image information, provide analysis:
Image Path: {image_path}
Captions: {captions}
Footnotes: {footnotes}
{vision_prompt}"""
# Table analysis prompt template
PROMPTS[
"table_prompt"
] = """Please analyze this table content and provide a JSON response with the following structure:
{{
"detailed_description": "A comprehensive analysis of the table including:
- Table structure and organization
- Column headers and their meanings
- Key data points and patterns
- Statistical insights and trends
- Relationships between data elements
- Significance of the data presented
Always use specific names and values instead of general references.",
"entity_info": {{
"entity_name": "{entity_name}",
"entity_type": "table",
"summary": "concise summary of the table's purpose and key findings (max 100 words)"
}}
}}
Table Information:
Image Path: {table_img_path}
Caption: {table_caption}
Body: {table_body}
Footnotes: {table_footnote}
Focus on extracting meaningful insights and relationships from the tabular data."""
# Equation analysis prompt template
PROMPTS[
"equation_prompt"
] = """Please analyze this mathematical equation and provide a JSON response with the following structure:
{{
"detailed_description": "A comprehensive analysis of the equation including:
- Mathematical meaning and interpretation
- Variables and their definitions
- Mathematical operations and functions used
- Application domain and context
- Physical or theoretical significance
- Relationship to other mathematical concepts
- Practical applications or use cases
Always use specific mathematical terminology.",
"entity_info": {{
"entity_name": "{entity_name}",
"entity_type": "equation",
"summary": "concise summary of the equation's purpose and significance (max 100 words)"
}}
}}
Equation Information:
Equation: {equation_text}
Format: {equation_format}
Focus on providing mathematical insights and explaining the equation's significance."""
# Generic content analysis prompt template
PROMPTS[
"generic_prompt"
] = """Please analyze this {content_type} content and provide a JSON response with the following structure:
{{
"detailed_description": "A comprehensive analysis of the content including:
- Content structure and organization
- Key information and elements
- Relationships between components
- Context and significance
- Relevant details for knowledge retrieval
Always use specific terminology appropriate for {content_type} content.",
"entity_info": {{
"entity_name": "{entity_name}",
"entity_type": "{content_type}",
"summary": "concise summary of the content's purpose and key points (max 100 words)"
}}
}}
Content: {content}
Focus on extracting meaningful information that would be useful for knowledge retrieval."""
# Modal chunk templates
PROMPTS["image_chunk"] = """
Image Content Analysis:
Image Path: {image_path}
Captions: {captions}
Footnotes: {footnotes}
Visual Analysis: {enhanced_caption}"""
PROMPTS["table_chunk"] = """Table Analysis:
Image Path: {table_img_path}
Caption: {table_caption}
Structure: {table_body}
Footnotes: {table_footnote}
Analysis: {enhanced_caption}"""
PROMPTS["equation_chunk"] = """Mathematical Equation Analysis:
Equation: {equation_text}
Format: {equation_format}
Mathematical Analysis: {enhanced_caption}"""
PROMPTS["generic_chunk"] = """{content_type} Content Analysis:
Content: {content}
Analysis: {enhanced_caption}"""
# Query-related prompts
PROMPTS["QUERY_IMAGE_DESCRIPTION"] = (
"Please briefly describe the main content, key elements, and important information in this image."
)
PROMPTS["QUERY_IMAGE_ANALYST_SYSTEM"] = (
"You are a professional image analyst who can accurately describe image content."
)
PROMPTS[
"QUERY_TABLE_ANALYSIS"
] = """Please analyze the main content, structure, and key information of the following table data:
Table data:
{table_data}
Table caption: {table_caption}
Please briefly summarize the main content, data characteristics, and important findings of the table."""
PROMPTS["QUERY_TABLE_ANALYST_SYSTEM"] = (
"You are a professional data analyst who can accurately analyze table data."
)
PROMPTS[
"QUERY_EQUATION_ANALYSIS"
] = """Please explain the meaning and purpose of the following mathematical formula:
LaTeX formula: {latex}
Formula caption: {equation_caption}
Please briefly explain the mathematical meaning, application scenarios, and importance of this formula."""
PROMPTS["QUERY_EQUATION_ANALYST_SYSTEM"] = (
"You are a mathematics expert who can clearly explain mathematical formulas."
)
PROMPTS[
"QUERY_GENERIC_ANALYSIS"
] = """Please analyze the following {content_type} type content and extract its main information and key features:
Content: {content_str}
Please briefly summarize the main characteristics and important information of this content."""
PROMPTS["QUERY_GENERIC_ANALYST_SYSTEM"] = (
"You are a professional content analyst who can accurately analyze {content_type} type content."
)
PROMPTS["QUERY_ENHANCEMENT_SUFFIX"] = (
"\n\nPlease provide a comprehensive answer based on the user query and the provided multimodal content information."
)