diff --git a/report/report_detail_levels.py b/report/report_detail_levels.py index e7a8236..16da163 100644 --- a/report/report_detail_levels.py +++ b/report/report_detail_levels.py @@ -118,74 +118,79 @@ class ReportDetailLevelManager: }, 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.", + "factual": "Create a detailed factual report that thoroughly answers the query with deeper analysis. Focus on accuracy, clarity, and analytical depth. Include:\n" + "1. A comprehensive answer to the query with nuanced details and multi-layered analysis\n" + "2. Extensive supporting evidence including statistics, expert opinions, and case examples\n" + "3. Deeper exploration of causal relationships and underlying mechanisms\n" + "4. Analysis of how different factors interact and influence each other\n" + "5. Examination of historical context and how it shapes current understanding\n" + "6. Consideration of diverse perspectives and interpretations of the evidence\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" + "Prioritize depth of analysis over breadth of topics. Focus on providing rich, insightful explanations rather than just adding more sections.", - "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" + "comparative": "Create a detailed comparative report with deeper analytical insights. Include:\n" + "1. A comprehensive overview of the topic with analysis of underlying principles\n" + "2. In-depth presentation of different viewpoints with exploration of their theoretical foundations\n" + "3. Detailed analysis of why differences exist and their historical development\n" + "4. Examination of how different perspectives might apply in various contexts or scenarios\n" + "5. Analysis of trade-offs, with quantitative measures where possible\n" + "6. Exploration of hybrid approaches or potential reconciliation of different viewpoints\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.", + "Prioritize depth of analysis over breadth of topics. Focus on providing rich, insightful explanations rather than just adding more sections.", - "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" + "exploratory": "Create a detailed exploratory report with deeper analytical insights. Include:\n" + "1. A comprehensive introduction with analysis of why this topic matters and to whom\n" + "2. Detailed explanation of key concepts with exploration of their evolution and interconnections\n" + "3. In-depth analysis of cause-and-effect relationships and systemic factors\n" + "4. Examination of apparent contradictions and how they might be resolved\n" + "5. Analysis of how different stakeholders might be affected differently\n" + "6. Exploration of second and third-order effects or implications\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." + "Prioritize depth of analysis over breadth of topics. Focus on providing rich, insightful explanations rather than just adding more sections." }, 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.", + "factual": "Create an exhaustive factual report with the deepest possible analysis. Include:\n" + "1. A multi-dimensional answer that explores all facets of the query with layered analysis\n" + "2. Comprehensive evidence including statistical data, expert consensus, minority viewpoints, and case studies\n" + "3. Detailed exploration of complex causal networks and feedback loops\n" + "4. Analysis of how the topic intersects with related domains and disciplines\n" + "5. Examination of historical evolution, current state, and future trajectories\n" + "6. Critical evaluation of the quality and reliability of different evidence sources\n" + "7. Synthesis of insights across multiple analytical frameworks\n" + "8. Visual elements such as tables or bullet points to organize complex information\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" + "Maximize analytical depth while maintaining clarity. Provide the richest possible understanding rather than simply covering more ground.", - "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" + "comparative": "Create an exhaustive comparative report with the deepest possible analysis. Include:\n" + "1. A multi-layered overview that places the comparison in broader theoretical and practical contexts\n" + "2. Comprehensive presentation of all viewpoints with analysis of their epistemological foundations\n" + "3. Detailed examination of how different perspectives have evolved in response to each other\n" + "4. Analysis of how cultural, historical, and disciplinary contexts shape different viewpoints\n" + "5. Quantitative and qualitative comparison using multiple frameworks and metrics\n" + "6. Exploration of edge cases where different perspectives might converge or diverge\n" + "7. Synthesis that identifies meta-patterns across different analytical dimensions\n" + "8. Visual elements such as tables or matrices to organize complex comparisons\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.", + "Maximize analytical depth while maintaining clarity. Provide the richest possible understanding rather than simply covering more ground.", - "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." + "exploratory": "Create an exhaustive exploratory report with the deepest possible analysis. Include:\n" + "1. A multi-dimensional introduction that situates the topic within broader intellectual landscapes\n" + "2. Comprehensive explanation of all concepts with analysis of their theoretical underpinnings\n" + "3. In-depth exploration of complex interaction effects and emergent properties\n" + "4. Detailed examination of how different methodological approaches yield different insights\n" + "5. Analysis of how the topic might be understood differently across disciplines or paradigms\n" + "6. Exploration of counterfactuals, thought experiments, and alternative scenarios\n" + "7. Synthesis that integrates insights across multiple levels of analysis\n" + "8. Visual elements such as tables or concept maps to organize complex information\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" + "Maximize analytical depth while maintaining clarity. Provide the richest possible understanding rather than simply covering more ground." } } diff --git a/report/report_synthesis.py b/report/report_synthesis.py index 313ea1f..64bbd44 100644 --- a/report/report_synthesis.py +++ b/report/report_synthesis.py @@ -125,26 +125,27 @@ class ReportSynthesizer: logger.error(f"Error generating completion: {e}") return f"Error: {str(e)}" - async def map_document_chunks(self, chunks: List[Dict[str, Any]], query: str) -> List[Dict[str, Any]]: + async def map_document_chunks(self, chunks: List[Dict[str, Any]], query: str, detail_level: str = "standard") -> List[Dict[str, Any]]: """ Map phase: Process individual document chunks to extract key information. Args: chunks: List of document chunks query: Original search query + detail_level: Level of detail for the report (brief, standard, detailed, comprehensive) Returns: List of processed chunks with extracted information """ processed_chunks = [] + # Get the appropriate extraction prompt based on detail level + extraction_prompt = self._get_extraction_prompt(detail_level) + for chunk in chunks: # Create a prompt for extracting key information from the chunk messages = [ - {"role": "system", "content": """You are an expert research assistant. Extract the most relevant information from this document chunk that addresses the user's query. - Focus on factual information, key concepts, and important details. - Include any relevant statistics, definitions, or explanations that would be valuable for a comprehensive report. - Format your response as a concise summary with bullet points for key facts."""}, + {"role": "system", "content": extraction_prompt}, {"role": "user", "content": f"""Query: {query} Document title: {chunk.get('title', 'Untitled')} @@ -167,6 +168,50 @@ class ReportSynthesizer: return processed_chunks + def _get_extraction_prompt(self, detail_level: str) -> str: + """ + Get the appropriate extraction prompt based on detail level. + + Args: + detail_level: Level of detail for the report (brief, standard, detailed, comprehensive) + + Returns: + Extraction prompt as a string + """ + if detail_level.lower() in ["brief", "standard"]: + return """You are an expert research assistant. Extract the most relevant information from this document chunk that addresses the user's query. + Focus on factual information, key concepts, and important details. + Include any relevant statistics, definitions, or explanations that would be valuable for a report. + Format your response as a concise summary with bullet points for key facts.""" + elif detail_level.lower() == "detailed": + return """You are an expert research analyst with deep domain knowledge. Extract comprehensive information from this document chunk that addresses the user's query. + Focus on: + - Detailed factual information and evidence + - Underlying principles and mechanisms + - Causal relationships and correlations + - Contextual factors and historical development + - Different perspectives or interpretations + - Quantitative data and qualitative insights + - Nuances, edge cases, and exceptions + + Prioritize depth of analysis over breadth. Extract information that provides deeper understanding rather than just basic facts. + Format your response with clear sections and bullet points for key insights.""" + else: # comprehensive + return """You are a world-class research analyst with exceptional analytical abilities. Extract the most comprehensive and nuanced information from this document chunk. + Focus on: + - Multi-layered analysis of all relevant facts and evidence + - Complex causal networks and interaction effects + - Theoretical frameworks and their applications + - Historical evolution and future trajectories + - Methodological considerations and limitations + - Diverse perspectives and their epistemological foundations + - Statistical data, case studies, and expert opinions + - Contradictions, paradoxes, and unresolved questions + + Extract information that provides the deepest possible understanding of the topic as it relates to the query. + Analyze the reliability and significance of the information. + Format your response with clearly organized sections and detailed bullet points.""" + async def reduce_processed_chunks(self, processed_chunks: List[Dict[str, Any]], query: str, query_type: str = "exploratory", detail_level: str = "standard") -> str: """ Reduce phase: Synthesize processed chunks into a coherent report. @@ -240,7 +285,7 @@ class ReportSynthesizer: # Map phase: Process individual document chunks logger.info("Starting map phase: Processing individual document chunks") - processed_chunks = await self.map_document_chunks(chunks, query) + processed_chunks = await self.map_document_chunks(chunks, query, detail_level) logger.info(f"Map phase complete: Processed {len(processed_chunks)} chunks") # Reduce phase: Synthesize processed chunks into a coherent report @@ -294,7 +339,7 @@ async def test_report_synthesizer(): query = "What are the key features of Python programming language?" # Map phase - processed_chunks = await synthesizer.map_document_chunks(chunks, query) + processed_chunks = await synthesizer.map_document_chunks(chunks, query, detail_level="detailed") # Print processed chunks print("Processed chunks:") @@ -304,7 +349,7 @@ async def test_report_synthesizer(): print() # Reduce phase - report = await synthesizer.reduce_processed_chunks(processed_chunks, query) + report = await synthesizer.reduce_processed_chunks(processed_chunks, query, detail_level="detailed") # Print report print("Generated Report:")