# Copyright (c) 2025 Patrick Motsch # All rights reserved. """ Summarize Document action for AI operations. Summarizes one or more documents, extracting key points and main ideas. """ import logging from typing import Dict, Any from modules.workflows.methods.methodBase import action from modules.datamodels.datamodelChat import ActionResult logger = logging.getLogger(__name__) @action async def summarizeDocument(self, parameters: Dict[str, Any]) -> ActionResult: """ GENERAL: - Purpose: Summarize one or more documents, extracting key points and main ideas. - Input requirements: documentList (required); optional summaryLength, focus. - Output format: Text document with summary (default: txt, can be overridden with resultType). Parameters: - documentList (list, required): Document reference(s) to summarize. - summaryLength (str, optional): Desired summary length - brief, medium, or detailed. Default: medium. - focus (str, optional): Specific aspect to focus on in the summary (e.g., "financial data", "key decisions"). - resultType (str, optional): Output file extension (txt, md, docx, etc.). Default: txt. """ documentList = parameters.get("documentList", []) if not documentList: return ActionResult.isFailure(error="documentList is required") summaryLength = parameters.get("summaryLength", "medium") focus = parameters.get("focus") resultType = parameters.get("resultType", "txt") lengthInstructions = { "brief": "Create a brief summary (2-3 paragraphs)", "medium": "Create a medium-length summary (comprehensive but concise)", "detailed": "Create a detailed summary covering all major points" } lengthInstruction = lengthInstructions.get(summaryLength.lower(), lengthInstructions["medium"]) aiPrompt = f"Summarize the provided document(s). {lengthInstruction}." if focus: aiPrompt += f" Focus specifically on: {focus}." aiPrompt += " Extract and present the key points, main ideas, and important information in a clear, well-structured format." return await self.process({ "aiPrompt": aiPrompt, "documentList": documentList, "resultType": resultType })