53 lines
2 KiB
Python
53 lines
2 KiB
Python
# Copyright (c) 2025 Patrick Motsch
|
|
# All rights reserved.
|
|
|
|
"""
|
|
Generate Document action for AI operations.
|
|
Generates documents from scratch or based on templates/inputs.
|
|
"""
|
|
|
|
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 generateDocument(self, parameters: Dict[str, Any]) -> ActionResult:
|
|
"""
|
|
GENERAL:
|
|
- Purpose: Generate documents from scratch or based on templates/inputs.
|
|
- Input requirements: prompt or description (required); optional documentList (for templates/references).
|
|
- Output format: Document in specified format (default: docx).
|
|
|
|
Parameters:
|
|
- prompt (str, required): Description of the document to generate.
|
|
- documentList (list, optional): Template documents or reference documents to use as a guide.
|
|
- documentType (str, optional): Type of document - letter, memo, proposal, contract, etc.
|
|
- resultType (str, optional): Output format (docx, pdf, txt, md, etc.). Default: docx.
|
|
"""
|
|
prompt = parameters.get("prompt")
|
|
if not prompt:
|
|
return ActionResult.isFailure(error="prompt is required")
|
|
|
|
documentList = parameters.get("documentList", [])
|
|
documentType = parameters.get("documentType")
|
|
resultType = parameters.get("resultType", "docx")
|
|
|
|
aiPrompt = f"Generate a document based on the following requirements: {prompt}"
|
|
if documentType:
|
|
aiPrompt += f" Document type: {documentType}."
|
|
if documentList:
|
|
aiPrompt += " Use the provided template/reference documents as a guide for structure, format, and style."
|
|
aiPrompt += " Create a professional, well-structured document with appropriate formatting and organization."
|
|
|
|
processParams = {
|
|
"aiPrompt": aiPrompt,
|
|
"resultType": resultType
|
|
}
|
|
if documentList:
|
|
processParams["documentList"] = documentList
|
|
|
|
return await self.process(processParams)
|
|
|