ira/report/report_detail_levels.py

259 lines
16 KiB
Python

"""
Report detail levels module for the intelligent research system.
This module provides functionality to define and configure different levels of detail
for generated reports, allowing users to customize the depth and breadth of information
included in reports.
"""
import enum
from typing import Dict, Any, Optional, List, Tuple
class DetailLevel(enum.Enum):
"""Enum for different report detail levels."""
BRIEF = "brief"
STANDARD = "standard"
DETAILED = "detailed"
COMPREHENSIVE = "comprehensive"
class ReportDetailLevelManager:
"""
Manager for report detail levels.
This class provides methods to get configuration parameters for different
report detail levels, allowing users to customize the depth and breadth of
information included in reports.
"""
def __init__(self):
"""Initialize the report detail level manager."""
# Define default configurations for different detail levels
self.detail_level_configs = {
DetailLevel.BRIEF: {
"num_results": 3,
"token_budget": 50000,
"chunk_size": 800,
"overlap_size": 50,
"model": "llama-3.1-8b-instant",
"description": "A concise summary of key findings and conclusions."
},
DetailLevel.STANDARD: {
"num_results": 7,
"token_budget": 100000,
"chunk_size": 1000,
"overlap_size": 100,
"model": "llama-3.1-8b-instant",
"description": "A balanced report with key findings, analysis, and conclusions."
},
DetailLevel.DETAILED: {
"num_results": 12,
"token_budget": 150000,
"chunk_size": 1200,
"overlap_size": 150,
"model": "llama-3.3-70b-versatile",
"description": "A comprehensive report with in-depth analysis, methodology, and implications."
},
DetailLevel.COMPREHENSIVE: {
"num_results": 20,
"token_budget": 200000,
"chunk_size": 1500,
"overlap_size": 200,
"model": "llama-3.3-70b-versatile",
"description": "An exhaustive report with all available information, extensive analysis, and detailed references."
}
}
# Define template modifiers for different detail levels
self.template_modifiers = {
DetailLevel.BRIEF: {
"factual": "Create a brief factual report that directly answers the query. Focus on accuracy and clarity. Include:\n"
"1. A clear, direct answer to the query\n"
"2. Key supporting evidence and facts\n"
"3. Citations for information (use numbered citations in square brackets [1], [2], etc.)\n"
"4. A concise references section\n\n"
"Keep the report concise and to the point, focusing only on the most essential information.",
"comparative": "Create a brief comparative report that analyzes different perspectives on the query. Include:\n"
"1. A concise overview of the topic\n"
"2. Key similarities and differences between perspectives\n"
"3. Citations for information (use numbered citations in square brackets [1], [2], etc.)\n"
"4. A concise references section\n\n"
"Keep the report concise and to the point, focusing only on the most essential comparisons.",
"exploratory": "Create a brief exploratory report that investigates the query. Include:\n"
"1. A concise introduction to the topic\n"
"2. Key findings and insights\n"
"3. Citations for information (use numbered citations in square brackets [1], [2], etc.)\n"
"4. A concise references section\n\n"
"Keep the report concise and to the point, focusing only on the most essential information."
},
DetailLevel.STANDARD: {
"factual": "Create a standard factual report that directly answers the query. Focus on accuracy and clarity. Include:\n"
"1. A clear, direct answer to the query\n"
"2. Supporting evidence and facts from the sources\n"
"3. Any relevant context needed to understand the answer\n"
"4. Citations for all information (use numbered citations in square brackets [1], [2], etc.)\n"
"5. A references section at the end listing all sources",
"comparative": "Create a standard comparative report that analyzes different perspectives on the query. Include:\n"
"1. An overview of the topic and why it's significant\n"
"2. A balanced presentation of different viewpoints or approaches\n"
"3. Analysis of similarities and differences\n"
"4. Evidence supporting each perspective\n"
"5. A synthesis of the information that highlights key insights\n"
"6. Citations for all information (use numbered citations in square brackets [1], [2], etc.)\n"
"7. A references section at the end listing all sources",
"exploratory": "Create a standard exploratory report that investigates the query in depth. Include:\n"
"1. An introduction that frames the topic and its significance\n"
"2. Key concepts and definitions\n"
"3. Main findings and insights from the sources\n"
"4. Analysis of the information that highlights patterns and connections\n"
"5. Implications or applications of the findings\n"
"6. Citations for all information (use numbered citations in square brackets [1], [2], etc.)\n"
"7. A references section at the end listing all sources"
},
DetailLevel.DETAILED: {
"factual": "Create a detailed factual report that thoroughly answers the query. Focus on accuracy, clarity, and depth. Include:\n"
"1. A comprehensive answer to the query with nuanced details\n"
"2. Extensive supporting evidence and facts from multiple sources\n"
"3. Contextual information and background to fully understand the topic\n"
"4. Discussion of any limitations or caveats in the information\n"
"5. Citations for all information (use numbered citations in square brackets [1], [2], etc.)\n"
"6. A detailed references section at the end listing all sources\n\n"
"Organize the report with clear sections and subsections to enhance readability.",
"comparative": "Create a detailed comparative report that thoroughly analyzes different perspectives on the query. Include:\n"
"1. A comprehensive overview of the topic, its history, and significance\n"
"2. In-depth presentation of different viewpoints, approaches, or theories\n"
"3. Detailed analysis of similarities, differences, strengths, and weaknesses\n"
"4. Extensive evidence supporting each perspective from multiple sources\n"
"5. Discussion of nuances, edge cases, and contextual factors\n"
"6. A thorough synthesis that highlights key insights and patterns\n"
"7. Citations for all information (use numbered citations in square brackets [1], [2], etc.)\n"
"8. A detailed references section at the end listing all sources\n\n"
"Organize the report with clear sections and subsections to enhance readability.",
"exploratory": "Create a detailed exploratory report that thoroughly investigates the query. Include:\n"
"1. A comprehensive introduction that frames the topic, its history, and significance\n"
"2. Detailed explanation of key concepts, definitions, and theoretical frameworks\n"
"3. In-depth presentation of findings and insights from multiple sources\n"
"4. Thorough analysis that highlights patterns, connections, and contradictions\n"
"5. Discussion of implications, applications, and future directions\n"
"6. Consideration of limitations, gaps in knowledge, and areas for further research\n"
"7. Citations for all information (use numbered citations in square brackets [1], [2], etc.)\n"
"8. A detailed references section at the end listing all sources\n\n"
"Organize the report with clear sections and subsections to enhance readability."
},
DetailLevel.COMPREHENSIVE: {
"factual": "Create an exhaustive factual report that answers the query with maximum depth and breadth. Focus on accuracy, clarity, and completeness. Include:\n"
"1. A comprehensive answer to the query with all available details and nuances\n"
"2. Exhaustive supporting evidence and facts from all available sources\n"
"3. Complete contextual information, background, and historical development\n"
"4. Thorough discussion of all limitations, caveats, and alternative interpretations\n"
"5. Analysis of conflicting information or disagreements in the sources\n"
"6. Visual elements such as tables or bullet points to organize complex information\n"
"7. Citations for all information (use numbered citations in square brackets [1], [2], etc.)\n"
"8. A comprehensive references section at the end listing all sources\n\n"
"Organize the report with clear sections, subsections, and where appropriate, sub-subsections to maximize readability.",
"comparative": "Create an exhaustive comparative report that analyzes different perspectives on the query with maximum depth and breadth. Include:\n"
"1. A comprehensive overview of the topic, its complete history, significance, and context\n"
"2. Exhaustive presentation of all viewpoints, approaches, theories, and models\n"
"3. Detailed analysis of all similarities, differences, strengths, weaknesses, and trade-offs\n"
"4. Complete evidence supporting each perspective from all available sources\n"
"5. Thorough discussion of all nuances, edge cases, and contextual factors\n"
"6. Analysis of how different perspectives have evolved over time\n"
"7. Visual elements such as tables or bullet points to organize complex comparisons\n"
"8. A comprehensive synthesis that highlights all insights, patterns, and implications\n"
"9. Citations for all information (use numbered citations in square brackets [1], [2], etc.)\n"
"10. A comprehensive references section at the end listing all sources\n\n"
"Organize the report with clear sections, subsections, and where appropriate, sub-subsections to maximize readability.",
"exploratory": "Create an exhaustive exploratory report that investigates the query with maximum depth and breadth. Include:\n"
"1. A comprehensive introduction that frames the topic, its complete history, significance, and context\n"
"2. Exhaustive explanation of all key concepts, definitions, and theoretical frameworks\n"
"3. Complete presentation of all findings and insights from all available sources\n"
"4. Thorough analysis that highlights all patterns, connections, contradictions, and outliers\n"
"5. Comprehensive discussion of all implications, applications, and future directions\n"
"6. Complete consideration of all limitations, gaps in knowledge, and areas for further research\n"
"7. Visual elements such as tables or bullet points to organize complex information\n"
"8. Citations for all information (use numbered citations in square brackets [1], [2], etc.)\n"
"9. A comprehensive references section at the end listing all sources\n\n"
"Organize the report with clear sections, subsections, and where appropriate, sub-subsections to maximize readability."
}
}
def get_detail_level_config(self, detail_level: str) -> Dict[str, Any]:
"""
Get configuration parameters for a specific detail level.
Args:
detail_level: Detail level as a string (brief, standard, detailed, comprehensive)
Returns:
Dictionary of configuration parameters for the specified detail level
Raises:
ValueError: If the detail level is not valid
"""
try:
level = DetailLevel(detail_level.lower())
return self.detail_level_configs[level]
except (ValueError, KeyError):
valid_levels = [level.value for level in DetailLevel]
raise ValueError(f"Invalid detail level: {detail_level}. Valid levels are: {', '.join(valid_levels)}")
def get_template_modifier(self, detail_level: str, query_type: str) -> str:
"""
Get template modifier for a specific detail level and query type.
Args:
detail_level: Detail level as a string (brief, standard, detailed, comprehensive)
query_type: Query type as a string (factual, exploratory, comparative)
Returns:
Template modifier as a string
Raises:
ValueError: If the detail level or query type is not valid
"""
try:
level = DetailLevel(detail_level.lower())
if query_type not in ["factual", "exploratory", "comparative"]:
query_type = "exploratory" # Default to exploratory if query type is not valid
return self.template_modifiers[level][query_type]
except (ValueError, KeyError):
valid_levels = [level.value for level in DetailLevel]
raise ValueError(f"Invalid detail level: {detail_level}. Valid levels are: {', '.join(valid_levels)}")
def get_available_detail_levels(self) -> List[Tuple[str, str]]:
"""
Get a list of available detail levels with descriptions.
Returns:
List of tuples containing detail level and description
"""
return [(level.value, config["description"])
for level, config in self.detail_level_configs.items()]
# Create a singleton instance for global use
report_detail_level_manager = ReportDetailLevelManager()
def get_report_detail_level_manager() -> ReportDetailLevelManager:
"""
Get the global report detail level manager instance.
Returns:
ReportDetailLevelManager instance
"""
return report_detail_level_manager